]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ButtonPanel.py
Don't build the animate contrib
[wxWidgets.git] / wxPython / demo / ButtonPanel.py
1
2 import wx
3 import wx.lib.buttonpanel as bp
4 import images
5
6 #----------------------------------------------------------------------
7 class ButtonPanelDemo(wx.Frame):
8
9 def __init__(self, parent, id=wx.ID_ANY, title="ButtonPanel wxPython Demo", *args, **kw):
10
11 wx.Frame.__init__(self, parent, id, title, *args, **kw)
12
13 self.CreateMenuBar()
14
15 self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
16 self.statusbar.SetStatusWidths([-2, -1])
17 # statusbar fields
18 statusbar_fields = [("ButtonPanel wxPython Demo, Andrea Gavana @ 02 Oct 2006"),
19 ("Welcome To wxPython!")]
20
21 for i in range(len(statusbar_fields)):
22 self.statusbar.SetStatusText(statusbar_fields[i], i)
23
24 mainPanel = wx.Panel(self, -1)
25 self.logtext = wx.TextCtrl(mainPanel, -1, "", size=(-1, 250),
26 style=wx.TE_MULTILINE|wx.TE_READONLY|wx.TE_RICH2)
27
28 vSizer = wx.BoxSizer(wx.VERTICAL)
29 mainPanel.SetSizer(vSizer)
30
31 # Create the buttons and place them on the
32 # tab area of the main book
33 alignment = bp.BP_ALIGN_RIGHT
34 self.titleBar = bp.ButtonPanel(mainPanel, -1, "A Simple Test & Demo",
35 alignment=alignment)
36
37 self.btn1bmp = images.get_bp_btn1Bitmap()
38 self.btn2bmp = images.get_bp_btn2Bitmap()
39 self.btn3bmp = images.get_bp_btn3Bitmap()
40 self.btn4bmp = images.get_bp_btn4Bitmap()
41 self.CreateButtons(alignment)
42
43 # set the color the text is drawn with
44 self.titleBar.SetColor(bp.BP_TEXT_COLOR, wx.WHITE)
45
46 # These default to white and whatever is set in the system
47 # settings for the wx.SYS_COLOUR_ACTIVECAPTION. We'll use
48 # some specific settings to ensure a consistent look for the
49 # demo.
50 self.titleBar.SetColor(bp.BP_CAPTION_BORDER_COLOR, wx.Colour(120,23,224))
51 self.titleBar.SetColor(bp.BP_CAPTION_COLOR, wx.Colour(60,11,112))
52 self.titleBar.SetColor(bp.BP_CAPTION_GRADIENT_COLOR, wx.Colour(120,23,224))
53
54 vSizer.Add(self.titleBar, 0, wx.EXPAND)
55 vSizer.Add(self.logtext, 1, wx.EXPAND|wx.ALL, 5)
56 vSizer.Layout()
57
58 sizer = wx.BoxSizer()
59 sizer.Add(mainPanel, 1, wx.EXPAND)
60 self.SetSizer(sizer)
61 self.Fit()
62
63
64 def CreateMenuBar(self):
65 mb = wx.MenuBar()
66
67 file_menu = wx.Menu()
68 item = wx.MenuItem(file_menu, wx.ID_ANY, "&Quit")
69 file_menu.AppendItem(item)
70 self.Bind(wx.EVT_MENU, self.OnClose, item)
71
72 edit_menu = wx.Menu()
73 item = wx.MenuItem(edit_menu, wx.ID_ANY, "BP_ALIGN_RIGHT", kind=wx.ITEM_RADIO)
74 edit_menu.AppendItem(item)
75 self.Bind(wx.EVT_MENU, self.OnAlignRight, item)
76 item = wx.MenuItem(edit_menu, wx.ID_ANY, "BP_ALIGN_LEFT", kind=wx.ITEM_RADIO)
77 edit_menu.AppendItem(item)
78 self.Bind(wx.EVT_MENU, self.OnAlignLeft, item)
79
80 help_menu = wx.Menu()
81 item = wx.MenuItem(help_menu, wx.ID_ANY, "&About...")
82 help_menu.AppendItem(item)
83 self.Bind(wx.EVT_MENU, self.OnAbout, item)
84
85 mb.Append(file_menu, "&File")
86 mb.Append(edit_menu, "&Edit")
87 mb.Append(help_menu, "&Help")
88
89 self.SetMenuBar(mb)
90
91
92 def CreateButtons(self, alignment=bp.BP_ALIGN_RIGHT):
93 self.buttons = []
94 self.Freeze()
95
96 self.titleBar.RemoveAllButtons()
97
98 bmps = [ self.btn1bmp,
99 self.btn2bmp,
100 self.btn3bmp,
101 self.btn4bmp,
102 ]
103 if alignment == bp.BP_ALIGN_LEFT:
104 bmps.reverse()
105
106 for bmp in bmps:
107 btn = bp.ButtonInfo(wx.NewId(), bmp)
108 self.titleBar.AddButton(btn)
109 self.Bind(wx.EVT_BUTTON, self.OnButton, btn)
110 self.buttons.append(btn.GetId())
111
112 self.strings = ["First", "Second", "Third", "Fourth"]
113 if alignment == bp.BP_ALIGN_RIGHT:
114 self.strings.reverse()
115
116 self.titleBar.SetAlignment(alignment)
117 self.Thaw()
118
119
120 def OnAlignLeft(self, event):
121 self.CreateButtons(alignment=bp.BP_ALIGN_LEFT)
122 event.Skip()
123
124
125 def OnAlignRight(self, event):
126 self.CreateButtons(alignment=bp.BP_ALIGN_RIGHT)
127 event.Skip()
128
129
130 def OnButton(self, event):
131 btn = event.GetId()
132 indx = self.buttons.index(btn)
133 self.logtext.AppendText("Event Fired From " + self.strings[indx] + " Button\n")
134 event.Skip()
135
136
137 def OnClose(self, event):
138 self.Destroy()
139 event.Skip()
140
141
142 def OnAbout(self, event):
143
144 msg = "This Is The About Dialog Of The ButtonPanel Demo.\n\n" + \
145 "Author: Andrea Gavana @ 02 Oct 2006\n\n" + \
146 "Please Report Any Bug/Requests Of Improvements\n" + \
147 "To Me At The Following Adresses:\n\n" + \
148 "andrea.gavana@gmail.com\n" + "gavana@kpo.kz\n\n" + \
149 "Based On Eran C++ Implementation (wxWidgets Forum).\n\n" + \
150 "Welcome To wxPython " + wx.VERSION_STRING + "!!"
151
152 dlg = wx.MessageDialog(self, msg, "ButtonPanel wxPython Demo",
153 wx.OK | wx.ICON_INFORMATION)
154 dlg.ShowModal()
155 dlg.Destroy()
156
157 #----------------------------------------------------------------------
158
159 class TestPanel(wx.Panel):
160 def __init__(self, parent, log):
161 self.log = log
162 wx.Panel.__init__(self, parent, -1)
163
164 b = wx.Button(self, -1, " Test ButtonPanel ", (50,50))
165 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
166
167
168 def OnButton(self, evt):
169 self.win = ButtonPanelDemo(self)
170 self.win.Show(True)
171
172
173 #----------------------------------------------------------------------
174
175 def runTest(frame, nb, log):
176 win = TestPanel(nb, log)
177 return win
178
179 #----------------------------------------------------------------------
180
181
182
183 overview = bp.__doc__
184
185
186
187 if __name__ == '__main__':
188 import sys,os
189 import run
190 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
191
192
193
194