Hi,
I was building a wizard style app with wxPython that will be cross platform, but primarily developed on Mac.
I followed the attached code to add the TaskBarIcon successfully to Mac and that works properly, however, when a right click is performed on the Dock Item icon, OnClose is called twice. The second iteration through OnClose seg faults because the icon has already been destroyed.
This works to fix it for Mac, but does not close the frame on windows:
def OnCloseWindow(self, evt):
print "OnCloseWindow called"
self.tbicon.RemoveIcon()
evt.Skip()
Windows hangs on shutting down on evt.Skip(). I have to explicitly also do self.tbicon.Destroy().
So I basically now have:
def OnCloseWindow(self, evt):
print "OnCLoseWindow called"
if evt.CanVeto():
print "Can veto, going to lower window" #Mac
#Put some logic here to lower the window from extended App class.
else:
self.tbicon.RemoveIcon() #Closed some other way
if wx.Platform == "__WXMSW__": #Seems to be required for Windows. On mac, when closed from dock a second call will segfault when closed from dock
self.tbicon.Destroy()
self.Destroy()
The problem here is closing on Windows (hitting X in the frame) is allowed to Veto by default.
Before going this route (not really knowing if this will cause other problems):
def OnCloseWindow(self, evt):
print "OnCLoseWindow called"
if evt.CanVeto():
print "Can veto, going to lower window" #Mac
#Put some logic here to lower the window from extended App class.
if wx.Platform == “WXMSW”:
self.Close(True)
else:
self.tbicon.RemoveIcon() #Closed some other way
if wx.Platform == "__WXMSW__": #Seems to be required for Windows. On mac, when closed from dock a second call will segfault when closed from dock
self.tbicon.Destroy()
self.Destroy()
Does this seem correct? The piece I was really wondering on was the Dock calling OnClose twice. I’m guessing that another thread is created to monitor the Dock related close event?
Also, does the logic seem reasonable?
Thanks!
David