我们从Python开源项目中,提取了以下27个代码示例,用于说明如何使用wx.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 SetChoices(self, choices): max_text_width = 0 max_text_height = 0 self.ListBox.Clear() for choice in choices: self.ListBox.Append(choice) w, h = self.ListBox.GetTextExtent(choice) max_text_width = max(max_text_width, w) max_text_height = max(max_text_height, h) itemcount = min(len(choices), MAX_ITEM_SHOWN) width = self.Parent.GetSize()[0] height = \ max_text_height * itemcount + \ LISTBOX_INTERVAL_HEIGHT * max(0, itemcount - 1) + \ 2 * LISTBOX_BORDER_HEIGHT if max_text_width + 10 > width: height += 15 size = wx.Size(width, height) if wx.Platform == '__WXMSW__': size.width -= 2 self.ListBox.SetSize(size) self.SetClientSize(size)
def __init__( self, parent, id, titlemsg ): wx.Dialog.__init__( self, parent, id, title=titlemsg ) MechList = [] for m in parent.ScoreServer.MechList.List: MechList.append( str(m.ID) + ": " + str(m.Name) ) self.MechText = wx.StaticText( self, -1, "Mech Selection:" ) self.MechChoice = wx.ListBox( self, -1, style=wx.LB_EXTENDED, choices=MechList ) self.CancelButton = wx.Button( self, wx.ID_CANCEL, "Cancel" ) self.OKButton = wx.Button( self, wx.ID_OK, "OK" ) TopSizer = wx.BoxSizer( wx.VERTICAL ) BtnSizer = wx.BoxSizer( wx.HORIZONTAL ) BtnSizer.Add( self.CancelButton, 0, wx.ALL, 5 ) BtnSizer.Add( self.OKButton, 0, wx.ALL, 5 ) TopSizer.Add( self.MechText, 0, wx.ALL, 5 ) TopSizer.Add( self.MechChoice, 0, wx.ALL, 5 ) TopSizer.Add( BtnSizer, 0, wx.ALL|wx.CENTER, 5 ) self.SetSizer( TopSizer ) TopSizer.Fit( self )
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, 'Duplicate Component values found!' '\n\nPlease select which format to follow:') 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_DCLICK, self.on_selection, id=wx.ID_ANY)
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 __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 createLayout(self): self.listbox = wx.ListBox(self, ID_LISTBOX, wx.DefaultPosition, wx.DefaultSize, [], wx.LB_SINGLE | wx.LB_SORT, wx.DefaultValidator) self.listbox.typedText = "" s = "" try: if (os.name == "posix"): #s = "/dev/cu.PL2303-3B1\t" s = "/dev/ttyUSB0\t" if (os.name == "nt"): for i in range(1,10): s += "COM"+str(i)+"\t" except: print_exc() for i in s.split("\t"): if i: self.listbox.Append(i) self.bOK = wx.Button(self, ID_BUTTON_OK, "OK") self.bCancel = wx.Button(self, ID_BUTTON_CANCEL, "Cancel") self.sizer1 = wx.BoxSizer(wx.VERTICAL) self.sizer2 = wx.BoxSizer(wx.HORIZONTAL) self.sizer2.Add(self.bOK, 1, wx.EXPAND|wx.ALL,10) self.sizer2.Add(self.bCancel, 1, wx.EXPAND|wx.ALL,10) self.sizer1.Add(self.listbox, 1, wx.EXPAND|wx.ALL,20) self.sizer1.Add(self.sizer2) self.SetSizer(self.sizer1) self.SetAutoLayout(1) self.sizer1.Fit(self) wx.EVT_LISTBOX_DCLICK(self, ID_LISTBOX, self.selectNewReaderOK) wx.EVT_BUTTON(self, ID_BUTTON_OK, self.selectNewReaderOK) wx.EVT_BUTTON(self, ID_BUTTON_CANCEL, self.selectNewReaderCancel)
def createLayout(self): self.listbox = wx.ListBox(self, ID_LISTBOX, wx.DefaultPosition, wx.DefaultSize, [], wx.LB_SINGLE | wx.LB_SORT, wx.DefaultValidator) self.listbox.typedText = "" try: s = self.pcsc.listAllReaders() except: print_exc() for i in s.split("\t"): if i: self.listbox.Append(i) self.bOK = wx.Button(self, ID_BUTTON_OK, "OK") self.bCancel = wx.Button(self, ID_BUTTON_CANCEL, "Cancel") self.sizer1 = wx.BoxSizer(wx.VERTICAL) self.sizer2 = wx.BoxSizer(wx.HORIZONTAL) self.sizer2.Add(self.bOK, 1, wx.EXPAND|wx.ALL,10) self.sizer2.Add(self.bCancel, 1, wx.EXPAND|wx.ALL,10) self.sizer1.Add(self.listbox, 1, wx.EXPAND|wx.ALL,20) self.sizer1.Add(self.sizer2) self.SetSizer(self.sizer1) self.SetAutoLayout(1) self.sizer1.Fit(self) wx.EVT_LISTBOX_DCLICK(self, ID_LISTBOX, self.selectNewReaderOK) wx.EVT_BUTTON(self, ID_BUTTON_OK, self.selectNewReaderOK) wx.EVT_BUTTON(self, ID_BUTTON_CANCEL, self.selectNewReaderCancel)
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 initMusicLists(self): self.albumControlBox = ControlBox(self, label='Albums', orient=wx.VERTICAL) self.albumListBox = wx.ListBox(self, choices=[], style=wx.LB_SINGLE) self.albumControlBox.Add(self.albumListBox, proportion=1, flag=wx.ALL | wx.EXPAND, border=5) self.songControlBox = ControlBox(self, label='Songs', orient=wx.VERTICAL) self.songListBox = wx.ListBox(self, choices=[], style=wx.LB_SINGLE) self.songControlBox.Add(self.songListBox, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
def __init__(self, parent, choices=[]): wx.PopupWindow.__init__(self, parent, wx.BORDER_SIMPLE) self.ListBox = wx.ListBox(self, -1, style=wx.LB_HSCROLL | wx.LB_SINGLE | wx.LB_SORT) self.SetChoices(choices) self.ListBox.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown) self.ListBox.Bind(wx.EVT_MOTION, self.OnMotion)
def MoveSelection(self, direction): selected = self.ListBox.GetSelection() if selected == wx.NOT_FOUND: if direction >= 0: selected = 0 else: selected = self.ListBox.GetCount() - 1 else: selected = (selected + direction) % (self.ListBox.GetCount() + 1) if selected == self.ListBox.GetCount(): selected = wx.NOT_FOUND self.ListBox.SetSelection(selected)
def GetSelection(self): return self.ListBox.GetStringSelection()
def OnLeftDown(self, event): selected = self.ListBox.HitTest(wx.Point(event.GetX(), event.GetY())) parent_size = self.Parent.GetSize() parent_rect = wx.Rect(0, -parent_size[1], parent_size[0], parent_size[1]) if selected != wx.NOT_FOUND: wx.CallAfter(self.Parent.SetValueFromSelected, self.ListBox.GetString(selected)) elif parent_rect.InsideXY(event.GetX(), event.GetY()): result, x, y = self.Parent.HitTest(wx.Point(event.GetX(), event.GetY() + parent_size[1])) if result != wx.TE_HT_UNKNOWN: self.Parent.SetInsertionPoint(self.Parent.XYToPosition(x, y)) else: wx.CallAfter(self.Parent.DismissListBox) event.Skip()
def DismissListBox(self): if self.listbox is not None: if self.listbox.ListBox.HasCapture(): self.listbox.ListBox.ReleaseMouse() self.listbox.Destroy() self.listbox = None
def OnInit(self): """ Sets up the GUI. Creates a window, a text field, a button, and a list box, and lays them out. Binds the submit button to self.fetchHandler. """ win = wx.Frame(None, title="File Sharing Client", size=(400, 300)) bkg = wx.Panel(win) self.input = input = wx.TextCtrl(bkg); submit = wx.Button(bkg, label="Fetch", size=(80, 25)) submit.Bind(wx.EVT_BUTTON, self.fetchHandler) hbox = wx.BoxSizer() hbox.Add(input, proportion=1, flag=wx.ALL | wx.EXPAND, border=10) hbox.Add(submit, flag=wx.TOP | wx.BOTTOM | wx.RIGHT, border=10) self.files = files = wx.ListBox(bkg) self.updateList() vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(hbox, proportion=0, flag=wx.EXPAND) vbox.Add(files, proportion=1, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=10) bkg.SetSizer(vbox) win.Show() return True
def OnInit(self): """ Sets up the GUI. Creates a window, a text field, and a button, and lays them out. Binds the submit button to self.fetchHandler """ win = wx.Frame(None, title="File Sharing Client", size=(400, 300)) bkg = wx.Panel(win) self.input = input = wx.TextCtrl(bkg) submit = wx.Button(bkg, label="Fetch", size=(80, 25)) submit.Bind(wx.EVT_BUTTON, self.fetchHandler) hbox = wx.BoxSizer() hbox.Add(input, proportion=1, flag=wx.ALL | wx.EXPAND, border=10) hbox.Add(submit, flag=wx.TOP | wx.BOTTOM | wx.RIGHT, border=10) self.peer = peer = wx.TextCtrl(bkg) add = wx.Button(bkg, label="Add a Peer", size=(80, 25)) add.Bind(wx.EVT_BUTTON, self.helloHandler) peerbox = wx.BoxSizer() peerbox.Add(peer, proportion=1, flag=wx.ALL | wx.EXPAND, border=10) peerbox.Add(add, flag=wx.TOP | wx.BOTTOM | wx.RIGHT, border=10) self.files = files =wx.ListBox(bkg) self.updateList() vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(hbox, proportion=0, flag=wx.EXPAND) vbox.Add(peerbox, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=10) vbox.Add(files, proportion=1, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=10) bkg.SetSizer(vbox) win.Show() return True
def __init__(self, *args, **kwds): # begin wxGlade: ui_choice2Dialog.__init__ kwds["style"] = wx.DIALOG_NO_PARENT wx.Dialog.__init__(self, *args, **kwds) self.numListBox = wx.ListBox(self, -1, choices=[], style=wx.LB_MULTIPLE) self.button_ok = wx.Button(self, wx.ID_OK, "") self.denListBox = wx.ListBox(self, -1, choices=[], style=wx.LB_MULTIPLE) self.button_cancel = wx.Button(self, wx.ID_CANCEL, "") self.__set_properties() self.__do_layout() # end wxGlade
def __init__(self, parent): wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=u"Background Logging", pos=wx.DefaultPosition, size=wx.Size(500, 300), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize) sizer = wx.BoxSizer(wx.VERTICAL) gb_sizer = wx.GridBagSizer(5, 5) gb_sizer.SetFlexibleDirection(wx.BOTH) gb_sizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) list_boxChoices = [] self.list_box = wx.ListBox(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, list_boxChoices, 0) gb_sizer.Add(self.list_box, wx.GBPosition(0, 0), wx.GBSpan(1, 1), wx.EXPAND, 0) self.button = wx.Button(self, wx.ID_ANY, u"Run", wx.DefaultPosition, wx.DefaultSize, 0) gb_sizer.Add(self.button, wx.GBPosition(1, 0), wx.GBSpan(1, 1), wx.EXPAND, 0) gb_sizer.AddGrowableCol(0) gb_sizer.AddGrowableRow(0) sizer.Add(gb_sizer, 1, wx.EXPAND | wx.ALL, 5) self.SetSizer(sizer) self.Layout() self.Centre(wx.BOTH) # Connect Events self.button.Bind(wx.EVT_BUTTON, self.on_run) self.model = WatchableDict() self.model["logs"] = [] pywatch.wx.ItemContainerItemWatcher(self.list_box, self.model, "logs") # Virtual event handlers, overide them in your derived class
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): self.keys = kwargs.pop('keys', []) wx.ListBox.__init__(self, *args, **kwargs)
def create_wxwindow(self): return self.initfn(wx.ListBox)(self.parent, self.id, self.pos, self.size, self.choices, self.style, self.validator, self.name)
def __init__(self, *args, **kwds): # begin wxGlade: promote.__init__ kwds["style"] = wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.RESIZE_BORDER | wx.TAB_TRAVERSAL | wx.CLIP_CHILDREN wx.Dialog.__init__(self, *args, **kwds) self.panel_2 = wx.ScrolledWindow(self, -1, style=wx.TAB_TRAVERSAL) self.label_10 = wx.StaticText(self.panel_2, -1, "Current Class Details") self.combo_box_1 = wx.ComboBox(self.panel_2, -1, choices=[], style=wx.CB_DROPDOWN | wx.CB_SIMPLE | wx.CB_DROPDOWN | wx.CB_READONLY) self.combo_box_2 = wx.ComboBox(self.panel_2, -1, choices=["Select Standard", "8", "9", "10"], style=wx.CB_DROPDOWN | wx.CB_SIMPLE | wx.CB_DROPDOWN | wx.CB_READONLY) self.combo_box_3 = wx.ComboBox(self.panel_2, -1, choices=['Select Division'], style=wx.CB_DROPDOWN | wx.CB_SIMPLE | wx.CB_DROPDOWN | wx.CB_READONLY) self.static_line_1 = wx.StaticLine(self.panel_2, -1, style=wx.LI_VERTICAL) self.label_11 = wx.StaticText(self.panel_2, -1, "Promote/Move To") self.combo_box_4 = wx.ComboBox(self.panel_2, -1, choices=[], style=wx.CB_DROPDOWN | wx.CB_SIMPLE | wx.CB_DROPDOWN | wx.CB_READONLY) self.combo_box_5 = wx.ComboBox(self.panel_2, -1, choices=["Select Standard", "8", "9", "10"], style=wx.CB_DROPDOWN | wx.CB_SIMPLE | wx.CB_DROPDOWN | wx.CB_READONLY) self.combo_box_6 = wx.ComboBox(self.panel_2, -1, choices=['Select Division'], style=wx.CB_DROPDOWN | wx.CB_SIMPLE | wx.CB_DROPDOWN | wx.CB_READONLY) self.static_line_2 = wx.StaticLine(self.panel_2, -1) self.panel_1 = wx.Panel(self.panel_2, -1) allLoc = ['Admission No Name'] self.check_list_box_1 = wx.CheckListBox(self.panel_1, -1, (60, 50), (30,30), allLoc) self.check_list_box_2 = wx.CheckListBox(self.panel_1, -1, (60, 50), wx.DefaultSize, []) #self.list_box_2 = wx.ListBox(self.panel_1, -1, choices=[]) #self.list_box_3 = wx.ListBox(self.panel_1, -1, choices=[]) self.button_cancel = wx.Button(self.panel_2, -1, "Close") self.button_proceed = wx.Button(self.panel_2, -1, "Proceed") self.__set_properties() self.__do_layout() self.Bind(wx.EVT_COMBOBOX, self.oncombo_year1, self.combo_box_1) self.Bind(wx.EVT_COMBOBOX, self.oncombo_class1, self.combo_box_2) self.Bind(wx.EVT_COMBOBOX, self.oncombo_div1, self.combo_box_3) self.Bind(wx.EVT_COMBOBOX, self.oncombo_year2, self.combo_box_4) self.Bind(wx.EVT_COMBOBOX, self.oncombo_class2, self.combo_box_5) self.Bind(wx.EVT_COMBOBOX, self.oncombo_div2, self.combo_box_6) self.Bind(wx.EVT_CHECKLISTBOX, self.on_check, self.check_list_box_1) self.Bind(wx.EVT_CHECKLISTBOX, self.on_check_2, self.check_list_box_2) self.Bind(wx.EVT_BUTTON, self.on_cancel, self.button_cancel) self.Bind(wx.EVT_BUTTON, self.on_proceed, self.button_proceed) self.checkedItems=() self.DB=db_operations() self.load_year(self.combo_box_1 ,self.combo_box_2 ,self.combo_box_3 ) self.load_year(self.combo_box_4 ,self.combo_box_5 ,self.combo_box_6 ) # end wxGlade
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
def __init__(self, parent): wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=u"Selection Frame", pos=wx.DefaultPosition, size=wx.Size(500, 300), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) self.model = WatchableDict() self.model["selection"] = 1 self.model["list"] = [u"One", u"Two", u"Three"] self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize) sizer = wx.BoxSizer(wx.VERTICAL) gb_sizer = wx.GridBagSizer(5, 5) gb_sizer.SetFlexibleDirection(wx.BOTH) gb_sizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) choices = [] self.combo_box = wx.ComboBox(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, choices, 0) gb_sizer.Add(self.combo_box, wx.GBPosition(0, 0), wx.GBSpan(1, 1), wx.EXPAND, 5) pywatch.wx.ItemContainerItemWatcher(self.combo_box, self.model, "list") pywatch.wx.SelectionChanger(self.combo_box, self.model, "selection") self.choice = wx.Choice(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, choices, 0) self.choice.SetSelection(0) gb_sizer.Add(self.choice, wx.GBPosition(1, 0), wx.GBSpan(1, 1), wx.EXPAND, 5) pywatch.wx.ItemContainerItemWatcher(self.choice, self.model, "list") pywatch.wx.SelectionChanger(self.choice, self.model, "selection") self.list_box = wx.ListBox(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, choices, 0) gb_sizer.Add(self.list_box, wx.GBPosition(2, 0), wx.GBSpan(1, 1), wx.EXPAND, 5) pywatch.wx.ItemContainerItemWatcher(self.list_box, self.model, "list") pywatch.wx.SelectionChanger(self.list_box, self.model, "selection") self.radio_box = wx.RadioBox(self, wx.ID_ANY, u"Radio Box", wx.DefaultPosition, wx.DefaultSize, [u"One", u"Two", u"Three"], 1, wx.RA_SPECIFY_COLS) self.radio_box.SetSelection(0) gb_sizer.Add(self.radio_box, wx.GBPosition(3, 0), wx.GBSpan(1, 1), wx.EXPAND, 5) pywatch.wx.SelectionChanger(self.radio_box, self.model, "selection") gb_sizer.AddGrowableCol(0) gb_sizer.AddGrowableRow(2) sizer.Add(gb_sizer, 1, wx.EXPAND | wx.ALL, 5) self.SetSizer(sizer) self.Layout() self.Centre(wx.BOTH)
def __init__(self, parent): wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=u"List Editor", pos=wx.DefaultPosition, size=wx.Size(500, 300), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize) sizer = wx.BoxSizer(wx.VERTICAL) gb_sizer = wx.GridBagSizer(5, 5) gb_sizer.SetFlexibleDirection(wx.BOTH) gb_sizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) list_boxChoices = [] self.list_box = wx.ListBox(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, list_boxChoices, 0) gb_sizer.Add(self.list_box, wx.GBPosition(0, 0), wx.GBSpan(1, 2), wx.EXPAND, 0) self.add_button = wx.Button(self, wx.ID_ANY, u"Add", wx.DefaultPosition, wx.DefaultSize, 0) gb_sizer.Add(self.add_button, wx.GBPosition(1, 0), wx.GBSpan(1, 1), wx.EXPAND, 0) self.remove_button = wx.Button(self, wx.ID_ANY, u"Remove", wx.DefaultPosition, wx.DefaultSize, 0) gb_sizer.Add(self.remove_button, wx.GBPosition(1, 1), wx.GBSpan(1, 1), wx.EXPAND, 0) self.text_ctrl = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0) gb_sizer.Add(self.text_ctrl, wx.GBPosition(2, 0), wx.GBSpan(1, 2), wx.EXPAND, 0) gb_sizer.AddGrowableCol(0) gb_sizer.AddGrowableCol(1) gb_sizer.AddGrowableRow(0) sizer.Add(gb_sizer, 1, wx.EXPAND | wx.ALL, 5) self.SetSizer(sizer) self.Layout() self.Centre(wx.BOTH) self.add_button.Bind(wx.EVT_BUTTON, self.on_add) self.remove_button.Bind(wx.EVT_BUTTON, self.on_remove) self.model = WatchableDict() self.model["list"] = ["one", "two", "three", "four"] self.model["selection"] = 0 pywatch.wx.ItemContainerItemWatcher(self.list_box, self.model, "list") pywatch.wx.SelectionChanger(self.list_box, self.model, "selection") def getter(): return self.model["list"][self.model["selection"]] def setter(value): self.model["list"][self.model["selection"]] = value pywatch.wx.ValueChanger(self.text_ctrl, self.model, ("list", "selection", setter, getter))
def __init__(self, parent): wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=u"List Frame", pos=wx.DefaultPosition, size=wx.Size(500, 300), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize) sizer = wx.BoxSizer(wx.VERTICAL) gb_sizer = wx.GridBagSizer(5, 5) gb_sizer.SetFlexibleDirection(wx.BOTH) gb_sizer.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED) list_boxChoices = [] self.list_box = wx.ListBox(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, list_boxChoices, 0) gb_sizer.Add(self.list_box, wx.GBPosition(0, 0), wx.GBSpan(1, 2), wx.EXPAND, 0) combo_boxChoices = [] self.combo_box = wx.ComboBox(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, combo_boxChoices, 0) gb_sizer.Add(self.combo_box, wx.GBPosition(1, 0), wx.GBSpan(1, 2), wx.EXPAND, 0) choiceChoices = [] self.choice = wx.Choice(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, choiceChoices, 0) self.choice.SetSelection(0) gb_sizer.Add(self.choice, wx.GBPosition(2, 0), wx.GBSpan(1, 2), wx.EXPAND, 0) self.text_ctrl = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_PROCESS_ENTER) gb_sizer.Add(self.text_ctrl, wx.GBPosition(3, 0), wx.GBSpan(1, 1), wx.EXPAND, 0) self.button = wx.Button(self, wx.ID_ANY, u"Add", wx.DefaultPosition, wx.DefaultSize, 0) gb_sizer.Add(self.button, wx.GBPosition(3, 1), wx.GBSpan(1, 1), wx.ALL, 0) gb_sizer.AddGrowableCol(0) gb_sizer.AddGrowableRow(0) sizer.Add(gb_sizer, 1, wx.EXPAND | wx.ALL, 5) self.SetSizer(sizer) self.Layout() self.Centre(wx.BOTH) # Connect Events self.button.Bind(wx.EVT_BUTTON, self.on_add) self.text_ctrl.Bind(wx.EVT_TEXT_ENTER, self.on_add) self.model = WatchableDict() self.model["list"] = [] self.model["text"] = "" pywatch.wx.ValueChanger(self.text_ctrl, self.model, "text") pywatch.wx.ItemContainerItemWatcher(self.list_box, self.model, "list") pywatch.wx.ItemContainerItemWatcher(self.choice, self.model, "list") pywatch.wx.ItemContainerItemWatcher(self.combo_box, self.model, "list") # Virtual event handlers, overide them in your derived class