我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用wx.EVT_LISTBOX。
def __init__(self, parent, size, data, *args, **kwargs): wx.ListBox.__init__(self, parent, size, **kwargs) self.data = data self.InsertItems(data, 0) self.Bind(wx.EVT_LISTBOX, self.on_selection_changed) self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down) self.Bind(wx.EVT_RIGHT_DOWN, self.on_right_down) self.Bind(wx.EVT_RIGHT_UP, self.on_right_up) self.Bind(wx.EVT_MOTION, self.on_move) self.index_iter = range(len(self.data)) self.selected_items = [True] * len(self.data) self.index_mapping = list(range(len(self.data))) self.drag_start_index = None self.update_selection() self.SetFocus()
def __init__(self): wx.Frame.__init__(self, None, title="ListBox Obj Tutorial") panel = wx.Panel(self, wx.ID_ANY) ford = Car(0, "Ford", "F-150", "2008") chevy = Car(1, "Chevrolet", "Camaro", "2010") nissan = Car(2, "Nissan", "370Z", "2005") sampleList = [] lb = wx.ListBox(panel, size=wx.DefaultSize, choices=sampleList) self.lb = lb lb.Append(ford.make, ford) lb.Append(chevy.make, chevy) lb.Append(nissan.make, nissan) lb.Bind(wx.EVT_LISTBOX, self.onSelect) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(lb, 0, wx.ALL, 5) panel.SetSizer(sizer)
def on_left_down(self, event): if self.HitTest(event.GetPosition()) != wx.NOT_FOUND: index = self.HitTest(event.GetPosition()) self.selected_items[index] = not self.selected_items[index] # doesn't really work to update selection direclty (focus issues) # instead we wait for the EVT_LISTBOX event and fix the selection # there... # self.update_selection() # TODO: we could probably use wx.CallAfter event.Skip()
def swap(self, i, j): self.index_mapping[i], self.index_mapping[j] = self.index_mapping[j], self.index_mapping[i] self.SetString(i, self.data[self.index_mapping[i]]) self.SetString(j, self.data[self.index_mapping[j]]) self.selected_items[i], self.selected_items[j] = self.selected_items[j], self.selected_items[i] # self.update_selection() # print("Updated mapping:", self.index_mapping) new_event = wx.PyCommandEvent(wx.EVT_LISTBOX.typeId, self.GetId()) self.GetEventHandler().ProcessEvent(new_event)
def __init__(self, parent, columns, df_list_ctrl): wx.Panel.__init__(self, parent) self.columns = columns self.df_list_ctrl = df_list_ctrl self.list_box = ListBoxDraggable(self, -1, columns, style=wx.LB_EXTENDED) self.Bind(wx.EVT_LISTBOX, self.update_selected_columns) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.list_box, 1, wx.ALL | wx.EXPAND | wx.GROW, 5) self.SetSizer(sizer) self.list_box.SetFocus()
def __init__(self, parent=None,id=-1,title="Checking Spelling..."): wx.Dialog.__init__(self, parent, id, title, size=wxSpellCheckerDialog.sz, style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER) self._numContext = 40 self._checker = None self._buttonsEnabled = True self.error_text = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_RICH) self.replace_text = wx.TextCtrl(self, -1, "", style=wx.TE_PROCESS_ENTER) self.replace_list = wx.ListBox(self, -1, style=wx.LB_SINGLE) self.InitLayout() wx.EVT_LISTBOX(self,self.replace_list.GetId(),self.OnReplSelect) wx.EVT_LISTBOX_DCLICK(self,self.replace_list.GetId(),self.OnReplace)
def initSelectorArea(self): self.selectorSizer = wx.BoxSizer(orient=wx.VERTICAL) filterListControlBox = widgets.ControlBox(self, label='Available Filters', orient=wx.VERTICAL) self.filterListBox = wx.ListBox(self, choices=filters.filterChoices.keys(), style=wx.LB_SORT | wx.LB_SINGLE) filterListControlBox.Add(self.filterListBox, proportion=1, flag=wx.ALL | wx.EXPAND, border=10) self.pushFilterButton = wx.Button(self, label='Push Filter') self.Bind(wx.EVT_BUTTON, self.pushFilter, self.pushFilterButton) filterListControlBox.Add(self.pushFilterButton, proportion=0, flag=wx.LEFT | wx.BOTTOM | wx.RIGHT | wx.EXPAND, border=10) self.selectorSizer.Add(filterListControlBox, proportion=1, flag=wx.ALL | wx.EXPAND, border=10) chainListControlBox = widgets.ControlBox(self, label='Filter Chain', orient=wx.VERTICAL) self.chainListBox = wx.ListBox(self, choices=[], style=wx.LB_SINGLE) ##self.chainListBox = wx.ListCtrl(self, style=wx.LC_NO_HEADER | wx.LC_SINGLE_SEL) self.Bind(wx.EVT_LISTBOX, self.configFilter, self.chainListBox) chainListControlBox.Add(self.chainListBox, proportion=1, flag=wx.ALL | wx.EXPAND, border=10) #self.configFilterButton = wx.Button(self, label='Configure Filter') #self.Bind(wx.EVT_BUTTON, self.configFilter, self.configFilterButton) #chainListControlBox.Add(self.configFilterButton, proportion=0, # flag=wx.LEFT | wx.RIGHT | wx.EXPAND, border=10) self.popFilterButton = wx.Button(self, label='Pop Filter') self.Bind(wx.EVT_BUTTON, self.popFilter, self.popFilterButton) chainListControlBox.Add(self.popFilterButton, proportion=0, flag=wx.LEFT | wx.BOTTOM | wx.RIGHT | wx.EXPAND, border=10) self.selectorSizer.Add(chainListControlBox, proportion=1, flag=wx.LEFT | wx.BOTTOM | wx.RIGHT | wx.EXPAND, border=10)
def _InitCheckboxes(self): option_strings = [ 'Append inode' ] self.checklistbox_options.InsertItems(option_strings,0) self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.checklistbox_options) self.Bind(wx.EVT_CHECKLISTBOX, self.EvtCheckListBox, self.checklistbox_options)
def __init__(self, parent, id, title): wx.Dialog.__init__(self, parent, id, title) self.selection_idx = None self.selection_text = None vbox = wx.BoxSizer(wx.VERTICAL) stline = wx.StaticText(self, 11, 'Please select from the following components') vbox.Add(stline, 0, wx.ALIGN_CENTER|wx.TOP) self.comp_list = wx.ListBox(self, 331, style=wx.LB_SINGLE) vbox.Add(self.comp_list, 1, wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND) self.SetSizer(vbox) self.comp_list.Bind(wx.EVT_LISTBOX, self.on_selection, id=wx.ID_ANY)
def __init__(self, *args, **kwargs): super(EncapsulatedListBox, self).__init__(*args, **kwargs) self.control.Bind(wx.EVT_LISTBOX, self.on_change)
def __init__(self, *args, **kwds): # begin wxGlade: add_div.__init__ kwds["style"] = wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX | wx.STAY_ON_TOP wx.Dialog.__init__(self, *args, **kwds) self.panel_1 = wx.ScrolledWindow(self, -1, style=wx.TAB_TRAVERSAL) self.label_1 = wx.StaticText(self.panel_1, -1, "YEAR") self.combo_box_1 = wx.ComboBox(self.panel_1, -1, choices=[], style=wx.CB_DROPDOWN | wx.CB_DROPDOWN | wx.CB_READONLY | wx.CB_SORT) self.label_2 = wx.StaticText(self.panel_1, -1, "CLASS") self.combo_box_2 = wx.ComboBox(self.panel_1, -1, choices=["Select","8","9","10"], style=wx.CB_DROPDOWN | wx.CB_DROPDOWN | wx.CB_READONLY | wx.CB_SORT) self.sizer_4_staticbox = wx.StaticBox(self.panel_1, -1, "Specify Class ") self.list_box_1 = wx.ListBox(self.panel_1, -1, choices=[], style=wx.LB_SINGLE | wx.LB_SORT) self.button_1 = wx.Button(self.panel_1, -1, "Remove Divison") self.text_ctrl_1 = wx.TextCtrl(self.panel_1, -1, "") self.button_2 = wx.Button(self.panel_1, -1, "Add Division") self.sizer_9_staticbox = wx.StaticBox(self.panel_1, -1, "New Division") self.button_3 = wx.Button(self.panel_1, -1, "Close") self.hyperlink_1 = wx.HyperlinkCtrl(self.panel_1, wx.ID_ANY, "", "Add Academic Year") self.__set_properties() self.__do_layout() self.Bind(wx.EVT_COMBOBOX, self.on_year, self.combo_box_1) self.Bind(wx.EVT_COMBOBOX, self.on_class, self.combo_box_2) self.Bind(wx.EVT_LISTBOX, self.on_list, self.list_box_1) self.Bind(wx.EVT_BUTTON, self.on_remove, self.button_1) self.Bind(wx.EVT_TEXT, self.on_text, self.text_ctrl_1) self.Bind(wx.EVT_BUTTON, self.on_add, self.button_2) self.Bind(wx.EVT_BUTTON, self.on_close, self.button_3) self.text_ctrl_1 .Bind(wx.EVT_SET_FOCUS,self.onfocus) self.text_ctrl_1 .Bind(wx.EVT_KILL_FOCUS,self.offocus) self.text_ctrl_1.Bind(wx.EVT_KEY_DOWN, self.on_keypress) self.Bind(wx.EVT_HYPERLINK, self.on_hlink, self.hyperlink_1) self.YEAR='' self.CLASS='' self.DB=db_operations() self.load_year() # end wxGlade