]>
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 bmp
= images
.getTest2Bitmap()
50 b
= wxGenBitmapButton(self
, -1, bmp
)
51 EVT_BUTTON(self
, b
.GetId(), self
.OnButton
)
55 b
= wxGenBitmapButton(self
, -1, None)
56 EVT_BUTTON(self
, b
.GetId(), self
.OnButton
)
57 bmp
= images
.getBulb1Bitmap()
58 mask
= wxMaskColour(bmp
, wxBLUE
)
61 bmp
= images
.getBulb2Bitmap()
62 mask
= wxMaskColour(bmp
, wxBLUE
)
64 b
.SetBitmapSelected(bmp
)
68 b
= wxGenToggleButton(self
, -1, "Toggle Button")
69 EVT_BUTTON(self
, b
.GetId(), self
.OnToggleButton
)
72 b
= wxGenBitmapToggleButton(self
, -1, None)
73 EVT_BUTTON(self
, b
.GetId(), self
.OnToggleButton
)
74 bmp
= images
.getBulb1Bitmap()
75 mask
= wxMaskColour(bmp
, wxBLUE
)
78 bmp
= images
.getBulb2Bitmap()
79 mask
= wxMaskColour(bmp
, wxBLUE
)
81 b
.SetBitmapSelected(bmp
)
86 b
= wxGenBitmapTextButton(self
, -1, None, "Bitmapped Text", size
= (200, 45))
87 EVT_BUTTON(self
, b
.GetId(), self
.OnButton
)
88 bmp
= images
.getBulb1Bitmap()
89 mask
= wxMaskColour(bmp
, wxBLUE
)
92 bmp
= images
.getBulb2Bitmap()
93 mask
= wxMaskColour(bmp
, wxBLUE
)
95 b
.SetBitmapSelected(bmp
)
96 b
.SetUseFocusIndicator(False)
100 border
= wxBoxSizer(wxVERTICAL
)
101 border
.Add(sizer
, 0, wxALL
, 25)
102 self
.SetSizer(border
)
105 def OnButton(self
, event
):
106 self
.log
.WriteText("Button Clicked: %d\n" % event
.GetId())
109 def OnBiggerButton(self
, event
):
110 self
.log
.WriteText("Bigger Button Clicked: %d\n" % event
.GetId())
111 b
= event
.GetEventObject()
112 txt
= "big " + b
.GetLabel()
114 self
.GetSizer().Layout()
117 def OnToggleButton(self
, event
):
118 msg
= (event
.GetIsDown() and "on") or "off"
119 self
.log
.WriteText("Button %d Toggled: %s\n" % (event
.GetId(), msg
))
123 #----------------------------------------------------------------------
126 def runTest(frame
, nb
, log
):
127 win
= TestPanel(nb
, log
)
131 #----------------------------------------------------------------------
134 import wxPython
.lib
.buttons
135 overview
= wxPython
.lib
.buttons
.__doc
__
139 if __name__
== '__main__':
142 run
.main(['', os
.path
.basename(sys
.argv
[0])])