Hi all,
I just know I'm missing something incredibly simple and obvious, but...
I've gotten PushEventHandler to work with an imported menubar, but now when I trigger an event from the menu, none of my event definitions seem to be able to figure out their working context. For example, I use the following two modules:
<module: RPA>
import OpenMenu
class MainFrame(wxFrame):
def __init__(self, *args, **kwds):
FirstMenu = OpenMenu.OpenMenuBar()
self.SetMenuBar(FirstMenu)
class Main(wxApp):
def OnInit(self):
frame_1 = MainFrame(None, -1, "")
MenuHandler=OpenMenu.OpenMenuEvents(frame_1)
frame_1.PushEventHandler(MenuHandler)
if __name__ == "__main__":
rpa = Main(0)
rpa.MainLoop()
<module: OpenMenu>
ID_New=wxNewId()
ID_Exit=wxNewId()
class OpenMenuBar(wxMenuBar):
def __init__(self, *args, **kwds):
class OpenMenuEvents(wxEvtHandler):
def __init__(self, parent):
frame=parent
wxEvtHandler.__init__(self)
EVT_MENU(self, ID_New, self.OnFileNew)
EVT_MENU(self, ID_Exit, self.OnFileExit)
def OnFileNew(self, event):
"""File > New"""
return
def OnFileExit(self,event):
"""File > Exit"""
self.Close()
When run, using the Exit command as my test, I get one of two errors depending on how I try to reference Close(). In the above example, I get OpenMenuEvents instance has no attribute 'Close". O.K., so I figure it's the self.reference causing the problem. But, I have tried frame_1.Close(), parent.Close(), frame.Close(), everything I can think of, and all I get is Global Variable 'xxx' not defined. I can't reference frame_1 directly, and I can't seem to pass it in as a parameter and either call the parameter directly or assign it to a local variable. I've also changed around the EVT_MENU(self, xx,xx) to replace 'self' with parent or frame_1 - also with no luck.
Can anyone explain how I apply the command 'Close()' to the frame 'frame_1' from inside the pushed event handler?