]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/wxPIA_book/Chapter-10/update_ui.py
fix typo
[wxWidgets.git] / wxPython / samples / wxPIA_book / Chapter-10 / update_ui.py
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 "UPDATE_UI 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.enabled = True
16 self.Bind(wx.EVT_MENU, self.OnSimple, id=ID_SIMPLE)
17 self.Bind(wx.EVT_UPDATE_UI, self.OnUpdateSimple, id=ID_SIMPLE)
18
19 menu.AppendSeparator()
20 menu.Append(wx.ID_EXIT, "Exit")
21 self.Bind(wx.EVT_MENU, self.OnExit, id=wx.ID_EXIT)
22
23 menuBar = wx.MenuBar()
24 menuBar.Append(menu, "Menu")
25 self.SetMenuBar(menuBar)
26
27
28 def OnSimple(self, event):
29 wx.MessageBox("You selected the simple menu item")
30
31 def OnExit(self, event):
32 self.Close()
33
34 def OnToggleItem(self, event):
35 self.btn.SetLabel(
36 (self.enabled and "Enable" or "Disable") + " Item")
37 self.enabled = not self.enabled
38
39 def OnUpdateSimple(self, event):
40 event.Enable(self.enabled)
41
42
43 if __name__ == "__main__":
44 app = wx.PySimpleApp()
45 frame = MyFrame()
46 frame.Show()
47 app.MainLoop()
48
49