This is the solution someone presented for my menus that acted
oddly after two creations... thought it might be of help to
the poster having issues with dynamic menu stuff at present...
If not, apologies for the repost
Regards,
Denny
···
--
Linux... because rebooting regularly is NOT normal...
This machine was last rebooted: 33 days 4:19 hours ago
---------- Forwarded message ----------
Date: Wed, 7 Mar 2001 08:09:01 -0700
From: Tim Hochberg <tim.hochberg@ieee.org>
Reply-To: wxpython-users@lists.sourceforge.net
To: wxpython-users@lists.sourceforge.net
Subject: Re: [wxPython] Popup menu problem
After the successful (if not helpful) diagnosis of my
listbox problem once I isolated it in a full script, I'm
hoping for similar miracles with this popup menu thing -
which is now encapsulated in this script:http://www-edc.eng.cam.ac.uk/~djd33/menu-broken.txt
The problem is that when you first right-click on an
item and select View Info, nothing happens... however,
from then on, no matter what item you click on and select
View Info, you will always get the output for the first
item you clicked on. I've stripped the output routine
down to a print statement on stdout, and you can see
the discrepancy between the printed output and the
numbers on the top of the menus themselves...Help?
Your wish is my command!
There are two problems here. The first is that you need to bind the event
before you popup the menu. This is why nothing happens the first time. The
second issue is more subtle. It's not letting you rebind the event using the
ID 2001 repeatedly. One way around this would be to use different IDs each
time, but I've found that you end up leaking memory that way. What I would
do is replace:
win.PopupMenuXY (node_menu, cursor_pos[0], cursor_pos[1])
EVT_MENU (win, 2001, self.ViewStates)
with
EVT_MENU (win, 2001, self.ViewStates)
win.PopupMenuXY (node_menu, cursor_pos[0], cursor_pos[1])
win.Disconnect(2001)
That seems to do the trick.
One other approach would be to generate the menus once in the constructor of
each spTangentNode, generating different ids each time. However, you'd still
need to disconnect the id when each spTangentNode was deleted, so I think
the method above is probably best.
-tim
----------------------------------------------------------
Denny De La Haye \ www-edc.eng.cam.ac.uk/~djd33
Engineering Design Centre, \ www-edc.eng.cam.ac.uk
Department of Engineering, \ www.eng.cam.ac.uk
University of Cambridge, UK \ www.cam.ac.uk
----------------------------------------------------------
"Only two things are infinite, the universe and human stupidity,
and I'm not sure about the former." (Albert Einstein)_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users
_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users