X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/493f1553fdfd276ed9944c5f1c070ee34be13b52..72858fcf67bf670ea18fe48a6b039d61afa87131:/wxPython/demo/wxListBox.py diff --git a/wxPython/demo/wxListBox.py b/wxPython/demo/wxListBox.py index c50d43bc51..074f2de5ae 100644 --- a/wxPython/demo/wxListBox.py +++ b/wxPython/demo/wxListBox.py @@ -1,8 +1,6 @@ from wxPython.wx import * -import string - #--------------------------------------------------------------------------- class wxFindPrefixListBox(wxListBox): @@ -10,18 +8,22 @@ class wxFindPrefixListBox(wxListBox): choices=[], style=0, validator=wxDefaultValidator): wxListBox.__init__(self, parent, id, pos, size, choices, style, validator) self.typedText = '' - EVT_KEY_UP(self, self.OnKey) + self.log = parent.log + EVT_KEY_DOWN(self, self.OnKey) def FindPrefix(self, prefix): + self.log.WriteText('Looking for prefix: %s\n' % prefix) if prefix: - prefix = string.lower(prefix) + prefix = prefix.lower() length = len(prefix) for x in range(self.Number()): text = self.GetString(x) - text = string.lower(text) + text = text.lower() if text[:length] == prefix: + self.log.WriteText('Prefix %s is found.\n' % prefix) return x + self.log.WriteText('Prefix %s is not found.\n' % prefix) return -1 @@ -43,8 +45,12 @@ class wxFindPrefixListBox(wxListBox): self.SetSelection(item) else: + self.typedText = '' evt.Skip() + def OnKeyDown(self, evt): + pass + #--------------------------------------------------------------------------- @@ -67,13 +73,15 @@ class TestListBox(wxPanel): EVT_LISTBOX_DCLICK(self, 60, self.EvtListBoxDClick) EVT_RIGHT_UP(self.lb1, self.EvtRightButton) self.lb1.SetSelection(3) + self.lb1.Append("with data", "This one has data"); + self.lb1.SetClientData(2, "This one has data"); wxStaticText(self, -1, "Select many:", wxPoint(200, 50), wxSize(65, 18)) self.lb2 = wxListBox(self, 70, wxPoint(280, 50), wxSize(80, 120), sampleList, wxLB_EXTENDED) EVT_LISTBOX(self, 70, self.EvtMultiListBox) - EVT_LISTBOX_DCLICK(self, 70, self.EvtListBoxDClick) + EVT_RIGHT_UP(self.lb2, self.EvtRightButton) self.lb2.SetSelection(0) @@ -88,7 +96,14 @@ class TestListBox(wxPanel): def EvtListBox(self, event): - self.log.WriteText('EvtListBox: %s\n' % event.GetString()) + self.log.WriteText('EvtListBox: %s, %s, %s\n' % + (event.GetString(), event.IsSelection(), event.GetSelection())) + + lb = event.GetEventObject() + data = lb.GetClientData(lb.GetSelection()) + if data is not None: + self.log.WriteText('\tdata: %s\n' % data) + def EvtListBoxDClick(self, event): self.log.WriteText('EvtListBoxDClick: %s\n' % self.lb1.GetSelection()) @@ -99,6 +114,12 @@ class TestListBox(wxPanel): def EvtRightButton(self, event): self.log.WriteText('EvtRightButton: %s\n' % event.GetPosition()) + if event.GetEventObject().GetId() == 70: + selections = list(self.lb2.GetSelections()) + selections.reverse() + for index in selections: + self.lb2.Delete(index) + #--------------------------------------------------------------------------- @@ -114,14 +135,19 @@ def runTest(frame, nb, log): +overview = """ +A listbox is used to select one or more of a list of +strings. The strings are displayed in a scrolling box, with the +selected string(s) marked in reverse video. A listbox can be single +selection (if an item is selected, the previous selection is removed) +or multiple selection (clicking an item toggles the item on or off +independently of other selections). + +""" +if __name__ == '__main__': + import sys,os + import run + run.main(['', os.path.basename(sys.argv[0])]) - - - - -overview = """\ -A listbox is used to select one or more of a list of strings. The strings are displayed in a scrolling box, with the selected string(s) marked in reverse video. A listbox can be single selection (if an item is selected, the previous selection is removed) or multiple selection (clicking an item toggles the item on or off independently of other selections). - -"""