My first post to the list, so please bear with me.
I've inherited a wxPython application that was written for Python-2.4.3
and wxPython-2.4.2.4 and which still works on a frozen Lunar Linux box.
However, we've moved to CentOS 4.4 which has a different configuration.
It has Python-2.3 as default and our app needs 2.4 features, so two
weeks ago I installed Python-2.4.4 and wxPython-2.8.0.1 under my $HOME.
Unfortunately the wxPython application seems to lose menu and button
events and I couldn't fot the life of me see why. Eventually I had to
install wxPython-2.4.2.4 under $HOME instead in order to continue working.
I've scoured the online tutorial/getting started pages, and have distilled
the problem down to a relatively short Python program which works on the
CentOS-4.4 / Python-2.4.4 / wxPython-2.4.2.4 combination, but which shows
the same disappearing event problem on my private box at home which has
an up-to-date Lunar Linux / Python-2.5 / wxPython-2.6.3.3
Can anyone tell me what is likely to be wrong in the code below?
- Have I based the event handling on outdated or too new examples?
- Is the event handling at the wrong level? i.e in Frame rather than...
- Is this likely to be a problem with lower level library?
Or does it just work on your systems? On mine, none of the menu items
generates the expected print line, pops up the dialog, or closes the app.
Cheers
Duncan
import wx
class MainWindow(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
menuBar = self._createMenuBar()
self.SetMenuBar(menuBar)
def _createMenuBar(self):
menuBar = wx.MenuBar()
fileMenu = self._createFileMenu()
menuBar.Append(fileMenu, "&File")
return menuBar
def _createFileMenu(self):
fileMenu = wx.Menu()
newId = wx.NewId()
fileMenu.Append(newId, "&New", " new thingy ")
wx.EVT_MENU(self, newId, self.OnNew)
prefsId = wx.NewId()
fileMenu.Append(prefsId, "&Preferences", " preferences thingy ")
wx.EVT_MENU(self, prefsId, self.OnPreferences)
exitId = wx.NewId()
fileMenu.Append(exitId, "E&xit", " exit thingy ")
wx.EVT_MENU(self, exitId, self.OnExit)
return fileMenu
def OnNew(self, unused_event):
print 'MainWindow:OnNew'
def OnPreferences(self, unused_event):
print 'MainWindow:OnPreferences'
d = wx.MessageDialog(self, 'Message Text', 'Title',
wx.OK | wx.ICON_INFORMATION)
d.ShowModal()
d.Destroy()
def OnExit(self, unused_event):
print 'MainWindow:OnExit'
self.Close()
def _main():
app = wx.PySimpleApp(0)
mainWindow = MainWindow(None, wx.ID_ANY, "Testing...")
mainWindow.Show(1)
app.MainLoop()
if __name__ == '__main__':
_main()