Using the wxOGL example in the wxPython demo as a starting point, how would
I create a popup menu that would respond to right-clicking on a shape. The
menu items on the popup menu should do something to the shape, for instance
adding/removing a shadow.
I have code that does everything EXCEPT respond properly to clicking on the
menu item. The menu pops up when I right click on the shape, but the event
handlers are not called when I click on a menu item in the popup menu. (In
fact, I am getting a cryptic TypeError message sent to stdout - "TypeError:
too many arguments; expected 1, got 2" - no actual exception and no
indication where it occurs.)
Thanks for any help!
Nick
# example code follows
# constants declared at the top of the module
ID_SHAPE_SHADOW_ON = 210
ID_SHAPE_SHADOW_OFF = 211
#...snip...
# the pop up menu is initialized in the __init__ method of
MyFrame(wxFrame)
self.shape_menu = wxMenu()
self.shape_menu.Append(ID_SHAPE_SHADOW_ON, "Shadow ON")
self.shape_menu.Append(ID_SHAPE_SHADOW_OFF, "Shadow OFF")
# handler declarations are shortly thereafter
EVT_MENU(self, ID_SHAPE_SHADOW_ON, self.OnShadowOn)
EVT_MENU(self, ID_SHAPE_SHADOW_OFF, self.OnShadowOff)
#...snip...
# event handlers declared in body of MyFrame class
def OnShadowOn(self):
print "OnShadowOn called\n"
# actual code removed for clarity
def OnShadowOff(self):
print "OnShadowOff called\n"
# actual code removed for clarity
#...snip...
# the right-click event handler in MyShapeEvtHandler(wxShapeEvtHandler)
def OnRightClick(self, x, y, *dontcare):
self.OnLeftClick(x, y, 0, 0) # selects the shape under
the mouse
self.UpdateStatusBar(shape)
shape = self.GetShape()
canvas = shape.GetCanvas()
frame = self.statbarFrame
# calculate where the popup menu should be drawn (it works,
but awaiting better response from mailing list)
(scrollX, scrollY) = canvas.CalcScrolledPosition(x, y)
(None, canvasY) = canvas.GetPositionTuple()
(None, frameY) = frame.GetPositionTuple()
# bring up the popup menu
frame.PopupMenu(frame.shape_menu, wxPoint(scrollX, scrollY +
canvasY + frameY))
···
_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users