]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/GenericButtons.py
documented need to install ZIP handler
[wxWidgets.git] / wxPython / demo / GenericButtons.py
1
2 from wxPython.wx import *
3 from wxPython.lib.buttons import *
4
5 import images
6 #----------------------------------------------------------------------
7
8
9 class TestPanel(wxPanel):
10 def __init__(self, parent, log):
11 wxPanel.__init__(self, parent, -1)
12 self.log = log
13
14 sizer = wxFlexGridSizer(1, 3, 20, 20)
15 b = wxButton(self, -1, "A real button")
16 b.SetDefault()
17 EVT_BUTTON(self, b.GetId(), self.OnButton)
18 sizer.Add(b)
19
20 b = wxButton(self, -1, "non-default")
21 EVT_BUTTON(self, b.GetId(), self.OnButton)
22 sizer.Add(b)
23 sizer.Add(10,10)
24
25 b = wxGenButton(self, -1, 'Hello')
26 EVT_BUTTON(self, b.GetId(), self.OnButton)
27 sizer.Add(b)
28
29 b = wxGenButton(self, -1, 'disabled')
30 EVT_BUTTON(self, b.GetId(), self.OnButton)
31 b.Enable(false)
32 sizer.Add(b)
33
34 b = wxGenButton(self, -1, 'bigger')
35 EVT_BUTTON(self, b.GetId(), self.OnBiggerButton)
36 b.SetFont(wxFont(20, wxSWISS, wxNORMAL, wxBOLD, false))
37 b.SetBezelWidth(5)
38 ###b.SetBestSize()
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
43
44 bmp = images.getTest2Bitmap()
45 b = wxGenBitmapButton(self, -1, bmp)
46 EVT_BUTTON(self, b.GetId(), self.OnButton)
47 sizer.Add(b)
48
49 b = wxGenBitmapButton(self, -1, None)
50 EVT_BUTTON(self, b.GetId(), self.OnButton)
51 bmp = images.getBulb1Bitmap()
52 mask = wxMaskColour(bmp, wxBLUE)
53 bmp.SetMask(mask)
54 b.SetBitmapLabel(bmp)
55 bmp = images.getBulb2Bitmap()
56 mask = wxMaskColour(bmp, wxBLUE)
57 bmp.SetMask(mask)
58 b.SetBitmapSelected(bmp)
59 b.SetBestSize()
60 sizer.Add(b)
61 sizer.Add(10,10)
62
63 b = wxGenToggleButton(self, -1, "Toggle Button")
64 EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
65 sizer.Add(b)
66
67 b = wxGenBitmapToggleButton(self, -1, None)
68 EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
69 bmp = images.getBulb1Bitmap()
70 mask = wxMaskColour(bmp, wxBLUE)
71 bmp.SetMask(mask)
72 b.SetBitmapLabel(bmp)
73 bmp = images.getBulb2Bitmap()
74 mask = wxMaskColour(bmp, wxBLUE)
75 bmp.SetMask(mask)
76 b.SetBitmapSelected(bmp)
77 b.SetToggle(true)
78 b.SetBestSize()
79 sizer.Add(b)
80
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)
85 bmp.SetMask(mask)
86 b.SetBitmapLabel(bmp)
87 bmp = images.getBulb2Bitmap()
88 mask = wxMaskColour(bmp, wxBLUE)
89 bmp.SetMask(mask)
90 b.SetBitmapSelected(bmp)
91 b.SetUseFocusIndicator(false)
92 b.SetBestSize()
93 sizer.Add(b)
94
95 border = wxBoxSizer(wxVERTICAL)
96 border.Add(sizer, 0, wxALL, 25)
97 self.SetSizer(border)
98
99
100 def OnButton(self, event):
101 self.log.WriteText("Button Clicked: %d\n" % event.GetId())
102
103
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()
108 b.SetLabel(txt)
109 self.GetSizer().Layout()
110
111
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))
115
116
117
118 #----------------------------------------------------------------------
119
120
121 def runTest(frame, nb, log):
122 win = TestPanel(nb, log)
123 return win
124
125
126 #----------------------------------------------------------------------
127
128
129 import wxPython.lib.buttons
130 overview = wxPython.lib.buttons.__doc__