X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/299647acac7960652aadb008775429c1f8ea9b8d..0a5bb138a71dfc1c706fc0858fb2801500e2c2e8:/wxPython/demo/CheckListBox.py diff --git a/wxPython/demo/CheckListBox.py b/wxPython/demo/CheckListBox.py index ef80a7637b..ffd4b180a4 100644 --- a/wxPython/demo/CheckListBox.py +++ b/wxPython/demo/CheckListBox.py @@ -1,8 +1,3 @@ -# 11/15/2003 - Jeff Grimmett (grimmtooth@softhome.net) -# -# o Updated for wx namespace -# o Why is there a popup menu in this demo? -# import wx @@ -19,50 +14,37 @@ class TestPanel(wx.Panel): wx.StaticText(self, -1, "This example uses the wxCheckListBox control.", (45, 15)) - lb = wx.CheckListBox(self, 60, (80, 50), (80, 120), sampleList) - self.Bind(wx.EVT_LISTBOX, self.EvtListBox, id=60) - self.Bind(wx.EVT_LISTBOX_DCLICK, self.EvtListBoxDClick, id=60) + lb = wx.CheckListBox(self, -1, (80, 50), wx.DefaultSize, sampleList) + self.Bind(wx.EVT_LISTBOX, self.EvtListBox, lb) + self.Bind(wx.EVT_CHECKLISTBOX, self.EvtCheckListBox, lb) lb.SetSelection(0) self.lb = lb + lb.Bind(wx.EVT_RIGHT_DOWN, self.OnDoHitTest) + pos = lb.GetPosition().x + lb.GetSize().width + 25 btn = wx.Button(self, -1, "Test SetString", (pos, 50)) - self.Bind(wx.EVT_BUTTON, self.OnTestButton, id=btn.GetId()) - self.Bind(wx.EVT_RIGHT_UP, self.OnDoPopup) + self.Bind(wx.EVT_BUTTON, self.OnTestButton, btn) def EvtListBox(self, event): self.log.WriteText('EvtListBox: %s\n' % event.GetString()) - def EvtListBoxDClick(self, event): - self.log.WriteText('EvtListBoxDClick:\n') + def EvtCheckListBox(self, event): + index = event.GetSelection() + label = self.lb.GetString(index) + status = 'un' + if self.lb.IsChecked(index): + status = '' + self.log.WriteText('Box %s is %schecked \n' % (label, status)) + self.lb.SetSelection(index) # so that (un)checking also selects (moves the highlight) + def OnTestButton(self, evt): self.lb.SetString(4, "FUBAR") - - def OnDoPopup(self, evt): - menu = wx.Menu() - # Make this first item bold - item = wx.MenuItem(menu, wx.NewId(), "If supported, this is bold") - df = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) - - nf = wx.Font( - df.GetPointSize(), df.GetFamily(), df.GetStyle(), - wx.BOLD, False, df.GetFaceName() - ) - - item.SetFont(nf) - menu.AppendItem(item) - - menu.AppendItem(wx.MenuItem(menu, wx.NewId(), "Normal Item &1")) - menu.AppendItem(wx.MenuItem(menu, wx.NewId(), "Normal Item &2")) - menu.AppendItem(wx.MenuItem(menu, wx.NewId(), "Normal Item &3")) - menu.AppendItem(wx.MenuItem(menu, wx.NewId(), "Normal Item &4")) - - self.PopupMenu(menu, evt.GetPosition()) - menu.Destroy() - evt.Skip() - + def OnDoHitTest(self, evt): + item = self.lb.HitTest(evt.GetPosition()) + self.log.write("HitTest: %d\n" % item) #---------------------------------------------------------------------- @@ -88,5 +70,5 @@ labels dynamically. 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:])