I was looking for an up-to-date way of coding with wxPython 2.5.3.x for MacOS X. Here is what I came up with based on stuff I read on the net (this website and others) and looking at the source code to the demo application. Sadly, a lot of the existing documentation uses the old style of importing the wx package so it is confusing to newbie's at first. In addition, this is the one place where I have found a single reference to easily creating the About/Exit documentation for creating the proper responses on the Mac. You may want to view the Migration guide for more information.

import wx
class MainWindow(wx.Frame):
    def __init__(self,parent,id,title):
        wx.Frame.__init__(self,parent,wx.ID_ANY, title, size = (1024,768),
                                     style=wx.DEFAULT_FRAME_STYLE|
                                           wx.NO_FULL_REPAINT_ON_RESIZE)
        self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
        self.CreateStatusBar() # A Statusbar in the bottom of the window
        # Creating the menubar.
        menuBar = wx.MenuBar()
        # Setting up the file menu.
        filemenu = wx.Menu()
        item = filemenu.Append(-1,'E&xit','Terminate the program')
        self.Bind(wx.EVT_MENU, self.OnExit, item)
        if wx.Platform=="__WXMAC__":
            wx.App.SetMacExitMenuItemId(item.GetId())
        menuBar.Append(filemenu,'&File') # Adding the "filemenu" to the MenuBar
        # Setting up the help menu.
        helpmenu = wx.Menu()
        item = helpmenu.Append(-1, '&About\tCtrl-H','Information about this program')
        self.Bind(wx.EVT_MENU, self.OnAbout, item)
        if wx.Platform=="__WXMAC__":
            wx.App.SetMacAboutMenuItemId(item.GetId())
        menuBar.Append(helpmenu,'&Help') # Adding the "helpmenu" to the MenuBar
        self.SetMenuBar(menuBar)  # Adding the MenuBar to the Frame content.
    def OnAbout(self,e):
        d = wx.MessageDialog(self, " A sample editor \n"
                            " in wxPython","About Sample Editor", wx.OK)
                            # Create a message dialog box
        d.ShowModal() # Shows it
        d.Destroy() # finally destroy it when finished.
    def OnExit(self,e):
        self.Close(True)  # Close the frame.
class app(wx.App):
    def OnInit(self):
        frame = MainWindow(None, -1, "Small editor")
        self.SetTopWindow(frame)
        frame.Show()
        return 1
if __name__ == "__main__":
    app = app(0)
    app.MainLoop()

SetMacExitMenuItemId (last edited 2008-03-11 10:50:22 by localhost)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.