]> git.saurik.com Git - wxWidgets.git/blame - wxPython/demo/GenericButtons.py
Cosmetic cleanup (-1 -> wxID_ANY, TRUE->true).
[wxWidgets.git] / wxPython / demo / GenericButtons.py
CommitLineData
6999b0d8
RD
1
2from wxPython.wx import *
ddcb3d83 3from wxPython.lib.buttons import *
6999b0d8 4
96bfd053 5import images
6999b0d8
RD
6#----------------------------------------------------------------------
7
8
9class 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 30 EVT_BUTTON(self, b.GetId(), self.OnButton)
1e4a197e 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)
1e4a197e 36 b.SetFont(wxFont(20, wxSWISS, wxNORMAL, wxBOLD, False))
6999b0d8 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
1e4a197e
RD
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
b0e5c039 55 b = wxGenBitmapButton(self, -1, None)
6999b0d8 56 EVT_BUTTON(self, b.GetId(), self.OnButton)
96bfd053 57 bmp = images.getBulb1Bitmap()
54b96882
RD
58 mask = wxMaskColour(bmp, wxBLUE)
59 bmp.SetMask(mask)
6999b0d8 60 b.SetBitmapLabel(bmp)
96bfd053 61 bmp = images.getBulb2Bitmap()
54b96882
RD
62 mask = wxMaskColour(bmp, wxBLUE)
63 bmp.SetMask(mask)
6999b0d8 64 b.SetBitmapSelected(bmp)
78385733 65 b.SetBestSize()
b0e5c039 66 sizer.Add(b)
6999b0d8 67
b0e5c039 68 b = wxGenToggleButton(self, -1, "Toggle Button")
6999b0d8 69 EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
b0e5c039 70 sizer.Add(b)
6999b0d8 71
b0e5c039 72 b = wxGenBitmapToggleButton(self, -1, None)
6999b0d8 73 EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
96bfd053 74 bmp = images.getBulb1Bitmap()
54b96882
RD
75 mask = wxMaskColour(bmp, wxBLUE)
76 bmp.SetMask(mask)
6999b0d8 77 b.SetBitmapLabel(bmp)
96bfd053 78 bmp = images.getBulb2Bitmap()
54b96882
RD
79 mask = wxMaskColour(bmp, wxBLUE)
80 bmp.SetMask(mask)
6999b0d8 81 b.SetBitmapSelected(bmp)
1e4a197e 82 b.SetToggle(True)
78385733 83 b.SetBestSize()
b0e5c039 84 sizer.Add(b)
6999b0d8 85
b0e5c039 86 b = wxGenBitmapTextButton(self, -1, None, "Bitmapped Text", size = (200, 45))
ddcb3d83
RD
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)
1e4a197e 96 b.SetUseFocusIndicator(False)
ddcb3d83 97 b.SetBestSize()
b0e5c039
RD
98 sizer.Add(b)
99
100 border = wxBoxSizer(wxVERTICAL)
101 border.Add(sizer, 0, wxALL, 25)
102 self.SetSizer(border)
ddcb3d83 103
6999b0d8
RD
104
105 def OnButton(self, event):
106 self.log.WriteText("Button Clicked: %d\n" % event.GetId())
107
b0e5c039
RD
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
6999b0d8
RD
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
126def runTest(frame, nb, log):
127 win = TestPanel(nb, log)
128 return win
129
130
131#----------------------------------------------------------------------
132
133
134import wxPython.lib.buttons
135overview = wxPython.lib.buttons.__doc__
1e4a197e
RD
136
137
138
139if __name__ == '__main__':
140 import sys,os
141 import run
142 run.main(['', os.path.basename(sys.argv[0])])
143