python - wxPython: frame class loads several commands AFTER it is called -
i have function runs few intensive commands, made spinner
class, simple window appears wx.gauge
widget pulses during loading.
the problem that, when called in run
, window doesn't appear until several seconds after initialized - self.triangulatepoints()
finishes before window appears. indeed, if don't comment out load.end()
(which closes window), spinner
instance appear , disappear.
i assume has threading, , program continues run while spinner
initiates. case? , if so, can pause progression of run()
until spinner
window appears?
it should noted running time.sleep(n)
after calling spinner(...)
not change when in program sequence appears on screen.
def run(self, event): gis.points_packed = false gis.triangulated = false load = spinner(self, style=wx.default_frame_style & (~wx.close_box) & (~wx.maximize_box) ^ (wx.resize_border) & (~wx.minimize_box)) load.update('circle packing points...') gis.boundary(infile=gis.loaded_boundary) load.pulse() self.getpoints(none, show=false) load.update("triangulating nodes...") self.triangulatepoints(none, show=true) load.end() ######################################################## class spinner(wx.frame): def __init__(self, *args, **kwds): super(spinner, self).__init__(*args, **kwds) self.setsize((300,80)) self.settitle('loading') process = "loading..." self.font = wx.font(pointsize = 12, family = wx.default, style = wx.normal, weight = wx.bold, facename = 'arial') self.process_txt = wx.statictext(self, -1, process) self.process_txt.setfont(self.font) self.progress = wx.gauge(self, id=-1, range=100, pos=(10,30), size=(280,15), name="loading") self.update(process) self.centre() self.show(true) def end(self): self.close(true) def update(self,txt): dc = wx.screendc() dc.setfont(self.font) tsize = dc.gettextextent(txt) self.process_txt.setposition((300/2-tsize[0]/2,10)) self.process_txt.setlabel(txt) self.progress.pulse() def pulse(self): self.progress.pulse()
there doesn't seem threads in code show, it's not clear why think has threading. quite contrary, in fact: afaics due not using threads. should run long running ("intensive") code in worker thread, things work , display correctly in ui.
you can't block main, ui thread non-trivial amount of time , still expect ui update correctly.
Comments
Post a Comment