window opens up then closes

Hi, I am running an application which has the main window open, I want to open another informational window up, then close once a file is downloaded.
This all works fine on OSX, but in windows the new info window opens, displays no text, then just freezes.

class AnotherClass(blahhhhh)

def schemaVersionCheck(self, iTunesVersion):

other stuff…

busy = BusyWindow(None, -1, “”)

while not os.path.exists(self.schemaFile):

time.sleep(0.5)

if foundSchemaFile == False:

busy.Close()

class BusyWindow(wx.Frame):

def init(self, parent, id, title):

wx.Frame.init(self, parent, id, title, size=(350, 80), style=wx.STAY_ON_TOP | wx.CLOSE_BOX | wx.CLIP_CHILDREN)

wx.StaticText(self, -1, " Downloading new schema file. \n Please wait")

self.Centre()

self.Show()

kevjwells wrote:

Hi, I am running an application which has the main window open, I want
to open another informational window up, then close once a file is
downloaded.
This all works fine on OSX, but in windows the new info window opens,
displays no text, then just freezes.

class AnotherClass(blahhhhh)
def schemaVersionCheck(self, iTunesVersion):
other stuff........
busy = BusyWindow(None, -1, "")
while not os.path.exists(self.schemaFile):
time.sleep(0.5)
if foundSchemaFile == False:
busy.Close()

class BusyWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(350, 80),
style=wx.STAY_ON_TOP | wx.CLOSE_BOX | wx.CLIP_CHILDREN)
wx.StaticText(self, -1, " Downloading new schema file. \n Please wait")
self.Centre()
self.Show()

You are blocking the program from returning to the event loop, so no new events can be processed, like letting the window paint itself, or processing of key or mouse events. In event driven programming situations like GUIs you want to avoid doing anything time consuming or blocking all in one event handler. Do what you need, do it fast, and get the heck outta there.

There are a few ways around your issue, some better than others depending on the situation. One simple but possibly unsafe approach would be to call wx.GetApp().Yield(True) inside your polling loop, but that would only allow events to be processed every .5 seconds, so things will appear choppy.

Another approach that would work well in this situation is to use a timer. Start the timer in schemaVersionCheck after creating the BusyWindow, and then return so events can be processed. Have the timer fire every 500 ms and in the handler you check if the file exists, and if so you stop the timer, close the BusyWindow and do whatever else you need to do.

See also:
http://wiki.wxpython.org/LongRunningTasks
http://wiki.wxpython.org/Non-Blocking_Gui
http://wiki.wxpython.org/CallAfter

···

--
Robin Dunn
Software Craftsman

Hi Robin, thanks for your reply, I found a much easier method for what I was trying to achieve, using wx.BusyInfo served my purpose, but have another issue with this, but only on Windows, I will post another issue about this, if you could take a look that would be great.

Kind regards.

···

On Tuesday, April 7, 2015 at 8:35:32 PM UTC+1, Robin Dunn wrote:

kevjwells wrote:

Hi, I am running an application which has the main window open, I want

to open another informational window up, then close once a file is

downloaded.

This all works fine on OSX, but in windows the new info window opens,

displays no text, then just freezes.

class AnotherClass(blahhhhh)

def schemaVersionCheck(self, iTunesVersion):

other stuff…

busy = BusyWindow(None, -1, “”)

while not os.path.exists(self.schemaFile):

time.sleep(0.5)

if foundSchemaFile == False:

busy.Close()

class BusyWindow(wx.Frame):

def init(self, parent, id, title):

wx.Frame.init(self, parent, id, title, size=(350, 80),

style=wx.STAY_ON_TOP | wx.CLOSE_BOX | wx.CLIP_CHILDREN)

wx.StaticText(self, -1, " Downloading new schema file. \n Please wait")

self.Centre()

self.Show()

You are blocking the program from returning to the event loop, so no new
events can be processed, like letting the window paint itself, or
processing of key or mouse events. In event driven programming
situations like GUIs you want to avoid doing anything time consuming or
blocking all in one event handler. Do what you need, do it fast, and
get the heck outta there.

There are a few ways around your issue, some better than others
depending on the situation. One simple but possibly unsafe approach
would be to call wx.GetApp().Yield(True) inside your polling loop, but
that would only allow events to be processed every .5 seconds, so things
will appear choppy.

Another approach that would work well in this situation is to use a
timer. Start the timer in schemaVersionCheck after creating the
BusyWindow, and then return so events can be processed. Have the timer
fire every 500 ms and in the handler you check if the file exists, and
if so you stop the timer, close the BusyWindow and do whatever else you
need to do.

See also:

http://wiki.wxpython.org/LongRunningTasks

http://wiki.wxpython.org/Non-Blocking_Gui

http://wiki.wxpython.org/CallAfter


Robin Dunn

Software Craftsman

http://wxPython.org