]>
Commit | Line | Data |
---|---|---|
1 | ||
2 | import wx | |
3 | import wx.lib.buttons as buttons | |
4 | ||
5 | import images | |
6 | ||
7 | #---------------------------------------------------------------------- | |
8 | ||
9 | class TestPanel(wx.Panel): | |
10 | def __init__(self, parent, log): | |
11 | wx.Panel.__init__(self, parent, -1) | |
12 | self.log = log | |
13 | ##self.SetBackgroundColour("sky blue") | |
14 | ||
15 | sizer = wx.FlexGridSizer(1, 3, 20, 20) | |
16 | ||
17 | # A regular button, selected as the default button | |
18 | b = wx.Button(self, -1, "A real button") | |
19 | b.SetDefault() | |
20 | self.Bind(wx.EVT_BUTTON, self.OnButton, b) | |
21 | sizer.Add(b) | |
22 | ||
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) | |
26 | sizer.Add(b) | |
27 | sizer.Add((10,10)) | |
28 | ||
29 | # Plain old text button based off GenButton() | |
30 | b = buttons.GenButton(self, -1, 'Hello') | |
31 | self.Bind(wx.EVT_BUTTON, self.OnButton, b) | |
32 | sizer.Add(b) | |
33 | ||
34 | # Plain old text button, disabled. | |
35 | b = buttons.GenButton(self, -1, 'disabled') | |
36 | self.Bind(wx.EVT_BUTTON, self.OnButton, b) | |
37 | b.Enable(False) | |
38 | sizer.Add(b) | |
39 | ||
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)) | |
45 | b.SetBezelWidth(5) | |
46 | ###b.SetBestSize() | |
47 | b.SetMinSize(wx.DefaultSize) | |
48 | b.SetBackgroundColour("Navy") | |
49 | b.SetForegroundColour(wx.WHITE) | |
50 | b.SetToolTipString("This is a BIG button...") | |
51 | # let the sizer set best size | |
52 | sizer.Add(b, flag=wx.ADJUST_MINSIZE) | |
53 | ||
54 | # An image button | |
55 | bmp = images.getTest2Bitmap() | |
56 | b = buttons.GenBitmapButton(self, -1, bmp) | |
57 | self.Bind(wx.EVT_BUTTON, self.OnButton, b) | |
58 | sizer.Add(b) | |
59 | ||
60 | # An image button, disabled. | |
61 | bmp = images.getTest2Bitmap() | |
62 | b = buttons.GenBitmapButton(self, -1, bmp) | |
63 | self.Bind(wx.EVT_BUTTON, self.OnButton, b) | |
64 | sizer.Add(b) | |
65 | b.Enable(False) | |
66 | ||
67 | # An image button, using a mask to get rid of the | |
68 | # undesireable part of the image | |
69 | b = buttons.GenBitmapButton(self, -1, None) | |
70 | self.Bind(wx.EVT_BUTTON, self.OnButton, b) | |
71 | bmp = images.getBulb1Bitmap() | |
72 | mask = wx.Mask(bmp, wx.BLUE) | |
73 | bmp.SetMask(mask) | |
74 | b.SetBitmapLabel(bmp) | |
75 | bmp = images.getBulb2Bitmap() | |
76 | mask = wx.Mask(bmp, wx.BLUE) | |
77 | bmp.SetMask(mask) | |
78 | b.SetBitmapSelected(bmp) | |
79 | b.SetBestSize() | |
80 | sizer.Add(b) | |
81 | ||
82 | # A toggle button | |
83 | b = buttons.GenToggleButton(self, -1, "Toggle Button") | |
84 | self.Bind(wx.EVT_BUTTON, self.OnToggleButton, b) | |
85 | sizer.Add(b) | |
86 | ||
87 | # An image toggle button | |
88 | b = buttons.GenBitmapToggleButton(self, -1, None) | |
89 | self.Bind(wx.EVT_BUTTON, self.OnToggleButton, b) | |
90 | bmp = images.getBulb1Bitmap() | |
91 | mask = wx.Mask(bmp, wx.BLUE) | |
92 | bmp.SetMask(mask) | |
93 | b.SetBitmapLabel(bmp) | |
94 | bmp = images.getBulb2Bitmap() | |
95 | mask = wx.Mask(bmp, wx.BLUE) | |
96 | bmp.SetMask(mask) | |
97 | b.SetBitmapSelected(bmp) | |
98 | b.SetToggle(True) | |
99 | b.SetBestSize() | |
100 | sizer.Add(b) | |
101 | ||
102 | # A bitmap button with text. | |
103 | b = buttons.GenBitmapTextButton(self, -1, None, "Bitmapped Text", size = (200, 45)) | |
104 | self.Bind(wx.EVT_BUTTON, self.OnButton, b) | |
105 | bmp = images.getBulb1Bitmap() | |
106 | mask = wx.Mask(bmp, wx.BLUE) | |
107 | bmp.SetMask(mask) | |
108 | b.SetBitmapLabel(bmp) | |
109 | bmp = images.getBulb2Bitmap() | |
110 | mask = wx.Mask(bmp, wx.BLUE) | |
111 | bmp.SetMask(mask) | |
112 | b.SetBitmapSelected(bmp) | |
113 | b.SetUseFocusIndicator(False) | |
114 | b.SetBestSize() | |
115 | sizer.Add(b) | |
116 | ||
117 | border = wx.BoxSizer(wx.VERTICAL) | |
118 | border.Add(sizer, 0, wx.ALL, 25) | |
119 | self.SetSizer(border) | |
120 | ||
121 | ||
122 | def OnButton(self, event): | |
123 | self.log.WriteText("Button Clicked: %d\n" % event.GetId()) | |
124 | ||
125 | ||
126 | def OnBiggerButton(self, event): | |
127 | self.log.WriteText("Bigger Button Clicked: %d\n" % event.GetId()) | |
128 | b = event.GetEventObject() | |
129 | txt = "big " + b.GetLabel() | |
130 | b.SetLabel(txt) | |
131 | self.GetSizer().Layout() | |
132 | ||
133 | ||
134 | def OnToggleButton(self, event): | |
135 | msg = (event.GetIsDown() and "on") or "off" | |
136 | self.log.WriteText("Button %d Toggled: %s\n" % (event.GetId(), msg)) | |
137 | ||
138 | ||
139 | ||
140 | #---------------------------------------------------------------------- | |
141 | ||
142 | ||
143 | def runTest(frame, nb, log): | |
144 | win = TestPanel(nb, log) | |
145 | return win | |
146 | ||
147 | ||
148 | #---------------------------------------------------------------------- | |
149 | ||
150 | ||
151 | overview = buttons.__doc__ | |
152 | ||
153 | if __name__ == '__main__': | |
154 | import sys,os | |
155 | import run | |
156 | run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) | |
157 |