[Pythonmac-SIG] Re: [wxPython-mac] wxPython for OS X - now with menus!
Kevin Ollivier
kevino@tulane.edu
Wed, 16 Jan 2002 10:26:45 -0500
> Hi actually you are then modifying somebody elses menubar - this is not at
> all a recommended action - event if it works ;-)
I know it is far from ideal behavior, but so far this is the only solution
to the problem I have been able to come up with. The problem is caused
because wxPython scripts are identified as "documents" belonging to Python
instead of applications. So instead of creating a new application, wxPython
code is executed within Python itself. Any attempt to create a new menubar
will fail, because Python already has a menubar. I haven't yet found any
Carbon code for dynamically creating a new Application, but I'm new to Mac
coding so I could be missing something. From what I've found though, it
seems we have to consider Python as a "host" application, which can be taken
over by wxPython when a wxPython script is run. I believe this behavior is
also used by Tkinter on Mac OS 9, but I just ran a couple tests so I could
be wrong. (I actually got the idea when looking at Tk's Mac menu code.)
We could do something like split Python into two executables - one for the
IDE and one which only runs scripts. I'm open to any other suggestions that
could get this working! =)
Also, as a more "gentle" way of handling this issue, I basically added some
code to check and see if a menubar already exists, and if not, create it. So
the code now looks like:
if (GetMenuBar() == NULL) {
Handle menubar = ::GetNewMBar( kwxMacMenuBarResource ) ;
wxString message ;
wxCHECK_RET( menubar != NULL, wxT("can't read MBAR resource"));
::SetMenuBar( menubar ) ;
::DisposeHandle( menubar ) ;
}
I've both run wxPython apps and compiled wxMac apps successfully with this
code. This code as I see it should do no harm - as I understand it, if
GetMenuBar() is not null, the following lines of code will fail anyways.
(Although I realize that it will go ahead and execute the other code.)
GetMenuBar should always return null for wxMac apps, and if GetMenuBar does
not return null, the only plausable situation I can see for that is if
wxWindows is running through a scripting language. Is this correct?
> Could somebody tell me what I need to follow get things building (or where
> to look at them) macos x might be ok for the moment. makes things easier
for
> me to try at the classic level
Yeah, realizing that all these components use Carbon as the GUI code, I
realized that wxPython for Mac Classic may be a realistic option. In any
case, here are the steps to build wxPython on Mac OS X:
Step 1: Get the Python 2.2 source code from www.python.org and build twice.
First as normal (configure/make/make install) and then as instructed in the
dist/src/mac/osx/ folder (from the beginning). This will create both a
"traditional" Python binary (in /usr/local/bin/) and a Carbon-based
Python.app (in /Applications). When you run scripts from the shell, you'll
be using the traditional binary. When you double-click in the Finder, then
you'll use Python.app. (These two will probably merge in the future.)
Step 2: Get the latest CVS of wxWindows and wxPython and build as usual. =)
Step 3: Copy the wxPython folder from
/usr/local/lib/python2.2/site-packages/ to
/Library/Frameworks/Python.Framework/Versions/2.2/python2.2/lib/site-package
s/
Step 4: Double-click on wxPython/demo/demo.py and see what happens!
I believe this is it. Let me know how it goes.
Thanks for your help!
Kevin