]>
Commit | Line | Data |
---|---|---|
6999b0d8 RD |
1 | |
2 | from wxPython.wx import * | |
ddcb3d83 | 3 | from wxPython.lib.buttons import * |
6999b0d8 | 4 | |
96bfd053 | 5 | import images |
6999b0d8 RD |
6 | #---------------------------------------------------------------------- |
7 | ||
8 | ||
9 | class TestPanel(wxPanel): | |
10 | def __init__(self, parent, log): | |
11 | wxPanel.__init__(self, parent, -1) | |
12 | self.log = log | |
13 | ||
b0e5c039 RD |
14 | sizer = wxFlexGridSizer(1, 3, 20, 20) |
15 | b = wxButton(self, -1, "A real button") | |
6999b0d8 RD |
16 | b.SetDefault() |
17 | EVT_BUTTON(self, b.GetId(), self.OnButton) | |
b0e5c039 RD |
18 | sizer.Add(b) |
19 | ||
20 | b = wxButton(self, -1, "non-default") | |
6999b0d8 | 21 | EVT_BUTTON(self, b.GetId(), self.OnButton) |
b0e5c039 RD |
22 | sizer.Add(b) |
23 | sizer.Add(10,10) | |
6999b0d8 | 24 | |
b0e5c039 | 25 | b = wxGenButton(self, -1, 'Hello') |
6999b0d8 | 26 | EVT_BUTTON(self, b.GetId(), self.OnButton) |
b0e5c039 RD |
27 | sizer.Add(b) |
28 | ||
29 | b = wxGenButton(self, -1, 'disabled') | |
6999b0d8 RD |
30 | EVT_BUTTON(self, b.GetId(), self.OnButton) |
31 | b.Enable(false) | |
b0e5c039 | 32 | sizer.Add(b) |
6999b0d8 | 33 | |
b0e5c039 RD |
34 | b = wxGenButton(self, -1, 'bigger') |
35 | EVT_BUTTON(self, b.GetId(), self.OnBiggerButton) | |
6999b0d8 RD |
36 | b.SetFont(wxFont(20, wxSWISS, wxNORMAL, wxBOLD, false)) |
37 | b.SetBezelWidth(5) | |
b0e5c039 RD |
38 | ###b.SetBestSize() |
39 | b.SetBackgroundColour("Navy") | |
6999b0d8 | 40 | b.SetForegroundColour(wxWHITE) |
185d7c3e | 41 | b.SetToolTipString("This is a BIG button...") |
b0e5c039 | 42 | sizer.Add(b, flag=wxADJUST_MINSIZE) # let the sizer set best size |
6999b0d8 | 43 | |
96bfd053 | 44 | bmp = images.getTest2Bitmap() |
b0e5c039 | 45 | b = wxGenBitmapButton(self, -1, bmp) |
6999b0d8 | 46 | EVT_BUTTON(self, b.GetId(), self.OnButton) |
b0e5c039 | 47 | sizer.Add(b) |
6999b0d8 | 48 | |
b0e5c039 | 49 | b = wxGenBitmapButton(self, -1, None) |
6999b0d8 | 50 | EVT_BUTTON(self, b.GetId(), self.OnButton) |
96bfd053 | 51 | bmp = images.getBulb1Bitmap() |
54b96882 RD |
52 | mask = wxMaskColour(bmp, wxBLUE) |
53 | bmp.SetMask(mask) | |
6999b0d8 | 54 | b.SetBitmapLabel(bmp) |
96bfd053 | 55 | bmp = images.getBulb2Bitmap() |
54b96882 RD |
56 | mask = wxMaskColour(bmp, wxBLUE) |
57 | bmp.SetMask(mask) | |
6999b0d8 | 58 | b.SetBitmapSelected(bmp) |
78385733 | 59 | b.SetBestSize() |
b0e5c039 RD |
60 | sizer.Add(b) |
61 | sizer.Add(10,10) | |
6999b0d8 | 62 | |
b0e5c039 | 63 | b = wxGenToggleButton(self, -1, "Toggle Button") |
6999b0d8 | 64 | EVT_BUTTON(self, b.GetId(), self.OnToggleButton) |
b0e5c039 | 65 | sizer.Add(b) |
6999b0d8 | 66 | |
b0e5c039 | 67 | b = wxGenBitmapToggleButton(self, -1, None) |
6999b0d8 | 68 | EVT_BUTTON(self, b.GetId(), self.OnToggleButton) |
96bfd053 | 69 | bmp = images.getBulb1Bitmap() |
54b96882 RD |
70 | mask = wxMaskColour(bmp, wxBLUE) |
71 | bmp.SetMask(mask) | |
6999b0d8 | 72 | b.SetBitmapLabel(bmp) |
96bfd053 | 73 | bmp = images.getBulb2Bitmap() |
54b96882 RD |
74 | mask = wxMaskColour(bmp, wxBLUE) |
75 | bmp.SetMask(mask) | |
6999b0d8 | 76 | b.SetBitmapSelected(bmp) |
fbff5d1b | 77 | b.SetToggle(true) |
78385733 | 78 | b.SetBestSize() |
b0e5c039 | 79 | sizer.Add(b) |
6999b0d8 | 80 | |
b0e5c039 | 81 | b = wxGenBitmapTextButton(self, -1, None, "Bitmapped Text", size = (200, 45)) |
ddcb3d83 RD |
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() | |
b0e5c039 RD |
93 | sizer.Add(b) |
94 | ||
95 | border = wxBoxSizer(wxVERTICAL) | |
96 | border.Add(sizer, 0, wxALL, 25) | |
97 | self.SetSizer(border) | |
ddcb3d83 | 98 | |
6999b0d8 RD |
99 | |
100 | def OnButton(self, event): | |
101 | self.log.WriteText("Button Clicked: %d\n" % event.GetId()) | |
102 | ||
b0e5c039 RD |
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 | ||
6999b0d8 RD |
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__ |