python - Update wxPython grid in real time -




i extracting data huge log , updating entry in wxpython grid. code have can see window after operation complete, takes 5 mins complete operation. there way update , see data on grid time = 0 itself. tried:

import wx import wx.grid  gridlib class myform(wx.frame):     def __init__(self):         ##         # constructor create basic frame         wx.frame.__init__(self, none, wx.id_any, "tool")          # add panel looks correct on platforms         panel = wx.panel(self, wx.id_any)         self.grid = gridlib.grid(panel)         rows = 4         column = 600000         self.grid.creategrid(column, rows)         self.count = 0         # change couple column labels         self.grid.setcollabelvalue(0, "timestamp")         self.grid.setcollabelvalue(1, "cmd")         self.grid.setcollabelvalue(2, "address")         self.grid.setcollabelvalue(3, "data")          # few more operations calculate cmd,timestamp field           in range(10**5):             self.count += 1             self.grid.setcellvalue(self.count,1,'cmd4')             self.grid.setcellvalue(self.count,0,str(self.count))             self.grid.setcellvalue(self.count, 2, "extracted address")             self.grid.setcellvalue(self.count, 3, "extracted data")         # change row labels          sizer = wx.boxsizer(wx.vertical)         sizer.add(self.grid, 1, wx.expand, 5)         panel.setsizer(sizer)  if __name__ == "__main__":     app = wx.app()     frame = myform()     frame.show()     app.mainloop() 

use wx.yield() hand control main loop.
here use divmod every 1000th iteration , call wx.yield.
use movecursordownblock allow visually follow updating grid.
may wish remove or amend this, slow down execution of program.

import wx import wx.grid gridlib class myform(wx.frame):     def __init__(self):         ##         # constructor create basic frame         wx.frame.__init__(self, none, wx.id_any, "tool")          # add panel looks correct on platforms         panel = wx.panel(self, wx.id_any)         self.grid = gridlib.grid(panel)         rows = 4         column = 100001         self.grid.creategrid(column, rows)         self.count = 0         # change couple column labels         self.grid.setcollabelvalue(0, "timestamp")         self.grid.setcollabelvalue(1, "cmd")         self.grid.setcollabelvalue(2, "address")         self.grid.setcollabelvalue(3, "data")          # few more operations calculate cmd,timestamp field          sizer = wx.boxsizer(wx.vertical)         sizer.add(self.grid, 1, wx.expand, 5)         panel.setsizer(sizer)         self.show()         in range(10**5):             self.count += 1             self.grid.setcellvalue(self.count,1,'cmd4')             self.grid.setcellvalue(self.count,0,str(self.count))             self.grid.setcellvalue(self.count, 2, "extracted address")             self.grid.setcellvalue(self.count, 3, "extracted data")             quo,rem = divmod(self.count,1000)             if rem == 0:                 self.grid.movecursordownblock(expandselection=false)                 wx.yield()  if __name__ == "__main__":     app = wx.app()     frame = myform()     app.mainloop() 




wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -