]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/GenericButtons.py
script to make the raw preview tarball
[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 bmp = images.getTest2Bitmap()
50 b = wxGenBitmapButton(self, -1, bmp)
51 EVT_BUTTON(self, b.GetId(), self.OnButton)
52 sizer.Add(b)
53 b.Enable(False)
54
55 b = wxGenBitmapButton(self, -1, None)
56 EVT_BUTTON(self, b.GetId(), self.OnButton)
57 bmp = images.getBulb1Bitmap()
58 mask = wxMaskColour(bmp, wxBLUE)
59 bmp.SetMask(mask)
60 b.SetBitmapLabel(bmp)
61 bmp = images.getBulb2Bitmap()
62 mask = wxMaskColour(bmp, wxBLUE)
63 bmp.SetMask(mask)
64 b.SetBitmapSelected(bmp)
65 b.SetBestSize()
66 sizer.Add(b)
67
68 b = wxGenToggleButton(self, -1, "Toggle Button")
69 EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
70 sizer.Add(b)
71
72 b = wxGenBitmapToggleButton(self, -1, None)
73 EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
74 bmp = images.getBulb1Bitmap()
75 mask = wxMaskColour(bmp, wxBLUE)
76 bmp.SetMask(mask)
77 b.SetBitmapLabel(bmp)
78 bmp = images.getBulb2Bitmap()
79 mask = wxMaskColour(bmp, wxBLUE)
80 bmp.SetMask(mask)
81 b.SetBitmapSelected(bmp)
82 b.SetToggle(True)
83 b.SetBestSize()
84 sizer.Add(b)
85
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)
90 bmp.SetMask(mask)
91 b.SetBitmapLabel(bmp)
92 bmp = images.getBulb2Bitmap()
93 mask = wxMaskColour(bmp, wxBLUE)
94 bmp.SetMask(mask)
95 b.SetBitmapSelected(bmp)
96 b.SetUseFocusIndicator(False)
97 b.SetBestSize()
98 sizer.Add(b)
99
100 border = wxBoxSizer(wxVERTICAL)
101 border.Add(sizer, 0, wxALL, 25)
102 self.SetSizer(border)
103
104
105 def OnButton(self, event):
106 self.log.WriteText("Button Clicked: %d\n" % event.GetId())
107
108
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()
113 b.SetLabel(txt)
114 self.GetSizer().Layout()
115
116
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))
120
121
122
123 #----------------------------------------------------------------------
124
125
126 def runTest(frame, nb, log):
127 win = TestPanel(nb, log)
128 return win
129
130
131 #----------------------------------------------------------------------
132
133
134 import wxPython.lib.buttons
135 overview = wxPython.lib.buttons.__doc__
136
137
138
139 if __name__ == '__main__':
140 import sys,os
141 import run
142 run.main(['', os.path.basename(sys.argv[0])])
143