]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/GenericButtons.py
2 from wxPython
.wx
import *
3 from wxPython
.lib
.buttons
import *
6 #----------------------------------------------------------------------
9 class TestPanel(wxPanel
):
10 def __init__(self
, parent
, log
):
11 wxPanel
.__init
__(self
, parent
, -1)
14 sizer
= wxFlexGridSizer(1, 3, 20, 20)
15 b
= wxButton(self
, -1, "A real button")
17 EVT_BUTTON(self
, b
.GetId(), self
.OnButton
)
20 b
= wxButton(self
, -1, "non-default")
21 EVT_BUTTON(self
, b
.GetId(), self
.OnButton
)
25 b
= wxGenButton(self
, -1, 'Hello')
26 EVT_BUTTON(self
, b
.GetId(), self
.OnButton
)
29 b
= wxGenButton(self
, -1, 'disabled')
30 EVT_BUTTON(self
, b
.GetId(), self
.OnButton
)
34 b
= wxGenButton(self
, -1, 'bigger')
35 EVT_BUTTON(self
, b
.GetId(), self
.OnBiggerButton
)
36 b
.SetFont(wxFont(20, wxSWISS
, wxNORMAL
, wxBOLD
, false
))
39 b
.SetBackgroundColour("Navy")
40 b
.SetForegroundColour(wxWHITE
)
41 b
.SetToolTipString("This is a BIG button...")
42 sizer
.Add(b
, flag
=wxADJUST_MINSIZE
) # let the sizer set best size
44 bmp
= images
.getTest2Bitmap()
45 b
= wxGenBitmapButton(self
, -1, bmp
)
46 EVT_BUTTON(self
, b
.GetId(), self
.OnButton
)
49 b
= wxGenBitmapButton(self
, -1, None)
50 EVT_BUTTON(self
, b
.GetId(), self
.OnButton
)
51 bmp
= images
.getBulb1Bitmap()
52 mask
= wxMaskColour(bmp
, wxBLUE
)
55 bmp
= images
.getBulb2Bitmap()
56 mask
= wxMaskColour(bmp
, wxBLUE
)
58 b
.SetBitmapSelected(bmp
)
63 b
= wxGenToggleButton(self
, -1, "Toggle Button")
64 EVT_BUTTON(self
, b
.GetId(), self
.OnToggleButton
)
67 b
= wxGenBitmapToggleButton(self
, -1, None)
68 EVT_BUTTON(self
, b
.GetId(), self
.OnToggleButton
)
69 bmp
= images
.getBulb1Bitmap()
70 mask
= wxMaskColour(bmp
, wxBLUE
)
73 bmp
= images
.getBulb2Bitmap()
74 mask
= wxMaskColour(bmp
, wxBLUE
)
76 b
.SetBitmapSelected(bmp
)
81 b
= wxGenBitmapTextButton(self
, -1, None, "Bitmapped Text", size
= (200, 45))
82 EVT_BUTTON(self
, b
.GetId(), self
.OnButton
)
83 bmp
= images
.getBulb1Bitmap()
84 mask
= wxMaskColour(bmp
, wxBLUE
)
87 bmp
= images
.getBulb2Bitmap()
88 mask
= wxMaskColour(bmp
, wxBLUE
)
90 b
.SetBitmapSelected(bmp
)
91 b
.SetUseFocusIndicator(false
)
95 border
= wxBoxSizer(wxVERTICAL
)
96 border
.Add(sizer
, 0, wxALL
, 25)
100 def OnButton(self
, event
):
101 self
.log
.WriteText("Button Clicked: %d\n" % event
.GetId())
104 def OnBiggerButton(self
, event
):
105 self
.log
.WriteText("Bigger Button Clicked: %d\n" % event
.GetId())
106 b
= event
.GetEventObject()
107 txt
= "big " + b
.GetLabel()
109 self
.GetSizer().Layout()
112 def OnToggleButton(self
, event
):
113 msg
= (event
.GetIsDown() and "on") or "off"
114 self
.log
.WriteText("Button %d Toggled: %s\n" % (event
.GetId(), msg
))
118 #----------------------------------------------------------------------
121 def runTest(frame
, nb
, log
):
122 win
= TestPanel(nb
, log
)
126 #----------------------------------------------------------------------
129 import wxPython
.lib
.buttons
130 overview
= wxPython
.lib
.buttons
.__doc
__