def ButtonOnly(self): # Here we (re)create the buttons for the button-only demo self.Freeze() if self.created: sizer = self.mainPanel.GetSizer() sizer.Detach(0) self.titleBar.Hide() wx.CallAfter(self.titleBar.Destroy) self.titleBar = bp.ButtonPanel(self.mainPanel, -1, "A Simple Test & Demo", style=self.style, alignment=self.alignment) self.SetProperties() # Buttons are created completely random, with random images, toggle behavior # and text self.indices = [] for count in xrange(8): itemImage = random.randint(0, 3) hasText = random.randint(0, 1) itemKind = random.randint(0, 1) btn = bp.ButtonInfo(self.titleBar, wx.NewId(), self.pngs[itemImage][0], kind=itemKind) if hasText: btn.SetText(self.pngs[itemImage][1]) rightText = random.randint(0, 1) if rightText: btn.SetTextAlignment(bp.BP_BUTTONTEXT_ALIGN_RIGHT) self.titleBar.AddButton(btn) self.Bind(wx.EVT_BUTTON, self.OnButton, id=btn.GetId()) self.indices.append(btn.GetId()) if count in [0, 3, 5]: self.titleBar.AddSeparator() self.strings = [ "First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth" ] self.ChangeLayout() self.Thaw() self.titleBar.DoLayout()
def CreateButtons(self): # Here we (re)create the buttons for the default startup demo self.Freeze() if self.created: sizer = self.mainPanel.GetSizer() sizer.Detach(0) self.titleBar.Hide() wx.CallAfter(self.titleBar.Destroy) self.titleBar = bp.ButtonPanel(self.mainPanel, -1, "A Simple Test & Demo", style=self.style, alignment=self.alignment) self.SetProperties() self.indices = [] for count, png in enumerate(self.pngs): shortHelp = "Button %d" % (count + 1) if count < 2: # First 2 buttons are togglebuttons kind = wx.ITEM_CHECK longHelp = "ButtonPanel Toggle Button No %d" % (count + 1) else: kind = wx.ITEM_NORMAL longHelp = "Simple Button without label No %d" % (count + 1) btn = bp.ButtonInfo(self.titleBar, wx.NewId(), png[0], kind=kind, shortHelp=shortHelp, longHelp=longHelp) self.titleBar.AddButton(btn) self.Bind(wx.EVT_BUTTON, self.OnButton, id=btn.GetId()) self.indices.append(btn.GetId()) if count < 2: # First 2 buttons have also a text btn.SetText(png[1]) if count == 2: # Append a separator after the second button self.titleBar.AddSeparator() if count == 1: # Add a wx.TextCtrl to ButtonPanel self.titleBar.AddControl( wx.TextCtrl(self.titleBar, -1, "Hello wxPython!")) btn.SetTextAlignment(bp.BP_BUTTONTEXT_ALIGN_RIGHT) # Add a wx.Choice to ButtonPanel self.titleBar.AddControl( wx.Choice(self.titleBar, -1, choices=["Hello", "From", "wxPython!"])) self.strings = ["First", "Second", "Third", "Fourth"] self.ChangeLayout() self.Thaw() self.titleBar.DoLayout() self.created = True