]>
Commit | Line | Data |
---|---|---|
be05b434 RD |
1 | import wx |
2 | ||
3 | ID_SIMPLE = wx.NewId() | |
4 | ||
5 | class MyFrame(wx.Frame): | |
6 | def __init__(self): | |
7 | wx.Frame.__init__(self, None, -1, | |
8 | "Enable/Disable Menu Example") | |
9 | p = wx.Panel(self) | |
10 | self.btn = wx.Button(p, -1, "Disable Item", (20,20)) | |
11 | self.Bind(wx.EVT_BUTTON, self.OnToggleItem, self.btn) | |
12 | ||
13 | menu = wx.Menu() | |
14 | menu.Append(ID_SIMPLE, "Simple menu item") | |
15 | self.Bind(wx.EVT_MENU, self.OnSimple, id=ID_SIMPLE) | |
16 | ||
17 | menu.AppendSeparator() | |
18 | menu.Append(wx.ID_EXIT, "Exit") | |
19 | self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT) | |
20 | ||
21 | menuBar = wx.MenuBar() | |
22 | menuBar.Append(menu, "Menu") | |
23 | self.SetMenuBar(menuBar) | |
24 | ||
25 | ||
26 | def OnSimple(self, event): | |
27 | wx.MessageBox("You selected the simple menu item") | |
28 | ||
29 | def OnExit(self, event): | |
30 | self.Close() | |
31 | ||
32 | def OnToggleItem(self, event): | |
33 | menubar = self.GetMenuBar() | |
34 | enabled = menubar.IsEnabled(ID_SIMPLE) | |
35 | menubar.Enable(ID_SIMPLE, not enabled) | |
36 | self.btn.SetLabel( | |
37 | (enabled and "Enable" or "Disable") + " Item") | |
38 | ||
39 | ||
40 | if __name__ == "__main__": | |
41 | app = wx.PySimpleApp() | |
42 | frame = MyFrame() | |
43 | frame.Show() | |
44 | app.MainLoop() | |
45 | ||
46 |