3 import wx
.lib
.buttonpanel
as bp
6 #----------------------------------------------------------------------
7 class ButtonPanelDemo(wx
.Frame
):
9 def __init__(self
, parent
, id=wx
.ID_ANY
, title
="ButtonPanel wxPython Demo", *args
, **kw
):
11 wx
.Frame
.__init
__(self
, parent
, id, title
, *args
, **kw
)
15 self
.statusbar
= self
.CreateStatusBar(2, wx
.ST_SIZEGRIP
)
16 self
.statusbar
.SetStatusWidths([-2, -1])
18 statusbar_fields
= [("ButtonPanel wxPython Demo, Andrea Gavana @ 02 Oct 2006"),
19 ("Welcome To wxPython!")]
21 for i
in range(len(statusbar_fields
)):
22 self
.statusbar
.SetStatusText(statusbar_fields
[i
], i
)
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
)
28 vSizer
= wx
.BoxSizer(wx
.VERTICAL
)
29 mainPanel
.SetSizer(vSizer
)
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",
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
)
43 # set the color the text is drawn with
44 self
.titleBar
.SetColor(bp
.BP_TEXT_COLOR
, wx
.WHITE
)
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
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))
54 vSizer
.Add(self
.titleBar
, 0, wx
.EXPAND
)
55 vSizer
.Add(self
.logtext
, 1, wx
.EXPAND|wx
.ALL
, 5)
59 sizer
.Add(mainPanel
, 1, wx
.EXPAND
)
64 def CreateMenuBar(self
):
68 item
= wx
.MenuItem(file_menu
, wx
.ID_ANY
, "&Quit")
69 file_menu
.AppendItem(item
)
70 self
.Bind(wx
.EVT_MENU
, self
.OnClose
, item
)
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
)
81 item
= wx
.MenuItem(help_menu
, wx
.ID_ANY
, "&About...")
82 help_menu
.AppendItem(item
)
83 self
.Bind(wx
.EVT_MENU
, self
.OnAbout
, item
)
85 mb
.Append(file_menu
, "&File")
86 mb
.Append(edit_menu
, "&Edit")
87 mb
.Append(help_menu
, "&Help")
92 def CreateButtons(self
, alignment
=bp
.BP_ALIGN_RIGHT
):
96 self
.titleBar
.RemoveAllButtons()
98 bmps
= [ self
.btn1bmp
,
103 if alignment
== bp
.BP_ALIGN_LEFT
:
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())
112 self
.strings
= ["First", "Second", "Third", "Fourth"]
113 if alignment
== bp
.BP_ALIGN_RIGHT
:
114 self
.strings
.reverse()
116 self
.titleBar
.SetAlignment(alignment
)
120 def OnAlignLeft(self
, event
):
121 self
.CreateButtons(alignment
=bp
.BP_ALIGN_LEFT
)
125 def OnAlignRight(self
, event
):
126 self
.CreateButtons(alignment
=bp
.BP_ALIGN_RIGHT
)
130 def OnButton(self
, event
):
132 indx
= self
.buttons
.index(btn
)
133 self
.logtext
.AppendText("Event Fired From " + self
.strings
[indx
] + " Button\n")
137 def OnClose(self
, event
):
142 def OnAbout(self
, event
):
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
+ "!!"
152 dlg
= wx
.MessageDialog(self
, msg
, "ButtonPanel wxPython Demo",
153 wx
.OK | wx
.ICON_INFORMATION
)
157 #----------------------------------------------------------------------
159 class TestPanel(wx
.Panel
):
160 def __init__(self
, parent
, log
):
162 wx
.Panel
.__init
__(self
, parent
, -1)
164 b
= wx
.Button(self
, -1, " Test ButtonPanel ", (50,50))
165 self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
)
168 def OnButton(self
, evt
):
169 self
.win
= ButtonPanelDemo(self
)
173 #----------------------------------------------------------------------
175 def runTest(frame
, nb
, log
):
176 win
= TestPanel(nb
, log
)
179 #----------------------------------------------------------------------
183 overview
= bp
.__doc
__
187 if __name__
== '__main__':
190 run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])