]>
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) 
  13         ##self.SetBackgroundColour("sky blue") 
  15         sizer 
= wx
.FlexGridSizer(1, 3, 20, 20) 
  17         # A regular button, selected as the default button 
  18         b 
= wx
.Button(self
, -1, "A real button") 
  20         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
  23         # Same thing, but NOT set as the default button 
  24         b 
= wx
.Button(self
, -1, "non-default") 
  25         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
  29         # Plain old text button based off GenButton() 
  30         b 
= buttons
.GenButton(self
, -1, 'Hello') 
  31         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
  34         # Plain old text button, disabled. 
  35         b 
= buttons
.GenButton(self
, -1, 'disabled') 
  36         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
  40         # This time, we let the botton be as big as it can be. 
  41         # Also, this one is fancier, with custom colors and bezel size. 
  42         b 
= buttons
.GenButton(self
, -1, 'bigger') 
  43         self
.Bind(wx
.EVT_BUTTON
, self
.OnBiggerButton
, b
) 
  44         b
.SetFont(wx
.Font(20, wx
.SWISS
, wx
.NORMAL
, wx
.BOLD
, False)) 
  46         b
.SetMinSize(wx
.DefaultSize
) 
  47         b
.SetBackgroundColour("Navy") 
  48         b
.SetForegroundColour(wx
.WHITE
) 
  49         b
.SetToolTipString("This is a BIG button...") 
  50         # let the sizer set best size 
  51         sizer
.Add(b
, flag
=wx
.ADJUST_MINSIZE
)  
  54         bmp 
= images
.getTest2Bitmap() 
  55         b 
= buttons
.GenBitmapButton(self
, -1, bmp
) 
  56         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
  59         # An image button, disabled. 
  60         bmp 
= images
.getTest2Bitmap() 
  61         b 
= buttons
.GenBitmapButton(self
, -1, bmp
) 
  62         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
  66         # An image button, using a mask to get rid of the 
  67         # undesireable part of the image 
  68         b 
= buttons
.GenBitmapButton(self
, -1, None) 
  69         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
  70         bmp 
= images
.getBulb1Bitmap() 
  71         mask 
= wx
.Mask(bmp
, wx
.BLUE
) 
  74         bmp 
= images
.getBulb2Bitmap() 
  75         mask 
= wx
.Mask(bmp
, wx
.BLUE
) 
  77         b
.SetBitmapSelected(bmp
) 
  82         b 
= buttons
.GenToggleButton(self
, -1, "Toggle Button") 
  83         self
.Bind(wx
.EVT_BUTTON
, self
.OnToggleButton
, b
) 
  86         # An image toggle button 
  87         b 
= buttons
.GenBitmapToggleButton(self
, -1, None) 
  88         self
.Bind(wx
.EVT_BUTTON
, self
.OnToggleButton
, b
) 
  89         bmp 
= images
.getBulb1Bitmap() 
  90         mask 
= wx
.Mask(bmp
, wx
.BLUE
) 
  93         bmp 
= images
.getBulb2Bitmap() 
  94         mask 
= wx
.Mask(bmp
, wx
.BLUE
) 
  96         b
.SetBitmapSelected(bmp
) 
 101         # A bitmap button with text. 
 102         b 
= buttons
.GenBitmapTextButton(self
, -1, None, "Bitmapped Text", size 
= (200, 45)) 
 103         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
 104         bmp 
= images
.getBulb1Bitmap() 
 105         mask 
= wx
.Mask(bmp
, wx
.BLUE
) 
 107         b
.SetBitmapLabel(bmp
) 
 108         bmp 
= images
.getBulb2Bitmap() 
 109         mask 
= wx
.Mask(bmp
, wx
.BLUE
) 
 111         b
.SetBitmapSelected(bmp
) 
 112         b
.SetUseFocusIndicator(False) 
 118         b 
= buttons
.GenButton(self
, -1, 'Flat buttons too!', style
=wx
.BORDER_NONE
) 
 119         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
 120         sizer
.Add(b
, flag
=wx
.ALIGN_CENTER_VERTICAL
) 
 122         # A flat image button 
 123         bmp 
= images
.getTest2Bitmap() 
 124         bmp
.SetMaskColour("blue") 
 125         b 
= buttons
.GenBitmapButton(self
, -1, bmp
, style
=wx
.BORDER_NONE
) 
 126         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
 128         ##b.SetBackgroundColour("sky blue") 
 129         ##b.SetBackgroundColour("pink") 
 131         b 
= buttons
.ThemedGenButton(self
, -1, 'Drawn with native renderer') 
 132         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
 136         border 
= wx
.BoxSizer(wx
.VERTICAL
) 
 137         border
.Add(sizer
, 0, wx
.ALL
, 25) 
 138         self
.SetSizer(border
) 
 141     def OnButton(self
, event
): 
 142         self
.log
.WriteText("Button Clicked: %d\n" % event
.GetId()) 
 145     def OnBiggerButton(self
, event
): 
 146         self
.log
.WriteText("Bigger Button Clicked: %d\n" % event
.GetId()) 
 147         b 
= event
.GetEventObject() 
 148         txt 
= "big " + b
.GetLabel() 
 150         self
.GetSizer().Layout() 
 153     def OnToggleButton(self
, event
): 
 154         msg 
= (event
.GetIsDown() and "on") or "off" 
 155         self
.log
.WriteText("Button %d Toggled: %s\n" % (event
.GetId(), msg
)) 
 159 #---------------------------------------------------------------------- 
 162 def runTest(frame
, nb
, log
): 
 163     win 
= TestPanel(nb
, log
) 
 167 #---------------------------------------------------------------------- 
 170 overview 
= buttons
.__doc
__ 
 172 if __name__ 
== '__main__': 
 175     run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])