Menus work on Windows and Linux but not Mac

In my application (VPython based on wxPython) I create menus in the usual way, and they appear and function on Windows and Linux (Xubuntu as it happens) but not on the Mac. Instead, on the Mac there is a single menu, named “Python”, and the choices are Services, Hide Python, Hide Others, Show All (grayed out), and Quit Python (which does nothing).

Does this ring a bell with anyone? It’s a bit hard for me to imagine that I’m doing something very wrong, since menus work fine on two out of three of the major platforms. I’m using wxPython 2.9.4 with 32-bit and 64-bit versions of Python 2.7.

I’ll mention that Steve Spicklemire (who has been contributing a lot to the project) and I are about to release a fully functional VPython based on wxPython, which makes it possible to put an easy-to-program VPython 3D OpenGL canvas in a window along with wxPython widgets. For those not familiar with VPython (vpython.org), the following is a complete program that displays a 3D cube and lets you zoom and rotate with the mouse:

from visual import *

box()

In my application (VPython based on wxPython) I create menus in the usual way, and they appear and function on Windows and Linux (Xubuntu as it happens) but not on the Mac. Instead, on the Mac there is a single menu, named "Python", and the choices are Services, Hide Python, Hide Others, Show All (grayed out), and Quit Python (which does nothing).

Does this ring a bell with anyone? It's a bit hard for me to imagine that I'm doing something very wrong, since menus work fine on two out of three of the major platforms. I'm using wxPython 2.9.4 with 32-bit and 64-bit versions of Python 2.7.

I'll mention that Steve Spicklemire (who has been contributing a lot to the project) and I are about to release a fully functional VPython based on wxPython, which makes it possible to put an easy-to-program VPython 3D OpenGL canvas in a window along with wxPython widgets. For those not familiar with VPython (vpython.org), the following is a complete program that displays a 3D cube and lets you zoom and rotate with the mouse:

from visual import *
box()

Hi Bruce,

The Mac is a rather different animal and its menus are a bit different. OS X adds some things of its own whether you want them or not and moves things around a bit to make them more Mac-standard. Because of this, you need to be careful about using standard menu ids (wx.ID_CUT, wx.ID_COPY, wx.ID_PASTE, wx.ID_EXIT, wx.ID_PREFERENCES, wx.ID_HELP, wx.ID_ABOUT, for example). There are a number of special commands for interacting with the Mac menu (like wx.App_SetMacHelpMenuTitleName(_("&Help")) , which I use to localize the Help Menu's name based on the language the user selects for my program rather than using the OS's default language). I recall that I have to do something to turn off the Mac's Window menu, but I can't seem to find it in my code at the moment.

But the Mac Menu feature that's most crazy-making for me is that you can't have different menus for different program windows. You get one menu for the program. In my program, I deal with video, text, images, etc. and I wish I could have different menus when I'm working with different data types, as the user can do very different things. But no. Can't do it. At the moment, if I load my still image popup window, it replaces my program menu on the Mac with my still image handling menu, and when I close the still image popup window, the program loses its menu entirely and crashes. I'm in the process of working out alternate ways to do the things most easily (and properly in my mind) handled within a menu structure so I can skip instantiating the menu for still images on the Mac.

This is a long way of saying that you may be instantiating your menus in sub-windows rather than your main program window, and if this is the case, I'd expect exactly the kinds of symptoms you describe. There's a page on the wxPython wiki about cross-platform development (maybe wiki.wxpython.org/Optimizing for Mac OS X) that talks about this, but it's been a couple of years since I've looked at it. (Sorry, I'm late and need to run, so don't have time to track it down further for you.)

Be prepared to write some platform specific code to handle the menu issues. Good luck.

David

Unfortunately, I’m aware of these Mac issues and have tried to write my code as recommended. I tried running the example program at

http://wiki.wxpython.org/Optimizing%20for%20Mac%20OS%20X

and it doesn’t work properly, either. It does do something (whereas my code does nothing), but what it does do is a mess. I’m running Mac 10.6.8 with 32-bit Python 2.7 (and a collaborator who sees the same problems is running 64-bit Python 2.7 on a later OSX), using wxPython 2.9.4 with Cocoa.

Here is the key segment of my code:

class window(_wx.Frame):

def init(self, _make_panel=True, x=0, y=0, width=600, height=600, title=‘VPython’):

win = _wx.Frame(None, -1, title, pos=(x, y), style=_wx.DEFAULT_FRAME_STYLE)

menubar = _wx.MenuBar()

menu = _wx.Menu()

item = menu.Append(_wx.ID_EXIT, “E&xit\tCtrl-Q”, “Exit”)

win.Bind(_wx.EVT_MENU, self._OnExitApp, item)

menubar.Append(menu, “&File”)

win.SetMenuBar(self.menubar)

I repeat that everything works fine on Windows and Linux.

I guess I should add that I also try adding to the menu bar a second menu “Options” with several entries, and it doesn’t show up, either. The wiki demo also makes additional menus, with messed-up results.

Bruce,

A few notes: Things are different the Mac, and wx tried to make things
native be default, so much of what you see is supposed to be done that
way. Which doesn't mean something isn't broken, of course, but the
basics are there.

I guess I should add that I also try adding to the menu bar a second menu
"Options" with several entries, and it doesn't show up, either. The wiki
demo also makes additional menus, with messed-up results.

The only menu the Wiki example adds is the File menu -- and on my
machine that shows up.

The "Exit" and "preferences" items get moved to the app menu

The "about" item from the help menu also gets moved there.

  -- that is all the Mac standard.

Are you seeing something else? what is "messed up" about it?

I also try adding to the menu bar a second menu
"Options" with several entries, and it doesn't show up, either.

That should work.

Could you try posting a minimal sample app that shows the problem --
maybe and edited version of the one in the Wiki (NOTE: that was
written a while ago, before the Cocoa version of wxMac, so it could
need some updating)

Instead, on the Mac there is a single menu, named "Python", and the choices are Services, > Hide Python, Hide Others, Show All (grayed out), and Quit Python (which does nothing).

That should all be there, yes -- though quit should work. Are you
using wx.ID_EXIT for the id for your exit or quit menu item?

That menu that says "Python" is the application menu -- if you want it
to have the proper applicaiton name, you need to put your app in a
bundle with py2app -- as outlined on that Wiki page.

(py2app has an "alias" mode, which creates a bundle that contians
links to the original code -- a good way to test it all out and/or run
code under active development.

HTH,
  -Chris

PS: a wxPython VPython is very cool -- nice work!

···

On Thu, Jan 24, 2013 at 7:21 PM, Bruce Sherwood <bruce.sherwood@gmail.com> wrote:

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

It's a bit hard for me to imagine that I'm doing something very
wrong, since menus work fine on two out of three of the major
platforms. I'm using wxPython 2.9.4 with 32-bit and 64-bit versions
of Python 2.7.

Have you tried the wxPython-Mac mailinglist?

<http://groups.google.com/group/wxpython-mac/subscribe?hl=en_US&gt;,
<mailto:wxpython-mac+subscribe@googlegroups.com>

Sincerely,

Wolfgang

Bruce Sherwood wrote:

In my application (VPython based on wxPython) I create menus in the
usual way, and they appear and function on Windows and Linux (Xubuntu as
it happens) but not on the Mac. Instead, on the Mac there is a single
menu, named "Python", and the choices are Services, Hide Python, Hide
Others, Show All (grayed out), and Quit Python (which does nothing).

Does this ring a bell with anyone? It's a bit hard for me to imagine
that I'm doing something very wrong, since menus work fine on two out of
three of the major platforms. I'm using wxPython 2.9.4 with 32-bit and
64-bit versions of Python 2.7.

If you're not running a framework build of Python then it can cause weird things to happen to the menubar. Where did the Python come from? In other words, is it Apple's, Python.org's, MacPorts, Homebrew, built it yourself? Any should work if built and used correctly, but Python from Python.org is usually the easiest.

···

--
Robin Dunn
Software Craftsman

VPython has always used Pythons from vpython.org. I guess as suggested I have to create a small application that hopefully can demonstrate the problem I see in the VPython context.

You might like to see how far we’ve gotten, with lots of help from this wxPython community. Below is a screen shot of the wxPython-based VPython (the image of this demo came from Windows and also displays correctly on Linux; everything but the menus works on a Mac). In the past, the 3D canvas had to fill the window; there couldn’t be other widgets in the window. In the program, the 3D cube rotates, and the controls let you change the color, the rotation speed, and the rotation direction, and you can also type into the text control.

The 3D portion of the code is pretty trivial. The first statement creates a window and the second places an OpenGL canvas in the left half of the window. You’ll note that some adjustment is made so that the canvas is L*L but the window is larger.

w = window(width=2*(L+window.get_dw()), height=L+window.get_dh(), title=‘Widgets’)

display(window=w, y = 0, width=L, height=L, forward=-vector(0,1,2))

cube = box(color=color.red)

… wxPython code to make widgets for setting color, and rotation speed and direction

while True:

rate(100)

cube.rotate(axis=(0,1,0), angle=cube.dir*cube.dtheta)

Of equal importance to widgets is the fact that it was possible to eliminate very nearly all platform-dependent C++ code (there are small instances of platform-dependent Python code, but that’s trivial). The only remaining platform-dependent C++ code is GetProcAddress. Of critical importance is that the new VPython works on 64-bit Cocoa-based Macs, something that was impossible with the old VPython, which was Carbon-based.

I’ve also run up against a significant platform-dependent display issue which I’ve “solved” temporarily on one particular Linux with hard-coded integers. The VPython API has always had the user specify the width and height of a window as the outer bounds, so that one can easily place (say) two windows adjacent to each other or one below the other, with the canvas being smaller than that. I need to know the dimensions of the writable area, but unfortunately only for Windows will wxWidgets give me the dimensions of borders, title bar, and menu bar. For Mac and Linux, the values are all -1. For both Windows and Mac, these values are probably extremely stable (I use hard-coded integers for the Mac), but on different distributions of Linux, or for different window managers on the same Linux, I don’t know how to get the dimension information I need.

Note that my problems are somewhat different from those using wxPython to create apps. VPython is middleware; people use VPython to create apps. This puts an additional burden on VPython to be universally cross-platform, not just cross-platform for a particular app.

Availability note: At vpython.org one can get an experimental version of the wxPython-based VPython, but the support for widgets isn’t yet included even in that experimental package. However, the up-to-date source code is available at

https://github.com/BruceSherwood/vpython-wx.

image.jpeg

One other suggestion – try your app with wxPython 2.8.12.1 rather
than 2.9.4.0. I downgraded my wxPython version today and a number
of mysterious Mac-only interface problems I was having have
disappeared. Still investigating that.
David

···

On 01/25/2013 02:57 PM, Bruce Sherwood
wrote:

VPython has always used Pythons from vpython.org .
I guess as suggested I have to create a small application that
hopefully can demonstrate the problem I see in the VPython
context.

      You might like to see how far we've gotten, with

lots of help from this wxPython community. Below is a screen
shot of the wxPython-based VPython (the image of this demo
came from Windows and also displays correctly on Linux;
everything but the menus works on a Mac). In the past, the 3D
canvas had to fill the window; there couldn’t be other widgets
in the window. In the program, the 3D cube rotates, and the
controls let you change the color, the rotation speed, and the
rotation direction, and you can also type into the text
control.

      The 3D portion of the code is pretty trivial. The

first statement creates a window and the second places an
OpenGL canvas in the left half of the window. You’ll note that
some adjustment is made so that the canvas is L*L but the
window is larger.

        w = window(width=2*(L+window.get_dw()),

height=L+window.get_dh(), title=‘Widgets’)

        display(window=w, y = 0, width=L, height=L,

forward=-vector(0,1,2))

cube = box(color=color.red)

        ... wxPython code to make widgets for setting

color, and rotation speed and direction

while True:

rate(100)

cube.rotate(axis=(0,1,0), angle=cube.dir*cube.dtheta)

      Of equal importance to widgets is the fact that it

was possible to eliminate very nearly all platform-dependent
C++ code (there are small instances of platform-dependent
Python code, but that’s trivial). The only remaining
platform-dependent C++ code is GetProcAddress. Of critical
importance is that the new VPython works on 64-bit Cocoa-based
Macs, something that was impossible with the old VPython,
which was Carbon-based.

      I've also run up against a significant

platform-dependent display issue which I’ve “solved”
temporarily on one particular Linux with hard-coded integers.
The VPython API has always had the user specify the width and
height of a window as the outer bounds, so that one can easily
place (say) two windows adjacent to each other or one below
the other, with the canvas being smaller than that. I need to
know the dimensions of the writable area, but unfortunately
only for Windows will wxWidgets give me the dimensions of
borders, title bar, and menu bar. For Mac and Linux, the
values are all -1. For both Windows and Mac, these values are
probably extremely stable (I use hard-coded integers for the
Mac), but on different distributions of Linux, or for
different window managers on the same Linux, I don’t know how
to get the dimension information I need.

      Note that my problems are somewhat different from

those using wxPython to create apps. VPython is middleware;
people use VPython to create apps. This puts an additional
burden on VPython to be universally cross-platform, not just
cross-platform for a particular app.

Availability note: At vpython.org one can get an
experimental version of the wxPython-based VPython, but the
support for widgets isn’t yet included even in that
experimental package. However, the up-to-date source code is
available at

https://github.com/BruceSherwood/vpython-wx.

  --

  To unsubscribe, send email to

or visit

wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en

I have to use 2.9. On November 24, 2012 I reported the following central problem, which went away when I moved from 2.8 to 2.9:

The statement “evtloop = wx.GUIEventLoop()” works on 64-bit Python 2.7 on a Mac and on 32-bit Python 2.7 on Windows, but on 64-bit Python 2.7 for Windows I get the error message

AttributeError: ‘module’ object has no attribute ‘GUIEventLoop’

···

On Fri, Jan 25, 2013 at 2:02 PM, David Woods transana@gmail.com wrote:

  On 01/25/2013 02:57 PM, Bruce Sherwood

wrote:

VPython has always used Pythons from vpython.org .
I guess as suggested I have to create a small application that
hopefully can demonstrate the problem I see in the VPython
context.

One other suggestion -- try your app with wxPython 2.8.12.1 rather

than 2.9.4.0. I downgraded my wxPython version today and a number
of mysterious Mac-only interface problems I was having have
disappeared. Still investigating that.

David

As suggested, I’ve written a minimal program that works on Windows and fails on Mac.

The Mac symptoms are that there is no Options menu, only a Python menu, which has the choices Services, Hide Python, Hide Others, Show All (grayed out), and Quit Python. Clicking the close button on the window does close the window, but choosing menu choice “Quit Python” does nothing.

The window does appear, it has the specified title, and I can move and resize it.

This is with 32-bit Python 2.7.3 on a MacBook Pro running OSX 10.6.8, using wxPython 2.9.3.1-cocoa.

import wx

from time import sleep

def one(evt):

print(‘one’)

def two(evt):

print(‘two’)

def create():

win = wx.Frame(None, -1, ‘Menu Demo’, pos=(50,50), style=wx.DEFAULT_FRAME_STYLE)

p = wx.Panel(win)

m = wx.MenuBar()

menu = wx.Menu()

item = menu.Append(-1, ‘One’)

win.Bind(wx.EVT_MENU, one, item)

item = menu.Append(-1, ‘Two’)

win.Bind(wx.EVT_MENU, two, item)

m.Append(menu, ‘Options’)

win.SetMenuBar(m)

win.SetSize((300,150))

win.Show(True)

App = wx.App()

evtloop = wx.GUIEventLoop()

wx.EventLoop.SetActive(evtloop)

isMac = (‘wxOSX’ in wx.PlatformInfo)

def Interact():

while not evtloop.Pending() and evtloop.ProcessIdle(): pass

if wx.GetApp(): wx.GetApp().ProcessPendingEvents()

if isMac and not evtloop.Dispatch(): return

Currently on wxOSX Pending always returns true, so the

ProcessIdle above is not ever called. Call it here instead.

if isMac: evtloop.ProcessIdle()

while True:

checkAgain = False

if wx.GetApp() and wx.GetApp().HasPendingEvents():

wx.GetApp().ProcessPendingEvents()

checkAgain = True

if not isMac and evtloop.Pending():

evtloop.Dispatch()

checkAgain = True

if not checkAgain:

break

create()

while True:

Interact()

sleep(0.03)

Correction. I’m using wxPython 2.9.4.0-cocoa.

Bruce Sherwood wrote:

As suggested, I've written a minimal program that works on Windows and
fails on Mac.

The Mac symptoms are that there is no Options menu, only a Python menu,
which has the choices Services, Hide Python, Hide Others, Show All
(grayed out), and Quit Python. Clicking the close button on the window
does close the window, but choosing menu choice "Quit Python" does nothing.

The window does appear, it has the specified title, and I can move and
resize it.

This is with 32-bit Python 2.7.3 on a MacBook Pro running OSX 10.6.8,
using wxPython 2.9.3.1-cocoa.

I had forgotten that you were replacing the main event loop, and that seems to be the source of the problem here. Calling App.MainLoop instead of doing your while True: Interact()... loop solves the menu problem, although I realize that doesn't meet your needs. It seems that there is something extra that needs to be done for the Mac menu bar to be usable from wx.Frames, and that something is happening upon entry to wx.App.MainLoop or shortly thereafter. I'll try to poke around later and see if I can figure out what it is, but we may be out of luck on this one.

···

--
Robin Dunn
Software Craftsman

Oh dear. I’ll keep my fingers crossed. It would be really unfortunate if menus can’t work in VPython on the Mac, especially since they work fine on Windows and Linux.

I’m trying to help track this down… I’ve discovered that while most events are getting dispatched OK, menu events are not.

Find below the example app I’m using to test. It’s a simple variation of Bruce’s example with a switch to use the Interact loop or the MainLoop() method.

If I use the MainLoop and click on a menu item, control eventually trickles down to menuNeedsUpdate:

#2 0x00000001016995c8 in wxMenu::HandleMenuOpened (this=0x103686600) at menu_osx.cpp:468

#3 0x00000001017b4f72 in -[wxNSMenuController menuNeedsUpdate:] (self=0x103682d00, _cmd=0x7fff958d1dc0, smenu=0x103685ba0) at menu.mm:93

#4 0x00007fff950d9c09 in -[NSMenu _populateFromDelegateWithEventRef:] ()

#5 0x00007fff94fce38c in -[NSMenu _populateWithEventRef:] ()

#6 0x00007fff950d8e33 in -[NSCarbonMenuImpl _carbonPopulateEvent:handlerCallRef:] ()

#7 0x00007fff950d89bb in NSSLMMenuEventHandler ()

#8 0x00007fff9381c234 in DispatchEventToHandlers ()

#9 0x00007fff9381b840 in SendEventToEventTargetInternal ()

#10 0x00007fff9381b67a in SendEventToEventTargetWithOptions ()

#11 0x00007fff9384dd29 in SendMenuPopulate ()

#12 0x00007fff9399a195 in SendMenuOpening ()

#13 0x00007fff9399d6d9 in DrawTheMenu ()

#14 0x00007fff9399dbe3 in MenuChanged ()

#15 0x00007fff9386da2f in TrackMenuCommon ()

#16 0x00007fff93868f13 in MenuSelectCore ()

#17 0x00007fff93868592 in _HandleMenuSelection2 ()

#18 0x00007fff94fd91da in _NSHandleCarbonMenuEvent ()

#19 0x00007fff94f6ecc9 in _DPSNextEvent ()

#20 0x00007fff94f6e07d in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()

#21 0x00007fff94f6a9b9 in -[NSApplication run] ()

#22 0x00000001017a84cc in wxGUIEventLoop::DoRun (this=0x1003aa670) at evtloop.mm:246

#23 0x00000001015a4d63 in wxCFEventLoop::Run (this=0x1003aa670) at evtloop_cf.cpp:403

#24 0x00000001013ed889 in wxAppConsoleBase::MainLoop (this=0x1045097a0) at appbase.cpp:314

#25 0x00000001010d5f9f in wxPyApp::MainLoop (this=0x1045097a0) at helpers.cpp:215

#26 0x00000001010ff649 in _wrap_PyApp_MainLoop (unnamed_arg=0x0, args=0x10056d610) at _core_wrap.cpp:34287

#27 0x00000001000c22c2 in PyEval_EvalFrameEx ()

#28 0x00000001000c4149 in PyEval_EvalCodeEx ()

#29 0x000000010003d910 in function_call ()

#30 0x000000010000c362 in PyObject_Call ()

#31 0x000000010001e97b in instancemethod_call ()

#32 0x000000010000c362 in PyObject_Call ()

#33 0x00000001000bf2c8 in PyEval_EvalFrameEx ()

#34 0x00000001000c286d in PyEval_EvalFrameEx ()

#35 0x00000001000c286d in PyEval_EvalFrameEx ()

#36 0x00000001000c4149 in PyEval_EvalCodeEx ()

#37 0x00000001000c4266 in PyEval_EvalCode ()

#38 0x00000001000e8a0c in PyRun_InteractiveOneFlags ()

#39 0x00000001000e8c6e in PyRun_InteractiveLoopFlags ()

#40 0x00000001000e9451 in PyRun_AnyFileExFlags ()

#41 0x000000010010006d in Py_Main ()

#42 0x0000000100000f14 in dyld_stub_strlen ()

Current language: auto; currently c++

(gdb)

On the other hand… if I use the InteractLoop this never gets called. I did check that the NSMenuController is getting created correctly when the menus are initialized in the “create()” function of the python script. As far as non-menu event handling it seems to wind up in the CommonModeObserverCallBack in either case. Here’s the MainLoop version:

#0 wxCFEventLoop::CommonModeObserverCallBack (this=0x104a3dde0, unnamed_arg=0x104a25270, activity=2) at evtloop_cf.cpp:156

#1 0x00000001015a441b in wxCFEventLoop::OSXCommonModeObserverCallBack (observer=0x104a25270, activity=2, info=0x104a3dde0) at evtloop_cf.cpp:144

#2 0x00007fff8f0378e7 in CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION ()

#3 0x00007fff8f037846 in __CFRunLoopDoObservers ()

#4 0x00007fff8f00caf9 in __CFRunLoopRun ()

#5 0x00007fff8f00c486 in CFRunLoopRunSpecific ()

#6 0x00007fff938162bf in RunCurrentEventLoopInMode ()

#7 0x00007fff9381d4bf in ReceiveNextEventCommon ()

#8 0x00007fff9381d3fa in BlockUntilNextEventMatchingListInMode ()

#9 0x00007fff94f6e779 in _DPSNextEvent ()

#10 0x00007fff94f6e07d in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()

#11 0x00007fff94f6a9b9 in -[NSApplication run] ()

#12 0x00000001017a84cc in wxGUIEventLoop::DoRun (this=0x104a3dde0) at evtloop.mm:246

#13 0x00000001015a4d63 in wxCFEventLoop::Run (this=0x104a3dde0) at evtloop_cf.cpp:403

#14 0x00000001013ed889 in wxAppConsoleBase::MainLoop (this=0x10365d880) at appbase.cpp:314

#15 0x00000001010d5f9f in wxPyApp::MainLoop (this=0x10365d880) at helpers.cpp:215

#16 0x00000001010ff649 in _wrap_PyApp_MainLoop (unnamed_arg=0x0, args=0x10056d610) at _core_wrap.cpp:34287

#17 0x00000001000c22c2 in PyEval_EvalFrameEx ()

#18 0x00000001000c4149 in PyEval_EvalCodeEx ()

#19 0x000000010003d910 in function_call ()

#20 0x000000010000c362 in PyObject_Call ()

#21 0x000000010001e97b in instancemethod_call ()

#22 0x000000010000c362 in PyObject_Call ()

#23 0x00000001000bf2c8 in PyEval_EvalFrameEx ()

#24 0x00000001000c286d in PyEval_EvalFrameEx ()

#25 0x00000001000c286d in PyEval_EvalFrameEx ()

#26 0x00000001000c4149 in PyEval_EvalCodeEx ()

#27 0x00000001000c4266 in PyEval_EvalCode ()

#28 0x00000001000e8a0c in PyRun_InteractiveOneFlags ()

#29 0x00000001000e8c6e in PyRun_InteractiveLoopFlags ()

#30 0x00000001000e9451 in PyRun_AnyFileExFlags ()

#31 0x000000010010006d in Py_Main ()

#32 0x0000000100000f14 in dyld_stub_strlen ()

And here’s the Interact Loop:

#0 wxCFEventLoop::CommonModeObserverCallBack (this=0x104b64160, unnamed_arg=0x104b6cbc0, activity=2) at evtloop_cf.cpp:156

#1 0x00000001015a441b in wxCFEventLoop::OSXCommonModeObserverCallBack (observer=0x104b6cbc0, activity=2, info=0x104b64160) at evtloop_cf.cpp:144

#2 0x00007fff8f0378e7 in CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION ()

#3 0x00007fff8f037846 in __CFRunLoopDoObservers ()

#4 0x00007fff8f00caf9 in __CFRunLoopRun ()

#5 0x00007fff8f00c486 in CFRunLoopRunSpecific ()

#6 0x00007fff938162bf in RunCurrentEventLoopInMode ()

#7 0x00007fff9381d4bf in ReceiveNextEventCommon ()

#8 0x00007fff9381d3fa in BlockUntilNextEventMatchingListInMode ()

#9 0x00007fff94f6e779 in _DPSNextEvent ()

#10 0x00007fff94f6e07d in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()

#11 0x00000001017a8809 in wxGUIEventLoop::DoDispatchTimeout (this=0x104b64160, timeout=0) at evtloop.mm:232

#12 0x00000001015a4051 in wxCFEventLoop::DispatchTimeout (this=0x104b64160, timeout=0) at evtloop_cf.cpp:314

#13 0x00000001015a3fb1 in wxCFEventLoop::DoProcessEvents (this=0x104b64160) at evtloop_cf.cpp:301

#14 0x00000001015a3fde in wxCFEventLoop::Dispatch (this=0x104b64160) at evtloop_cf.cpp:306

#15 0x00000001010fdafc in _wrap_EventLoopBase_Dispatch (unnamed_arg=0x0, args=0x1005bc850) at _core_wrap.cpp:35858

#16 0x00000001000c22c2 in PyEval_EvalFrameEx ()

#17 0x00000001000c4149 in PyEval_EvalCodeEx ()

#18 0x00000001000c1a3d in PyEval_EvalFrameEx ()

#19 0x00000001000c286d in PyEval_EvalFrameEx ()

#20 0x00000001000c286d in PyEval_EvalFrameEx ()

#21 0x00000001000c4149 in PyEval_EvalCodeEx ()

#22 0x00000001000c4266 in PyEval_EvalCode ()

#23 0x00000001000e8a0c in PyRun_InteractiveOneFlags ()

#24 0x00000001000e8c6e in PyRun_InteractiveLoopFlags ()

#25 0x00000001000e9451 in PyRun_AnyFileExFlags ()

#26 0x000000010010006d in Py_Main ()

#27 0x0000000100000f14 in dyld_stub_strlen ()

Current language: auto; currently c++

Both wind up in _DPSNextEvent(). While it’s handled correctly for “regular” events, either the Menu events are not getting generated, or they are not being handled. Is it possible there are some events being created and/or handled in the MainLoop() version that aren’t in the Interact?

Any insight appreciated!

thanks,

-steve

···

On Tuesday, January 29, 2013 12:59:42 PM UTC-7, Bruce Sherwood wrote:

Oh dear. I’ll keep my fingers crossed. It would be really unfortunate if menus can’t work in VPython on the Mac, especially since they work fine on Windows and Linux.

Oh… here’s the test script!

-steve

testMenu.py (1.39 KB)

···

On Sunday, February 3, 2013 9:40:49 AM UTC-7, Steve Spicklemire wrote:

I’m trying to help track this down… I’ve discovered that while most events are getting dispatched OK, menu events are not.

Find below the example app I’m using to test. It’s a simple variation of Bruce’s example with a switch to use the Interact loop or the MainLoop() method.

If I use the MainLoop and click on a menu item, control eventually trickles down to menuNeedsUpdate:

#2 0x00000001016995c8 in wxMenu::HandleMenuOpened (this=0x103686600) at menu_osx.cpp:468

#3 0x00000001017b4f72 in -[wxNSMenuController menuNeedsUpdate:] (self=0x103682d00, _cmd=0x7fff958d1dc0, smenu=0x103685ba0) at menu.mm:93

#4 0x00007fff950d9c09 in -[NSMenu _populateFromDelegateWithEventRef:] ()

#5 0x00007fff94fce38c in -[NSMenu _populateWithEventRef:] ()

#6 0x00007fff950d8e33 in -[NSCarbonMenuImpl _carbonPopulateEvent:handlerCallRef:] ()

#7 0x00007fff950d89bb in NSSLMMenuEventHandler ()

#8 0x00007fff9381c234 in DispatchEventToHandlers ()

#9 0x00007fff9381b840 in SendEventToEventTargetInternal ()

#10 0x00007fff9381b67a in SendEventToEventTargetWithOptions ()

#11 0x00007fff9384dd29 in SendMenuPopulate ()

#12 0x00007fff9399a195 in SendMenuOpening ()

#13 0x00007fff9399d6d9 in DrawTheMenu ()

#14 0x00007fff9399dbe3 in MenuChanged ()

#15 0x00007fff9386da2f in TrackMenuCommon ()

#16 0x00007fff93868f13 in MenuSelectCore ()

#17 0x00007fff93868592 in _HandleMenuSelection2 ()

#18 0x00007fff94fd91da in _NSHandleCarbonMenuEvent ()

#19 0x00007fff94f6ecc9 in _DPSNextEvent ()

#20 0x00007fff94f6e07d in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()

#21 0x00007fff94f6a9b9 in -[NSApplication run] ()

#22 0x00000001017a84cc in wxGUIEventLoop::DoRun (this=0x1003aa670) at evtloop.mm:246

#23 0x00000001015a4d63 in wxCFEventLoop::Run (this=0x1003aa670) at evtloop_cf.cpp:403

#24 0x00000001013ed889 in wxAppConsoleBase::MainLoop (this=0x1045097a0) at appbase.cpp:314

#25 0x00000001010d5f9f in wxPyApp::MainLoop (this=0x1045097a0) at helpers.cpp:215

#26 0x00000001010ff649 in _wrap_PyApp_MainLoop (unnamed_arg=0x0, args=0x10056d610) at _core_wrap.cpp:34287

#27 0x00000001000c22c2 in PyEval_EvalFrameEx ()

#28 0x00000001000c4149 in PyEval_EvalCodeEx ()

#29 0x000000010003d910 in function_call ()

#30 0x000000010000c362 in PyObject_Call ()

#31 0x000000010001e97b in instancemethod_call ()

#32 0x000000010000c362 in PyObject_Call ()

#33 0x00000001000bf2c8 in PyEval_EvalFrameEx ()

#34 0x00000001000c286d in PyEval_EvalFrameEx ()

#35 0x00000001000c286d in PyEval_EvalFrameEx ()

#36 0x00000001000c4149 in PyEval_EvalCodeEx ()

#37 0x00000001000c4266 in PyEval_EvalCode ()

#38 0x00000001000e8a0c in PyRun_InteractiveOneFlags ()

#39 0x00000001000e8c6e in PyRun_InteractiveLoopFlags ()

#40 0x00000001000e9451 in PyRun_AnyFileExFlags ()

#41 0x000000010010006d in Py_Main ()

#42 0x0000000100000f14 in dyld_stub_strlen ()

Current language: auto; currently c++

(gdb)

On the other hand… if I use the InteractLoop this never gets called. I did check that the NSMenuController is getting created correctly when the menus are initialized in the “create()” function of the python script. As far as non-menu event handling it seems to wind up in the CommonModeObserverCallBack in either case. Here’s the MainLoop version:

#0 wxCFEventLoop::CommonModeObserverCallBack (this=0x104a3dde0, unnamed_arg=0x104a25270, activity=2) at evtloop_cf.cpp:156

#1 0x00000001015a441b in wxCFEventLoop::OSXCommonModeObserverCallBack (observer=0x104a25270, activity=2, info=0x104a3dde0) at evtloop_cf.cpp:144

#2 0x00007fff8f0378e7 in CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION ()

#3 0x00007fff8f037846 in __CFRunLoopDoObservers ()

#4 0x00007fff8f00caf9 in __CFRunLoopRun ()

#5 0x00007fff8f00c486 in CFRunLoopRunSpecific ()

#6 0x00007fff938162bf in RunCurrentEventLoopInMode ()

#7 0x00007fff9381d4bf in ReceiveNextEventCommon ()

#8 0x00007fff9381d3fa in BlockUntilNextEventMatchingListInMode ()

#9 0x00007fff94f6e779 in _DPSNextEvent ()

#10 0x00007fff94f6e07d in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()

#11 0x00007fff94f6a9b9 in -[NSApplication run] ()

#12 0x00000001017a84cc in wxGUIEventLoop::DoRun (this=0x104a3dde0) at evtloop.mm:246

#13 0x00000001015a4d63 in wxCFEventLoop::Run (this=0x104a3dde0) at evtloop_cf.cpp:403

#14 0x00000001013ed889 in wxAppConsoleBase::MainLoop (this=0x10365d880) at appbase.cpp:314

#15 0x00000001010d5f9f in wxPyApp::MainLoop (this=0x10365d880) at helpers.cpp:215

#16 0x00000001010ff649 in _wrap_PyApp_MainLoop (unnamed_arg=0x0, args=0x10056d610) at _core_wrap.cpp:34287

#17 0x00000001000c22c2 in PyEval_EvalFrameEx ()

#18 0x00000001000c4149 in PyEval_EvalCodeEx ()

#19 0x000000010003d910 in function_call ()

#20 0x000000010000c362 in PyObject_Call ()

#21 0x000000010001e97b in instancemethod_call ()

#22 0x000000010000c362 in PyObject_Call ()

#23 0x00000001000bf2c8 in PyEval_EvalFrameEx ()

#24 0x00000001000c286d in PyEval_EvalFrameEx ()

#25 0x00000001000c286d in PyEval_EvalFrameEx ()

#26 0x00000001000c4149 in PyEval_EvalCodeEx ()

#27 0x00000001000c4266 in PyEval_EvalCode ()

#28 0x00000001000e8a0c in PyRun_InteractiveOneFlags ()

#29 0x00000001000e8c6e in PyRun_InteractiveLoopFlags ()

#30 0x00000001000e9451 in PyRun_AnyFileExFlags ()

#31 0x000000010010006d in Py_Main ()

#32 0x0000000100000f14 in dyld_stub_strlen ()

And here’s the Interact Loop:

#0 wxCFEventLoop::CommonModeObserverCallBack (this=0x104b64160, unnamed_arg=0x104b6cbc0, activity=2) at evtloop_cf.cpp:156

#1 0x00000001015a441b in wxCFEventLoop::OSXCommonModeObserverCallBack (observer=0x104b6cbc0, activity=2, info=0x104b64160) at evtloop_cf.cpp:144

#2 0x00007fff8f0378e7 in CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION ()

#3 0x00007fff8f037846 in __CFRunLoopDoObservers ()

#4 0x00007fff8f00caf9 in __CFRunLoopRun ()

#5 0x00007fff8f00c486 in CFRunLoopRunSpecific ()

#6 0x00007fff938162bf in RunCurrentEventLoopInMode ()

#7 0x00007fff9381d4bf in ReceiveNextEventCommon ()

#8 0x00007fff9381d3fa in BlockUntilNextEventMatchingListInMode ()

#9 0x00007fff94f6e779 in _DPSNextEvent ()

#10 0x00007fff94f6e07d in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()

#11 0x00000001017a8809 in wxGUIEventLoop::DoDispatchTimeout (this=0x104b64160, timeout=0) at evtloop.mm:232

#12 0x00000001015a4051 in wxCFEventLoop::DispatchTimeout (this=0x104b64160, timeout=0) at evtloop_cf.cpp:314

#13 0x00000001015a3fb1 in wxCFEventLoop::DoProcessEvents (this=0x104b64160) at evtloop_cf.cpp:301

#14 0x00000001015a3fde in wxCFEventLoop::Dispatch (this=0x104b64160) at evtloop_cf.cpp:306

#15 0x00000001010fdafc in _wrap_EventLoopBase_Dispatch (unnamed_arg=0x0, args=0x1005bc850) at _core_wrap.cpp:35858

#16 0x00000001000c22c2 in PyEval_EvalFrameEx ()

#17 0x00000001000c4149 in PyEval_EvalCodeEx ()

#18 0x00000001000c1a3d in PyEval_EvalFrameEx ()

#19 0x00000001000c286d in PyEval_EvalFrameEx ()

#20 0x00000001000c286d in PyEval_EvalFrameEx ()

#21 0x00000001000c4149 in PyEval_EvalCodeEx ()

#22 0x00000001000c4266 in PyEval_EvalCode ()

#23 0x00000001000e8a0c in PyRun_InteractiveOneFlags ()

#24 0x00000001000e8c6e in PyRun_InteractiveLoopFlags ()

#25 0x00000001000e9451 in PyRun_AnyFileExFlags ()

#26 0x000000010010006d in Py_Main ()

#27 0x0000000100000f14 in dyld_stub_strlen ()

Current language: auto; currently c++

Both wind up in _DPSNextEvent(). While it’s handled correctly for “regular” events, either the Menu events are not getting generated, or they are not being handled. Is it possible there are some events being created and/or handled in the MainLoop() version that aren’t in the Interact?

Any insight appreciated!

thanks,

-steve

On Tuesday, January 29, 2013 12:59:42 PM UTC-7, Bruce Sherwood wrote:

Oh dear. I’ll keep my fingers crossed. It would be really unfortunate if menus can’t work in VPython on the Mac, especially since they work fine on Windows and Linux.

Bruce Sherwood wrote:

Oh dear. I'll keep my fingers crossed. It would be really unfortunate if
menus can't work in VPython on the Mac, especially since they work fine
on Windows and Linux.

We'll probably need Stefan's help with this. Please create a ticket about it at trac.wxwidgets.org and reference this message thread. Be sure to describe how you are trying to override MainLoop without ever calling the real MainLoop.

···

--
Robin Dunn
Software Craftsman

OK… I’ll write something up and post it.

···

On Mon, Feb 4, 2013 at 2:16 PM, Robin Dunn robin@alldunn.com wrote:

Bruce Sherwood wrote:

Oh dear. I’ll keep my fingers crossed. It would be really unfortunate if

menus can’t work in VPython on the Mac, especially since they work fine

on Windows and Linux.

We’ll probably need Stefan’s help with this. Please create a ticket about it at trac.wxwidgets.org and reference this message thread. Be sure to describe how you are trying to override MainLoop without ever calling the real MainLoop.

Robin Dunn

Software Craftsman

http://wxPython.org

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

OK.. it's up there.

thanks for the help!

http://trac.wxwidgets.org/ticket/15026

-steve

···

On Feb 4, 2013, at 2:16 PM, Robin Dunn wrote:

Bruce Sherwood wrote:

Oh dear. I'll keep my fingers crossed. It would be really unfortunate if
menus can't work in VPython on the Mac, especially since they work fine
on Windows and Linux.

We'll probably need Stefan's help with this. Please create a ticket about it at trac.wxwidgets.org and reference this message thread. Be sure to describe how you are trying to override MainLoop without ever calling the real MainLoop.

--
Robin Dunn
Software Craftsman
http://wxPython.org

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Unfortunately, Vpython needs a 2.9 only feature.

Let’s hope we can far these issues fixed on wxMac.

David, I owe you some toolbar testing!

Chris

···

On 01/25/2013 02:57 PM, Bruce Sherwood
wrote:

VPython has always used Pythons from vpython.org .
I guess as suggested I have to create a small application that
hopefully can demonstrate the problem I see in the VPython
context.

      You might like to see how far we've gotten, with

lots of help from this wxPython community. Below is a screen
shot of the wxPython-based VPython (the image of this demo
came from Windows and also displays correctly on Linux;
everything but the menus works on a Mac). In the past, the 3D
canvas had to fill the window; there couldn’t be other widgets
in the window. In the program, the 3D cube rotates, and the
controls let you change the color, the rotation speed, and the
rotation direction, and you can also type into the text
control.

      The 3D portion of the code is pretty trivial. The

first statement creates a window and the second places an
OpenGL canvas in the left half of the window. You’ll note that
some adjustment is made so that the canvas is L*L but the
window is larger.

        w = window(width=2*(L+window.get_dw()),

height=L+window.get_dh(), title=‘Widgets’)

        display(window=w, y = 0, width=L, height=L,

forward=-vector(0,1,2))

cube = box(color=color.red)

        ... wxPython code to make widgets for setting

color, and rotation speed and direction

while True:

rate(100)

cube.rotate(axis=(0,1,0), angle=cube.dir*cube.dtheta)

      Of equal importance to widgets is the fact that it

was possible to eliminate very nearly all platform-dependent
C++ code (there are small instances of platform-dependent
Python code, but that’s trivial). The only remaining
platform-dependent C++ code is GetProcAddress. Of critical
importance is that the new VPython works on 64-bit Cocoa-based
Macs, something that was impossible with the old VPython,
which was Carbon-based.

      I've also run up against a significant

platform-dependent display issue which I’ve “solved”
temporarily on one particular Linux with hard-coded integers.
The VPython API has always had the user specify the width and
height of a window as the outer bounds, so that one can easily
place (say) two windows adjacent to each other or one below
the other, with the canvas being smaller than that. I need to
know the dimensions of the writable area, but unfortunately
only for Windows will wxWidgets give me the dimensions of
borders, title bar, and menu bar. For Mac and Linux, the
values are all -1. For both Windows and Mac, these values are
probably extremely stable (I use hard-coded integers for the
Mac), but on different distributions of Linux, or for
different window managers on the same Linux, I don’t know how
to get the dimension information I need.

      Note that my problems are somewhat different from

those using wxPython to create apps. VPython is middleware;
people use VPython to create apps. This puts an additional
burden on VPython to be universally cross-platform, not just
cross-platform for a particular app.

Availability note: At vpython.org one can get an
experimental version of the wxPython-based VPython, but the
support for widgets isn’t yet included even in that
experimental package. However, the up-to-date source code is
available at

https://github.com/BruceSherwood/vpython-wx.

<mime-attachment.jpg>

  --

  To unsubscribe, send email to

or visit
wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en

wxPython-users+unsubscribe@googlegroups.com
http://groups.google.com/group/wxPython-users?hl=en