Exemplo n.º 1
0
    def __init__(self,
                 parent,
                 id=wx.ID_ANY,
                 title="ButtonPanel wxPython Demo ;-)",
                 pos=wx.DefaultPosition,
                 size=(640, 400),
                 style=wx.DEFAULT_FRAME_STYLE):

        wx.Frame.__init__(self, parent, id, title, pos, size, style)

        self.useredited = False
        self.hassettingpanel = False

        self.SetIcon(images.Mondrian.GetIcon())
        self.CreateMenuBar()

        self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
        self.statusbar.SetStatusWidths([-2, -1])
        # statusbar fields
        statusbar_fields = [
            ("ButtonPanel wxPython Demo, Andrea Gavana @ 02 Oct 2006"),
            ("Welcome To wxPython!")
        ]

        for i in range(len(statusbar_fields)):
            self.statusbar.SetStatusText(statusbar_fields[i], i)

        self.mainPanel = wx.Panel(self, -1)
        self.logtext = wx.TextCtrl(self.mainPanel,
                                   -1,
                                   "",
                                   style=wx.TE_MULTILINE | wx.TE_READONLY)

        vSizer = wx.BoxSizer(wx.VERTICAL)
        self.mainPanel.SetSizer(vSizer)

        self.alignments = [
            bp.BP_ALIGN_LEFT, bp.BP_ALIGN_RIGHT, bp.BP_ALIGN_TOP,
            bp.BP_ALIGN_BOTTOM
        ]

        self.alignment = bp.BP_ALIGN_LEFT
        self.style = bp.BP_USE_GRADIENT

        self.titleBar = bp.ButtonPanel(self.mainPanel,
                                       -1,
                                       "A Simple Test & Demo",
                                       style=self.style,
                                       alignment=self.alignment)

        self.created = False
        self.pngs = [
            (images._bp_btn1.GetBitmap(), 'label1'),
            (images._bp_btn2.GetBitmap(), 'label2'),
            (images._bp_btn3.GetBitmap(), 'label3'),
            (images._bp_btn4.GetBitmap(), 'label4'),
        ]
        self.CreateButtons()
        self.SetProperties()
Exemplo n.º 2
0
    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()
Exemplo n.º 3
0
    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