]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/GenericButtons.py
   3 import  wx
.lib
.buttons  
as  buttons
 
   7 #---------------------------------------------------------------------- 
   9 class TestPanel(wx
.Panel
): 
  10     def __init__(self
, parent
, log
): 
  11         wx
.Panel
.__init
__(self
, parent
, -1) 
  14         sizer 
= wx
.FlexGridSizer(1, 3, 20, 20) 
  16         # A regular button, selected as the default button 
  17         b 
= wx
.Button(self
, -1, "A real button") 
  19         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
  22         # Same thing, but NOT set as the default button 
  23         b 
= wx
.Button(self
, -1, "non-default") 
  24         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
  28         # Plain old text button based off GenButton() 
  29         b 
= buttons
.GenButton(self
, -1, 'Hello') 
  30         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
  33         # Plain old text button, disabled. 
  34         b 
= buttons
.GenButton(self
, -1, 'disabled') 
  35         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
  39         # This time, we let the botton be as big as it can be. 
  40         # Also, this one is fancier, with custom colors and bezel size. 
  41         b 
= buttons
.GenButton(self
, -1, 'bigger') 
  42         self
.Bind(wx
.EVT_BUTTON
, self
.OnBiggerButton
, b
) 
  43         b
.SetFont(wx
.Font(20, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
, False)) 
  46         b
.SetBackgroundColour("Navy") 
  47         b
.SetForegroundColour(wx
.WHITE
) 
  48         b
.SetToolTipString("This is a BIG button...") 
  49         # let the sizer set best size 
  50         sizer
.Add(b
, flag
=wx
.ADJUST_MINSIZE
)  
  53         bmp 
= images
.getTest2Bitmap() 
  54         b 
= buttons
.GenBitmapButton(self
, -1, bmp
) 
  55         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
  58         # An image button, disabled. 
  59         bmp 
= images
.getTest2Bitmap() 
  60         b 
= buttons
.GenBitmapButton(self
, -1, bmp
) 
  61         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
  65         # An image button, using a mask to get rid of the 
  66         # undesireable part of the image 
  67         b 
= buttons
.GenBitmapButton(self
, -1, None) 
  68         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
  69         bmp 
= images
.getBulb1Bitmap() 
  70         mask 
= wx
.MaskColour(bmp
, wx
.BLUE
) 
  73         bmp 
= images
.getBulb2Bitmap() 
  74         mask 
= wx
.MaskColour(bmp
, wx
.BLUE
) 
  76         b
.SetBitmapSelected(bmp
) 
  81         b 
= buttons
.GenToggleButton(self
, -1, "Toggle Button") 
  82         self
.Bind(wx
.EVT_BUTTON
, self
.OnToggleButton
, b
) 
  85         # An image toggle button 
  86         b 
= buttons
.GenBitmapToggleButton(self
, -1, None) 
  87         self
.Bind(wx
.EVT_BUTTON
, self
.OnToggleButton
, b
) 
  88         bmp 
= images
.getBulb1Bitmap() 
  89         mask 
= wx
.MaskColour(bmp
, wx
.BLUE
) 
  92         bmp 
= images
.getBulb2Bitmap() 
  93         mask 
= wx
.MaskColour(bmp
, wx
.BLUE
) 
  95         b
.SetBitmapSelected(bmp
) 
 100         # A bitmap button with text. 
 101         b 
= buttons
.GenBitmapTextButton(self
, -1, None, "Bitmapped Text", size 
= (200, 45)) 
 102         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
 103         bmp 
= images
.getBulb1Bitmap() 
 104         mask 
= wx
.MaskColour(bmp
, wx
.BLUE
) 
 106         b
.SetBitmapLabel(bmp
) 
 107         bmp 
= images
.getBulb2Bitmap() 
 108         mask 
= wx
.MaskColour(bmp
, wx
.BLUE
) 
 110         b
.SetBitmapSelected(bmp
) 
 111         b
.SetUseFocusIndicator(False) 
 115         border 
= wx
.BoxSizer(wx
.VERTICAL
) 
 116         border
.Add(sizer
, 0, wx
.ALL
, 25) 
 117         self
.SetSizer(border
) 
 120     def OnButton(self
, event
): 
 121         self
.log
.WriteText("Button Clicked: %d\n" % event
.GetId()) 
 124     def OnBiggerButton(self
, event
): 
 125         self
.log
.WriteText("Bigger Button Clicked: %d\n" % event
.GetId()) 
 126         b 
= event
.GetEventObject() 
 127         txt 
= "big " + b
.GetLabel() 
 129         self
.GetSizer().Layout() 
 132     def OnToggleButton(self
, event
): 
 133         msg 
= (event
.GetIsDown() and "on") or "off" 
 134         self
.log
.WriteText("Button %d Toggled: %s\n" % (event
.GetId(), msg
)) 
 138 #---------------------------------------------------------------------- 
 141 def runTest(frame
, nb
, log
): 
 142     win 
= TestPanel(nb
, log
) 
 146 #---------------------------------------------------------------------- 
 149 overview 
= buttons
.__doc
__ 
 151 if __name__ 
== '__main__': 
 154     run
.main(['', os
.path
.basename(sys
.argv
[0])])