X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/299647acac7960652aadb008775429c1f8ea9b8d..628eae0bcd7916c57847b7eab739d4cc32534ccf:/wxPython/demo/Menu.py diff --git a/wxPython/demo/Menu.py b/wxPython/demo/Menu.py index 516241efcf..57bd44ce80 100644 --- a/wxPython/demo/Menu.py +++ b/wxPython/demo/Menu.py @@ -4,10 +4,12 @@ # menus in wxPython 2.3.3 # #------------------------------------------------------------------- -# 11/20/2003 - Jeff Grimmett (grimmtooth@softhome.net) # -# o Updated for wx namespace -# +# o Debug message when adding a menu item (see last menu): +# +# Debug: ..\..\src\msw\menuitem.cpp(370): 'GetMenuState' failed with +# error 0x00000002 (the system cannot find the file specified.). +# import time import wx @@ -133,13 +135,13 @@ check the source for this sample to see how to implement them. # Methods def OnMenuHighlight(self, event): - # Show how to get menu item imfo from this event handler + # Show how to get menu item info from this event handler id = event.GetMenuId() item = self.GetMenuBar().FindItemById(id) - text = item.GetText() - help = item.GetHelp() + if item: + text = item.GetText() + help = item.GetHelp() - #print text, help # but in this case just call Skip so the default is done event.Skip() @@ -249,21 +251,34 @@ check the source for this sample to see how to implement them. menu.InsertItem(pos, item) -#------------------------------------------------------------------- +#--------------------------------------------------------------------------- -wx.RegisterId(10000) +class TestPanel(wx.Panel): + def __init__(self, parent, log): + self.log = log + wx.Panel.__init__(self, parent, -1) + + b = wx.Button(self, -1, "Show the Menu sample", (50,50)) + self.Bind(wx.EVT_BUTTON, self.OnButton, b) -def runTest(frame, nb, log): - win = MyFrame(frame, -1, log) - frame.otherWin = win - win.Show(True) + def OnButton(self, evt): + win = MyFrame(self, -1, self.log) + win.Show(True) + + +#--------------------------------------------------------------------------- + + +def runTest(frame, nb, log): + win = TestPanel(nb, log) + return win #------------------------------------------------------------------- overview = """\ -A demo of using wxMenuBar and wxMenu in various ways. +A demo of using wx.MenuBar and wx.Menu in various ways. A menu is a popup (or pull down) list of items, one of which may be selected before the menu goes away (clicking elsewhere dismisses the menu). Menus may be @@ -278,7 +293,7 @@ Menu items may be either normal items, check items or radio items. Normal items don't have any special properties while the check items have a boolean flag associated to them and they show a checkmark in the menu when the flag is set. wxWindows automatically toggles the flag value when the item is clicked and its value may -be retrieved using either IsChecked method of wxMenu or wxMenuBar itself or by +be retrieved using either IsChecked method of wx.Menu or wx.MenuBar itself or by using wxEvent.IsChecked when you get the menu notification for the item in question. The radio items are similar to the check items except that all the other items @@ -296,5 +311,5 @@ and GTK+ currently. if __name__ == '__main__': import sys,os import run - run.main(['', os.path.basename(sys.argv[0])]) + run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])