Matthew Cahn
2006-06-07 21:40:40 UTC
I have a rather elaborate image viewing application. A brief
description: the main GUI uses a wx.SplitterWindow. In the left-hand
pane is a wx.TreeCtrl for choosing sets of images (directory names or
database entries). In the right-hand pane is a wx.ScrolledWindow
containing thumbnail images (each of which is a wx.StaticBitmap and a
wx.StaticText in a wx.Panel).
Whenever the user clicks on a different set of images on the left (or
selects a different size for the thumbnails), I destroy the
wx.ScrolledWindow and make a new one containing the new thumbnails.
Sometimes this works, and sometimes the application silently exits.
This behavior recently got much worse when I added a gamma correction to
the thumbnails, that is, there's more computation before the creation of
the new wx.ScrolledWindow. Now it exits about half the time.
From other messages on the mailing list, it seems like this might have
to do with destroying the wx.ScrolledWindow while there are still events
pending. I put the destroy in a wx.CallAfter, and then the re-creation
in a second wx.CallAfter, but this seems to destroy the window _after_ I
create it. Is there a good strategy for handling any pending events,
destroying the window, and then creating the window, all in the right
order? Or am I barking up the wrong tree in trying to fix my silent
exit? Here's the bit of code that does the destroy/create:
class MainFrame(wx.Frame):
...
def createThumbPanel(self, parent, id, size=wx.DefaultSize):
wx.CallAfter(self._destroyThumbPanel)
wx.CallAfter(self._createThumbPanel, parent, id, size=size)
def _destroyThumbPanel(self):
try:
rv = self.thumbPanel.Destroy()
except AttributeError, err: # No thumb panel the first time
pass
def _createThumbPanel(self, parent, id, size=wx.DefaultSize):
self.thumbPanel = IVthumbs.ThumbPanel(parent, id, size=size,
style=wx.WANTS_CHARS)
self.splitter.SplitVertically(self.navTreePanel,
self.thumbPanel, navPanelWidth)
self.splitter.SetMinimumPaneSize(20)
self.splitter.SetSashPosition(navPanelWidth + scrollBarWidth)
self.thumbPanel.Bind(wx.EVT_CHAR, self.processKeys, self.thumbPanel)
...
Any help appreciated,
Matthew
--
--------------------------------
| Matthew Cahn
| Principal Systems Analyst
| Bristol-Myers Squibb Company
| Mailbox code: H23-05
| P.O. Box 4000
| Princeton, NJ 08543-4000
|
| Phone: (609) 252-3477
| Fax: (609) 252-6030
| Email: ***@bms.com
| Pager: ***@imbta.com
--------------------------------
description: the main GUI uses a wx.SplitterWindow. In the left-hand
pane is a wx.TreeCtrl for choosing sets of images (directory names or
database entries). In the right-hand pane is a wx.ScrolledWindow
containing thumbnail images (each of which is a wx.StaticBitmap and a
wx.StaticText in a wx.Panel).
Whenever the user clicks on a different set of images on the left (or
selects a different size for the thumbnails), I destroy the
wx.ScrolledWindow and make a new one containing the new thumbnails.
Sometimes this works, and sometimes the application silently exits.
This behavior recently got much worse when I added a gamma correction to
the thumbnails, that is, there's more computation before the creation of
the new wx.ScrolledWindow. Now it exits about half the time.
From other messages on the mailing list, it seems like this might have
to do with destroying the wx.ScrolledWindow while there are still events
pending. I put the destroy in a wx.CallAfter, and then the re-creation
in a second wx.CallAfter, but this seems to destroy the window _after_ I
create it. Is there a good strategy for handling any pending events,
destroying the window, and then creating the window, all in the right
order? Or am I barking up the wrong tree in trying to fix my silent
exit? Here's the bit of code that does the destroy/create:
class MainFrame(wx.Frame):
...
def createThumbPanel(self, parent, id, size=wx.DefaultSize):
wx.CallAfter(self._destroyThumbPanel)
wx.CallAfter(self._createThumbPanel, parent, id, size=size)
def _destroyThumbPanel(self):
try:
rv = self.thumbPanel.Destroy()
except AttributeError, err: # No thumb panel the first time
pass
def _createThumbPanel(self, parent, id, size=wx.DefaultSize):
self.thumbPanel = IVthumbs.ThumbPanel(parent, id, size=size,
style=wx.WANTS_CHARS)
self.splitter.SplitVertically(self.navTreePanel,
self.thumbPanel, navPanelWidth)
self.splitter.SetMinimumPaneSize(20)
self.splitter.SetSashPosition(navPanelWidth + scrollBarWidth)
self.thumbPanel.Bind(wx.EVT_CHAR, self.processKeys, self.thumbPanel)
...
Any help appreciated,
Matthew
--
--------------------------------
| Matthew Cahn
| Principal Systems Analyst
| Bristol-Myers Squibb Company
| Mailbox code: H23-05
| P.O. Box 4000
| Princeton, NJ 08543-4000
|
| Phone: (609) 252-3477
| Fax: (609) 252-6030
| Email: ***@bms.com
| Pager: ***@imbta.com
--------------------------------