]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/GenericButtons.py
fix text scrolling in GTK2 (patch 703988)
[wxWidgets.git] / wxPython / demo / GenericButtons.py
index ccdf0ef34af4ab775fb1c1ba4662fa3fbb3f564d..c3e7ff40398dd0543da0d22560aa03563c79f53b 100644 (file)
@@ -1,8 +1,8 @@
 
 from wxPython.wx import *
 
 from wxPython.wx import *
-from wxPython.lib.buttons import wxGenButton, wxGenBitmapButton, \
-                                 wxGenToggleButton, wxGenBitmapToggleButton
+from wxPython.lib.buttons import *
 
 
+import images
 #----------------------------------------------------------------------
 
 
 #----------------------------------------------------------------------
 
 
@@ -11,67 +11,109 @@ class TestPanel(wxPanel):
         wxPanel.__init__(self, parent, -1)
         self.log = log
 
         wxPanel.__init__(self, parent, -1)
         self.log = log
 
-        b = wxButton(self, -1, "A real button", (10,10))
+        sizer = wxFlexGridSizer(1, 3, 20, 20)
+        b = wxButton(self, -1, "A real button")
         b.SetDefault()
         EVT_BUTTON(self, b.GetId(), self.OnButton)
         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))
+        sizer.Add(b)
 
 
-        b = wxGenButton(self, -1, 'Hello', (10,65))
+        b = wxButton(self, -1, "non-default")
         EVT_BUTTON(self, b.GetId(), self.OnButton)
         EVT_BUTTON(self, b.GetId(), self.OnButton)
-        b = wxGenButton(self, -1, 'disabled', (140,65))
+        sizer.Add(b)
+        sizer.Add(10,10)
+
+        b = wxGenButton(self, -1, 'Hello')
         EVT_BUTTON(self, b.GetId(), self.OnButton)
         EVT_BUTTON(self, b.GetId(), self.OnButton)
-        b.Enable(false)
+        sizer.Add(b)
 
 
-        b = wxGenButton(self, -1, 'bigger', (250,50))
+        b = wxGenButton(self, -1, 'disabled')
         EVT_BUTTON(self, b.GetId(), self.OnButton)
         EVT_BUTTON(self, b.GetId(), self.OnButton)
-        b.SetFont(wxFont(20, wxSWISS, wxNORMAL, wxBOLD, false))
+        b.Enable(False)
+        sizer.Add(b)
+
+        b = wxGenButton(self, -1, 'bigger')
+        EVT_BUTTON(self, b.GetId(), self.OnBiggerButton)
+        b.SetFont(wxFont(20, wxSWISS, wxNORMAL, wxBOLD, False))
         b.SetBezelWidth(5)
         b.SetBezelWidth(5)
-        b.SetBestSize()
-        b.SetBackgroundColour(wxNamedColour("Navy"))
+        ###b.SetBestSize()
+        b.SetBackgroundColour("Navy")
         b.SetForegroundColour(wxWHITE)
         b.SetForegroundColour(wxWHITE)
-        #b.SetUseFocusIndicator(false)
         b.SetToolTipString("This is a BIG button...")
         b.SetToolTipString("This is a BIG button...")
+        sizer.Add(b, flag=wxADJUST_MINSIZE)  # let the sizer set best size
 
 
-        bmp = wxBitmap('bitmaps/test2.bmp', wxBITMAP_TYPE_BMP)
-        b = wxGenBitmapButton(self, -1, bmp, (10, 130))
+        bmp = images.getTest2Bitmap()
+        b = wxGenBitmapButton(self, -1, bmp)
         EVT_BUTTON(self, b.GetId(), self.OnButton)
         EVT_BUTTON(self, b.GetId(), self.OnButton)
+        sizer.Add(b)
 
 
+        bmp = images.getTest2Bitmap()
+        b = wxGenBitmapButton(self, -1, bmp)
+        EVT_BUTTON(self, b.GetId(), self.OnButton)
+        sizer.Add(b)
+        b.Enable(False)
 
 
-        b = wxGenBitmapButton(self, -1, None, (140, 130))
+        b = wxGenBitmapButton(self, -1, None)
         EVT_BUTTON(self, b.GetId(), self.OnButton)
         EVT_BUTTON(self, b.GetId(), self.OnButton)
-        bmp = wxBitmap('bitmaps/lb1.bmp', wxBITMAP_TYPE_BMP)
+        bmp = images.getBulb1Bitmap()
         mask = wxMaskColour(bmp, wxBLUE)
         bmp.SetMask(mask)
         b.SetBitmapLabel(bmp)
         mask = wxMaskColour(bmp, wxBLUE)
         bmp.SetMask(mask)
         b.SetBitmapLabel(bmp)
-        bmp = wxBitmap('bitmaps/lb2.bmp', wxBITMAP_TYPE_BMP)
+        bmp = images.getBulb2Bitmap()
         mask = wxMaskColour(bmp, wxBLUE)
         bmp.SetMask(mask)
         b.SetBitmapSelected(bmp)
         b.SetBestSize()
         mask = wxMaskColour(bmp, wxBLUE)
         bmp.SetMask(mask)
         b.SetBitmapSelected(bmp)
         b.SetBestSize()
+        sizer.Add(b)
 
 
-        b = wxGenToggleButton(self, -1, "Toggle Button", (10, 230))
+        b = wxGenToggleButton(self, -1, "Toggle Button")
         EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
         EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
+        sizer.Add(b)
 
 
-
-        b = wxGenBitmapToggleButton(self, -1, None, (140, 230))
+        b = wxGenBitmapToggleButton(self, -1, None)
         EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
         EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
-        bmp = wxBitmap('bitmaps/lb1.bmp', wxBITMAP_TYPE_BMP)
+        bmp = images.getBulb1Bitmap()
         mask = wxMaskColour(bmp, wxBLUE)
         bmp.SetMask(mask)
         b.SetBitmapLabel(bmp)
         mask = wxMaskColour(bmp, wxBLUE)
         bmp.SetMask(mask)
         b.SetBitmapLabel(bmp)
-        bmp = wxBitmap('bitmaps/lb2.bmp', wxBITMAP_TYPE_BMP)
+        bmp = images.getBulb2Bitmap()
         mask = wxMaskColour(bmp, wxBLUE)
         bmp.SetMask(mask)
         b.SetBitmapSelected(bmp)
         mask = wxMaskColour(bmp, wxBLUE)
         bmp.SetMask(mask)
         b.SetBitmapSelected(bmp)
-        b.SetToggle(true)
+        b.SetToggle(True)
         b.SetBestSize()
         b.SetBestSize()
+        sizer.Add(b)
+
+        b = wxGenBitmapTextButton(self, -1, None, "Bitmapped Text", size = (200, 45))
+        EVT_BUTTON(self, b.GetId(), self.OnButton)
+        bmp = images.getBulb1Bitmap()
+        mask = wxMaskColour(bmp, wxBLUE)
+        bmp.SetMask(mask)
+        b.SetBitmapLabel(bmp)
+        bmp = images.getBulb2Bitmap()
+        mask = wxMaskColour(bmp, wxBLUE)
+        bmp.SetMask(mask)
+        b.SetBitmapSelected(bmp)
+        b.SetUseFocusIndicator(False)
+        b.SetBestSize()
+        sizer.Add(b)
+
+        border = wxBoxSizer(wxVERTICAL)
+        border.Add(sizer, 0, wxALL, 25)
+        self.SetSizer(border)
 
 
     def OnButton(self, event):
         self.log.WriteText("Button Clicked: %d\n" % event.GetId())
 
 
 
     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))
     def OnToggleButton(self, event):
         msg = (event.GetIsDown() and "on") or "off"
         self.log.WriteText("Button %d Toggled: %s\n" % (event.GetId(), msg))
@@ -91,3 +133,11 @@ def runTest(frame, nb, log):
 
 import wxPython.lib.buttons
 overview = wxPython.lib.buttons.__doc__
 
 import wxPython.lib.buttons
 overview = wxPython.lib.buttons.__doc__
+
+
+
+if __name__ == '__main__':
+    import sys,os
+    import run
+    run.main(['', os.path.basename(sys.argv[0])])
+