Attachment 'sysmenu-test.py'

Download

   1 #!/usr/bin/env python
   2 #coding=utf-8
   3 
   4 import wx
   5 import sysmenu
   6 
   7 class testframe(wx.Frame, sysmenu.mixSysMenu):
   8     def __init__(self, parent, id, *args, **kwds):
   9         wx.Frame.__init__(self, parent, id, *args, **kwds)
  10         
  11         pan = wx.Panel(self, -1)
  12         sz = wx.BoxSizer(wx.VERTICAL)
  13         pan.SetSizer(sz)
  14         
  15         szItems = wx.StaticBoxSizer(wx.StaticBox(pan, -1, "Options added to system menu"), wx.HORIZONTAL)
  16         sz.Add(szItems, 2, wx.EXPAND|wx.ALL, 3)
  17         
  18         # Options List
  19         self.ItemList = wx.ListBox(pan, -1, size=wx.Size(200,-1))
  20         szItems.Add(self.ItemList, 2, wx.EXPAND)
  21                    
  22         szStates = wx.BoxSizer(wx.VERTICAL)
  23         szItems.Add(szStates)
  24         
  25         self.Checked = wx.CheckBox(pan, -1, "Checked")
  26         szStates.Add(self.Checked, 0, wx.ALL, 3)
  27         
  28         self.Disabled = wx.CheckBox(pan, -1, "Disabled")
  29         szStates.Add(self.Disabled, 0, wx.ALL, 3)
  30         
  31         szButtons = wx.BoxSizer(wx.HORIZONTAL)
  32         sz.Add(szButtons, 0, wx.ALL, 3)
  33         
  34         self.BtnAppend = wx.Button(pan, -1, "Append Menu Item")
  35         szButtons.Add(self.BtnAppend, 0, wx.ALL, 3)
  36         
  37         self.BtnRemove = wx.Button(pan, -1, "Remove Menu Item")
  38         szButtons.Add(self.BtnRemove, 0, wx.ALL, 3)
  39         
  40         self.Message = wx.StaticText(pan, -1, size=wx.Size(-1, 30))
  41         sz.Add(self.Message, 0, wx.ALL, 6)
  42         
  43         sz.SetSizeHints(self)
  44         self.Layout()
  45         
  46         # Bind Events
  47         self.ItemList.Bind(wx.EVT_LISTBOX, self.OnListItems)
  48         self.Checked.Bind(wx.EVT_CHECKBOX, self.OnStates)
  49         self.Disabled.Bind(wx.EVT_CHECKBOX, self.OnStates)
  50         self.BtnAppend.Bind(wx.EVT_BUTTON, self.OnAppendItem)
  51         self.BtnRemove.Bind(wx.EVT_BUTTON, self.OnRemoveItem)
  52                     
  53         # Add optiones to sysmenu
  54         self.SysMenuAddSeparator()
  55         idOption1 = wx.NewId()
  56         self.SysMenuAppendItem("Custom option 1", idOption1, self.OnMenu)
  57         self.SysMenuSetState(idOption1, sysmenu.MF_CHECKED)      
  58         self.SysMenuAppendItem("Custom option 2", None, self.OnMenu)
  59         
  60         self.RefreshList()
  61         
  62     def RefreshList(self):
  63         items = self.SysMenuGetItemsList()
  64         print items
  65         self.ItemList.Clear()
  66         for item in items:
  67             self.ItemList.Append(item[1], item[0])
  68         if items:
  69             self.ItemList.SetSelection(0)
  70             self.OnListItems(None)
  71         
  72     def OnListItems(self, evt):
  73         itemid = self.ItemList.GetClientData(self.ItemList.GetSelection())
  74         self.Checked.SetValue(self.SysMenuGetState(itemid, sysmenu.MF_CHECKED))
  75         self.Disabled.SetValue(self.SysMenuGetState(itemid, sysmenu.MF_GRAYED))
  76     
  77     def OnStates(self, evt):
  78         itemid = self.ItemList.GetClientData(self.ItemList.GetSelection())
  79         checked = sysmenu.MF_CHECKED if self.Checked.GetValue() else sysmenu.MF_UNCHECKED
  80         disabled = sysmenu.MF_GRAYED if self.Disabled.GetValue() else sysmenu.MF_ENABLED
  81         self.SysMenuSetState(itemid, checked|disabled)            
  82     
  83     def OnAppendItem(self, evt):
  84         dlg = wx.TextEntryDialog(self, "Item text:", "Add new Item", '', style = wx.OK | wx.CANCEL)
  85         if dlg.ShowModal() == wx.ID_CANCEL:
  86             return
  87         text = dlg.GetValue()
  88         dlg.Destroy()
  89         if text:
  90             self.SysMenuAppendItem(text, None, self.OnMenu)
  91             self.RefreshList()
  92             
  93     def OnRemoveItem(self, evt):
  94         if self.ItemList.GetSelection() == wx.NOT_FOUND:
  95             return
  96         itemid = self.ItemList.GetClientData(self.ItemList.GetSelection())
  97         self.SysMenuDeleteItem(itemid)
  98         self.RefreshList()
  99     
 100 
 101 
 102         
 103     def OnMenu(self, ItemId):
 104         msg = "Click on:'%s', ItemId:%s, \nChecked:%s, Disabled:%s" % \
 105                 (self.SysMenuGetMenuString(ItemId),
 106                 ItemId,
 107                 self.SysMenuGetState(ItemId, sysmenu.MF_CHECKED),
 108                 self.SysMenuGetState(ItemId, sysmenu.MF_GRAYED))
 109         self.Message.SetLabel(msg)
 110 
 111     
 112     
 113 # --- Start App ---
 114 app = wx.App(0)
 115 f = testframe(None, -1)
 116 f.Show()
 117 app.MainLoop()

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-11-18 19:31:58, 4.1 KB) [[attachment:sysmenu-test.py]]
  • [get | view] (2009-11-18 19:47:48, 4.7 KB) [[attachment:sysmenu.py]]
  • [get | view] (2009-11-18 19:22:28, 8.6 KB) [[attachment:sysmenu1.png]]
  • [get | view] (2009-11-18 19:22:46, 13.0 KB) [[attachment:sysmenu2.png]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.