]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/GenericButtons.py
Remove some items from the Recent additions list
[wxWidgets.git] / wxPython / demo / GenericButtons.py
index 876542eae8374f9ec2401714fd0bbc3a8f5e121f..a142d5c2342dc260b714d8a6dd608d4ebc0ecb53 100644 (file)
 
-from wxPython.wx import *
-from wxPython.lib.buttons import wxGenButton, wxGenBitmapButton, \
-                                 wxGenToggleButton, wxGenBitmapToggleButton
+import  wx
+import  wx.lib.buttons  as  buttons
 
-#----------------------------------------------------------------------
+import images
 
+#----------------------------------------------------------------------
 
-class TestPanel(wxPanel):
+class TestPanel(wx.Panel):
     def __init__(self, parent, log):
-        wxPanel.__init__(self, parent, -1)
+        wx.Panel.__init__(self, parent, -1)
         self.log = log
+        ##self.SetBackgroundColour("sky blue")
+
+        sizer = wx.FlexGridSizer(1, 3, 20, 20)
 
-        b = wxButton(self, -1, "A real button", (10,10))
+        # A regular button, selected as the default button
+        b = wx.Button(self, -1, "A real button")
         b.SetDefault()
-        EVT_BUTTON(self, b.GetId(), self.OnButton)
-        b = wxButton(self, -1, "non-default", (140, 10))
-        EVT_BUTTON(self, b.GetId(), self.OnButton)
-        #wxTextCtrl(self, -1, "", (10,40))
-
-        b = wxGenButton(self, -1, 'Hello', (10,65))
-        EVT_BUTTON(self, b.GetId(), self.OnButton)
-        b = wxGenButton(self, -1, 'disabled', (140,65))
-        EVT_BUTTON(self, b.GetId(), self.OnButton)
-        b.Enable(false)
-
-        b = wxGenButton(self, -1, 'bigger', (250,50))
-        EVT_BUTTON(self, b.GetId(), self.OnButton)
-        b.SetFont(wxFont(20, wxSWISS, wxNORMAL, wxBOLD, false))
+        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
+        sizer.Add(b)
+
+        # Same thing, but NOT set as the default button
+        b = wx.Button(self, -1, "non-default")
+        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
+        sizer.Add(b)
+        sizer.Add((10,10))
+
+        # Plain old text button based off GenButton()
+        b = buttons.GenButton(self, -1, 'Hello')
+        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
+        sizer.Add(b)
+
+        # Plain old text button, disabled.
+        b = buttons.GenButton(self, -1, 'disabled')
+        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
+        b.Enable(False)
+        sizer.Add(b)
+
+        # This time, we let the botton be as big as it can be.
+        # Also, this one is fancier, with custom colors and bezel size.
+        b = buttons.GenButton(self, -1, 'bigger')
+        self.Bind(wx.EVT_BUTTON, self.OnBiggerButton, b)
+        b.SetFont(wx.Font(20, wx.SWISS, wx.NORMAL, wx.BOLD, False))
         b.SetBezelWidth(5)
-        b.SetBestSize()
-        b.SetBackgroundColour(wxNamedColour("Navy"))
-        b.SetForegroundColour(wxWHITE)
-        #b.SetUseFocusIndicator(false)
-
-        bmp = wxBitmap('bitmaps/test2.bmp', wxBITMAP_TYPE_BMP)
-        b = wxGenBitmapButton(self, -1, bmp, (10, 130))
-        EVT_BUTTON(self, b.GetId(), self.OnButton)
-
-
-        b = wxGenBitmapButton(self, -1, None, (140, 130))
-        EVT_BUTTON(self, b.GetId(), self.OnButton)
-        bmp = wxBitmap('bitmaps/lb1.bmp', wxBITMAP_TYPE_BMP)
-        mask = wxMaskColour(bmp, wxBLUE)
+        b.SetMinSize(wx.DefaultSize)
+        b.SetBackgroundColour("Navy")
+        b.SetForegroundColour(wx.WHITE)
+        b.SetToolTipString("This is a BIG button...")
+        # let the sizer set best size
+        sizer.Add(b, flag=wx.ADJUST_MINSIZE) 
+
+        # An image button
+        bmp = images.getTest2Bitmap()
+        b = buttons.GenBitmapButton(self, -1, bmp)
+        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
+        sizer.Add(b)
+
+        # An image button, disabled.
+        bmp = images.getTest2Bitmap()
+        b = buttons.GenBitmapButton(self, -1, bmp)
+        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
+        sizer.Add(b)
+        b.Enable(False)
+
+        # An image button, using a mask to get rid of the
+        # undesireable part of the image
+        b = buttons.GenBitmapButton(self, -1, None)
+        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
+        bmp = images.getBulb1Bitmap()
+        mask = wx.Mask(bmp, wx.BLUE)
         bmp.SetMask(mask)
         b.SetBitmapLabel(bmp)
-        bmp = wxBitmap('bitmaps/lb2.bmp', wxBITMAP_TYPE_BMP)
-        mask = wxMaskColour(bmp, wxBLUE)
+        bmp = images.getBulb2Bitmap()
+        mask = wx.Mask(bmp, wx.BLUE)
         bmp.SetMask(mask)
         b.SetBitmapSelected(bmp)
-        b.SetBestSize()
-
-        b = wxGenToggleButton(self, -1, "Toggle Button", (10, 230))
-        EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
-
-
-        b = wxGenBitmapToggleButton(self, -1, None, (140, 230))
-        EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
-        bmp = wxBitmap('bitmaps/lb1.bmp', wxBITMAP_TYPE_BMP)
-        mask = wxMaskColour(bmp, wxBLUE)
+        b.SetInitialSize()
+        sizer.Add(b)
+
+        # A toggle button
+        b = buttons.GenToggleButton(self, -1, "Toggle Button")
+        self.Bind(wx.EVT_BUTTON, self.OnToggleButton, b)
+        sizer.Add(b)
+
+        # An image toggle button
+        b = buttons.GenBitmapToggleButton(self, -1, None)
+        self.Bind(wx.EVT_BUTTON, self.OnToggleButton, b)
+        bmp = images.getBulb1Bitmap()
+        mask = wx.Mask(bmp, wx.BLUE)
         bmp.SetMask(mask)
         b.SetBitmapLabel(bmp)
-        bmp = wxBitmap('bitmaps/lb2.bmp', wxBITMAP_TYPE_BMP)
-        mask = wxMaskColour(bmp, wxBLUE)
+        bmp = images.getBulb2Bitmap()
+        mask = wx.Mask(bmp, wx.BLUE)
         bmp.SetMask(mask)
         b.SetBitmapSelected(bmp)
-        b.SetToggle(true)
-        b.SetBestSize()
+        b.SetToggle(True)
+        b.SetInitialSize()
+        sizer.Add(b)
+
+        # A bitmap button with text.
+        b = buttons.GenBitmapTextButton(self, -1, None, "Bitmapped Text", size = (200, 45))
+        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
+        bmp = images.getBulb1Bitmap()
+        mask = wx.Mask(bmp, wx.BLUE)
+        bmp.SetMask(mask)
+        b.SetBitmapLabel(bmp)
+        bmp = images.getBulb2Bitmap()
+        mask = wx.Mask(bmp, wx.BLUE)
+        bmp.SetMask(mask)
+        b.SetBitmapSelected(bmp)
+        b.SetUseFocusIndicator(False)
+        b.SetInitialSize()
+        sizer.Add(b)
+
+
+        # a flat text button
+        b = buttons.GenButton(self, -1, 'Flat buttons too!', style=wx.BORDER_NONE)
+        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
+        sizer.Add(b, flag=wx.ALIGN_CENTER_VERTICAL)
+
+        # A flat image button
+        bmp = images.getTest2Bitmap()
+        bmp.SetMaskColour("blue")
+        b = buttons.GenBitmapButton(self, -1, bmp, style=wx.BORDER_NONE)
+        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
+        sizer.Add(b)
+        ##b.SetBackgroundColour("sky blue")
+        ##b.SetBackgroundColour("pink")
+
+        b = buttons.ThemedGenButton(self, -1, 'Drawn with native renderer')
+        self.Bind(wx.EVT_BUTTON, self.OnButton, b)
+        sizer.Add(b)
+        
+
+        border = wx.BoxSizer(wx.VERTICAL)
+        border.Add(sizer, 0, wx.ALL, 25)
+        self.SetSizer(border)
 
 
     def OnButton(self, event):
         self.log.WriteText("Button Clicked: %d\n" % event.GetId())
 
+
+    def OnBiggerButton(self, event):
+        self.log.WriteText("Bigger Button Clicked: %d\n" % event.GetId())
+        b = event.GetEventObject()
+        txt = "big " + b.GetLabel()
+        b.SetLabel(txt)
+        self.GetSizer().Layout()
+
+
     def OnToggleButton(self, event):
         msg = (event.GetIsDown() and "on") or "off"
         self.log.WriteText("Button %d Toggled: %s\n" % (event.GetId(), msg))
@@ -88,5 +167,10 @@ def runTest(frame, nb, log):
 #----------------------------------------------------------------------
 
 
-import wxPython.lib.buttons
-overview = wxPython.lib.buttons.__doc__
+overview = buttons.__doc__
+
+if __name__ == '__main__':
+    import sys,os
+    import run
+    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
+