From: ata.jaf on
Hi,
I'm newbie to wxPython and need it to develop my little app.
But from start I have problems with tutorials. Because all of them are
compatible with Windows but not so much with Mac.
For example in this code:


import wx

class MainWindow(wx.Frame) :
def __init__(self, parent, title) :
wx.Frame.__init__(self, parent, title=title, size=(200, 100))
self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
self.CreateStatusBar()

filemenu = wx.Menu()

filemenu.Append(wx.ID_ABOUT, '&About', ' Information about this
program.')
filemenu.AppendSeparator()
filemenu.Append(wx.ID_EXIT, 'E&xit', ' Terminate the program')

menuBar = wx.MenuBar()
menuBar.Append(filemenu, '&File')
self.SetMenuBar(menuBar)
self.Show(True)

app = wx.App(False)
frame = MainWindow(None, 'Sample editor')
app.MainLoop()



The menus doesn't appear in the product.
Can anyone help me to find a tutorial that is for using wxPython on a
Mac?
Thanks
Ata
From: David Bolen on
"ata.jaf" <a.j.romanista(a)gmail.com> writes:

> import wx
>
> class MainWindow(wx.Frame) :
> def __init__(self, parent, title) :
> wx.Frame.__init__(self, parent, title=title, size=(200, 100))
> self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
> self.CreateStatusBar()
>
> filemenu = wx.Menu()
>
> filemenu.Append(wx.ID_ABOUT, '&About', ' Information about this
> program.')
> filemenu.AppendSeparator()
> filemenu.Append(wx.ID_EXIT, 'E&xit', ' Terminate the program')
>
> menuBar = wx.MenuBar()
> menuBar.Append(filemenu, '&File')
> self.SetMenuBar(menuBar)
> self.Show(True)
>
> app = wx.App(False)
> frame = MainWindow(None, 'Sample editor')
> app.MainLoop()
>
> The menus doesn't appear in the product.
> Can anyone help me to find a tutorial that is for using wxPython on a
> Mac?

I think the menus are actually working as designed, and they are
present, but just not perhaps what or where you expected. That's
because some of the standard IDs (e.g., wx.ID_ABOUT) and some names
(e.g., "E&xit") are adjusted under OSX to conform to that platform's
menu standard. This is actually to your benefit, as you can use the
same wxPython code to get menus on each platform to which users on
that platform will be familiar.

So for example, ID_ABOUT and ID_EXIT are always under the Application
menu (and E&xit becomes &Quit) which is where Mac users expect them to
be. Mac users would be quite confused if your application exited with
Command-x rather than Command-Q.

See http://wiki.wxpython.org/Optimizing%20for%20Mac%20OS%20X for a
little more information. There are also a series of methods on wxApp
if you want finer control over this (such as SetMacAboutMenuItemId,
SetMacExitMenuItemId, SetMacPreferencesMenuItemId) but using the
standard ID_* names does it automatically.

If you're looking for your own specific menus, I'd just switch away
from the standard ids and names. For example, if you switched the
wx.ID_* in the above to -1, you'd see them show up under the File menu
rather than relocated to the Application menu. Although "E&xit" would
still get replaced with "&Quit".

But if you are in fact setting up a menu for an application exit, I'd
let wxPython do what it's doing, as your application will appear
"normal" to users on the Mac.

I'd also suggest moving over to the wxPython mailing list for followup
questions as there are more folks there familiar with wxPython.

-- David