2 import wx
.lib
.buttonpanel 
as bp
 
   7 #---------------------------------------------------------------------- 
   9 ID_BackgroundColour 
= wx
.NewId() 
  10 ID_GradientFrom 
= wx
.NewId() 
  11 ID_GradientTo 
= wx
.NewId() 
  12 ID_BorderColour 
= wx
.NewId() 
  13 ID_CaptionColour 
= wx
.NewId() 
  14 ID_ButtonTextColour 
= wx
.NewId() 
  15 ID_SelectionBrush 
= wx
.NewId() 
  16 ID_SelectionPen 
= wx
.NewId() 
  17 ID_SeparatorColour 
= wx
.NewId() 
  20 #---------------------------------------------------------------------- 
  21 # Some icons for the demo 
  22 #---------------------------------------------------------------------- 
  23 def GetMondrianData(): 
  25 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00 \x08\x06\x00\ 
  26 \x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00qID\ 
  27 ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a\x82:\x16\ 
  28 o\xda\x84pB2\x1f\x81Fa\x8c\x9c\x08\x04Z{\xcf\xa72\xbcv\xfa\xc5\x08 \x80r\x80\ 
  29 \xfc\xa2\x0e\x1c\xe4\xba\xfaX\x1d\xd0\xde]S\x07\x02\xd8>\xe1wa-`\x9fQ\xe9\ 
  30 \x86\x01\x04\x10\x00\\(Dk\x1b-\x04\xdc\x1d\x07\x14\x98;\x0bS\x7f\x7f\xf9\x13\ 
  31 \x04\x10@\xf9X\xbe\x00\xc9 \x14K\xc1<={\x00\x00\x00\x00IEND\xaeB`\x82'  
  34 def GetMondrianBitmap(): 
  35     return wx
.BitmapFromImage(GetMondrianImage()) 
  38 def GetMondrianImage(): 
  40     stream 
= cStringIO
.StringIO(GetMondrianData()) 
  41     return wx
.ImageFromStream(stream
) 
  44 def GetMondrianIcon(): 
  46     icon
.CopyFromBitmap(GetMondrianBitmap()) 
  50 #---------------------------------------------------------------------- 
  52 class SettingsPanel(wx
.MiniFrame
): 
  54     def __init__(self
, parent
, id=wx
.ID_ANY
, title
="Settings Panel", pos
=wx
.DefaultPosition
, 
  56                  style
=wx
.SYSTEM_MENU | wx
.CAPTION | wx
.CLOSE_BOX | wx
.FRAME_NO_TASKBAR
 
  57                  | wx
.FRAME_FLOAT_ON_PARENT | wx
.CLIP_CHILDREN
): 
  59         wx
.MiniFrame
.__init
__(self
, parent
, id, title
, pos
, size
, style
) 
  61         self
.targetTitleBar 
= parent
.titleBar
 
  63         self
.panel 
= wx
.Panel(self
, -1) 
  65         self
.coloursizer_staticbox 
= wx
.StaticBox(self
.panel
, -1, "Colour Options") 
  66         self
.bottomsizer_staticbox 
= wx
.StaticBox(self
.panel
, -1, "Size Options") 
  67         self
.stylesizer_staticbox 
= wx
.StaticBox(self
.panel
, -1, "ButtonPanel Styles") 
  68         self
.defaultstyle 
= wx
.RadioButton(self
.panel
, -1, "Default Style", style
=wx
.RB_GROUP
) 
  69         self
.gradientstyle 
= wx
.RadioButton(self
.panel
, -1, "Gradient Style") 
  70         self
.verticalgradient 
= wx
.RadioButton(self
.panel
, -1, "Vertical Gradient", style
=wx
.RB_GROUP
) 
  71         self
.horizontalgradient 
= wx
.RadioButton(self
.panel
, -1, "Horizontal Gradient") 
  73         b 
= self
.CreateColorBitmap(wx
.BLACK
) 
  75         self
.bakbrush 
= wx
.BitmapButton(self
.panel
, ID_BackgroundColour
, b
, size
=wx
.Size(50,25)) 
  76         self
.gradientfrom 
= wx
.BitmapButton(self
.panel
, ID_GradientFrom
, b
, size
=wx
.Size(50,25)) 
  77         self
.gradientto 
= wx
.BitmapButton(self
.panel
, ID_GradientTo
, b
, size
=wx
.Size(50,25)) 
  78         self
.bordercolour 
= wx
.BitmapButton(self
.panel
, ID_BorderColour
, b
, size
=wx
.Size(50,25)) 
  79         self
.captioncolour 
= wx
.BitmapButton(self
.panel
, ID_CaptionColour
, b
, size
=wx
.Size(50,25)) 
  80         self
.textbuttoncolour 
= wx
.BitmapButton(self
.panel
, ID_ButtonTextColour
, b
, size
=wx
.Size(50,25)) 
  81         self
.selectionbrush 
= wx
.BitmapButton(self
.panel
, ID_SelectionBrush
, b
, size
=wx
.Size(50,25)) 
  82         self
.selectionpen 
= wx
.BitmapButton(self
.panel
, ID_SelectionPen
, b
, size
=wx
.Size(50,25)) 
  83         self
.separatorcolour 
= wx
.BitmapButton(self
.panel
, ID_SeparatorColour
, b
, size
=wx
.Size(50,25)) 
  85         self
.separatorspin 
= wx
.SpinCtrl(self
.panel
, -1, "7", min=3, max=20, 
  86                                          style
=wx
.SP_ARROW_KEYS
) 
  87         self
.marginspin 
= wx
.SpinCtrl(self
.panel
, -1, "6", min=3, max=20, 
  88                                       style
=wx
.SP_ARROW_KEYS
) 
  89         self
.paddingspin 
= wx
.SpinCtrl(self
.panel
, -1, "6", min=3, max=20, 
  90                                        style
=wx
.SP_ARROW_KEYS
) 
  91         self
.borderspin 
= wx
.SpinCtrl(self
.panel
, -1, "3", min=3, max=7, 
  92                                       style
=wx
.SP_ARROW_KEYS
) 
  94         self
.__set
_properties
() 
  97         self
.Bind(wx
.EVT_RADIOBUTTON
, self
.OnDefaultStyle
, self
.defaultstyle
) 
  98         self
.Bind(wx
.EVT_RADIOBUTTON
, self
.OnGradientStyle
, self
.gradientstyle
) 
  99         self
.Bind(wx
.EVT_RADIOBUTTON
, self
.OnVerticalGradient
, self
.verticalgradient
) 
 100         self
.Bind(wx
.EVT_RADIOBUTTON
, self
.OnHorizontalGradient
, self
.horizontalgradient
) 
 101         self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_BackgroundColour
) 
 102         self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_GradientFrom
) 
 103         self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_GradientTo
) 
 104         self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_BorderColour
) 
 105         self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_CaptionColour
) 
 106         self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_ButtonTextColour
) 
 107         self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_SelectionBrush
) 
 108         self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_SelectionPen
) 
 109         self
.Bind(wx
.EVT_BUTTON
, self
.OnSetColour
, id=ID_SeparatorColour
) 
 111         self
.Bind(wx
.EVT_SPINCTRL
, self
.OnSeparator
, self
.separatorspin
) 
 112         self
.Bind(wx
.EVT_SPINCTRL
, self
.OnMargins
, self
.marginspin
) 
 113         self
.Bind(wx
.EVT_SPINCTRL
, self
.OnPadding
, self
.paddingspin
) 
 114         self
.Bind(wx
.EVT_SPINCTRL
, self
.OnBorder
, self
.borderspin
) 
 116         self
.Bind(wx
.EVT_CLOSE
, self
.OnClose
)         
 119     def __set_properties(self
): 
 121         self
.defaultstyle
.SetFont(wx
.Font(8, wx
.DEFAULT
, wx
.NORMAL
, wx
.BOLD
, 0, "")) 
 122         self
.defaultstyle
.SetValue(1) 
 123         self
.gradientstyle
.SetFont(wx
.Font(8, wx
.DEFAULT
, wx
.NORMAL
, wx
.BOLD
, 0, "")) 
 124         self
.verticalgradient
.SetValue(1) 
 126         if self
.targetTitleBar
.GetStyle() & bp
.BP_DEFAULT_STYLE
: 
 127             self
.verticalgradient
.Enable(False) 
 128             self
.horizontalgradient
.Enable(False) 
 129             self
.defaultstyle
.SetValue(1) 
 131             self
.gradientstyle
.SetValue(1) 
 133         self
.borderspin
.SetValue(self
.targetTitleBar
.GetBPArt().GetMetric(bp
.BP_BORDER_SIZE
)) 
 134         self
.separatorspin
.SetValue(self
.targetTitleBar
.GetBPArt().GetMetric(bp
.BP_SEPARATOR_SIZE
)) 
 135         self
.marginspin
.SetValue(self
.targetTitleBar
.GetBPArt().GetMetric(bp
.BP_MARGINS_SIZE
).x
) 
 136         self
.paddingspin
.SetValue(self
.targetTitleBar
.GetBPArt().GetMetric(bp
.BP_PADDING_SIZE
).x
) 
 141     def __do_layout(self
): 
 143         mainsizer 
= wx
.BoxSizer(wx
.VERTICAL
) 
 144         buttonsizer 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 145         bottomsizer 
= wx
.StaticBoxSizer(self
.bottomsizer_staticbox
, wx
.VERTICAL
) 
 146         sizer_13 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 147         sizer_12 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 148         sizer_11 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 149         sizer_10 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 150         coloursizer 
= wx
.StaticBoxSizer(self
.coloursizer_staticbox
, wx
.HORIZONTAL
) 
 151         rightsizer 
= wx
.BoxSizer(wx
.VERTICAL
) 
 152         sizer_9 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 153         sizer_8 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 154         sizer_7 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 155         sizer_6 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 156         leftsizer 
= wx
.BoxSizer(wx
.VERTICAL
) 
 157         sizer_5 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 158         sizer_4 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 159         sizer_3 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 160         sizer_2 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 161         sizer_1 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 162         stylesizer 
= wx
.StaticBoxSizer(self
.stylesizer_staticbox
, wx
.VERTICAL
) 
 163         tophsizer 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 164         tophsizer2 
= wx
.BoxSizer(wx
.VERTICAL
) 
 166         stylesizer
.Add(self
.defaultstyle
, 0, wx
.ALL|wx
.EXPAND|wx
.ADJUST_MINSIZE
, 5) 
 168         tophsizer
.Add(self
.gradientstyle
, 0, wx
.LEFT|wx
.RIGHT|wx
.EXPAND|
 
 169                       wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5) 
 171         tophsizer2
.Add(self
.verticalgradient
, 0, wx
.BOTTOM|wx
.ADJUST_MINSIZE
, 3) 
 172         tophsizer2
.Add(self
.horizontalgradient
, 0, wx
.ADJUST_MINSIZE
, 0) 
 174         tophsizer
.Add(tophsizer2
, 1, wx
.LEFT|wx
.EXPAND|wx
.ALIGN_CENTER_VERTICAL
, 10) 
 176         stylesizer
.Add(tophsizer
, 1, wx
.EXPAND
, 0) 
 178         mainsizer
.Add(stylesizer
, 0, wx
.ALL|wx
.EXPAND
, 5) 
 180         label_1 
= wx
.StaticText(self
.panel
, -1, "Background Brush Colour:") 
 181         sizer_1
.Add(label_1
, 0, wx
.ALL|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5) 
 182         sizer_1
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0) 
 183         sizer_1
.Add(self
.bakbrush
, 0, wx
.ADJUST_MINSIZE
, 0) 
 185         leftsizer
.Add(sizer_1
, 1, wx
.EXPAND
, 0) 
 187         label_2 
= wx
.StaticText(self
.panel
, -1, "Gradient Colour From:") 
 188         sizer_2
.Add(label_2
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5) 
 189         sizer_2
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0) 
 190         sizer_2
.Add(self
.gradientfrom
, 0, wx
.ADJUST_MINSIZE
, 0) 
 192         leftsizer
.Add(sizer_2
, 1, wx
.EXPAND
, 0) 
 194         label_3 
= wx
.StaticText(self
.panel
, -1, "Gradient Colour To:") 
 195         sizer_3
.Add(label_3
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5) 
 196         sizer_3
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0) 
 197         sizer_3
.Add(self
.gradientto
, 0, wx
.ADJUST_MINSIZE
, 0) 
 199         leftsizer
.Add(sizer_3
, 1, wx
.EXPAND
, 0) 
 201         label_4 
= wx
.StaticText(self
.panel
, -1, "Border Colour:") 
 202         sizer_4
.Add(label_4
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5) 
 203         sizer_4
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0) 
 204         sizer_4
.Add(self
.bordercolour
, 0, wx
.ADJUST_MINSIZE
, 0) 
 206         leftsizer
.Add(sizer_4
, 1, wx
.EXPAND
, 0) 
 208         label_5 
= wx
.StaticText(self
.panel
, -1, "Main Caption Colour:") 
 209         sizer_5
.Add(label_5
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5) 
 210         sizer_5
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0) 
 211         sizer_5
.Add(self
.captioncolour
, 0, wx
.ADJUST_MINSIZE
, 0) 
 213         leftsizer
.Add(sizer_5
, 1, wx
.EXPAND
, 0) 
 215         coloursizer
.Add(leftsizer
, 0, wx
.ALL|wx
.ALIGN_CENTER_VERTICAL
, 5) 
 216         coloursizer
.Add((20, 20), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0) 
 218         label_6 
= wx
.StaticText(self
.panel
, -1, "Text Button Colour:") 
 219         sizer_6
.Add(label_6
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5) 
 220         sizer_6
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0) 
 221         sizer_6
.Add(self
.textbuttoncolour
, 0, wx
.ADJUST_MINSIZE
, 0) 
 223         rightsizer
.Add(sizer_6
, 1, wx
.EXPAND
, 0) 
 225         label_7 
= wx
.StaticText(self
.panel
, -1, "Selection Brush Colour:") 
 226         sizer_7
.Add(label_7
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5) 
 227         sizer_7
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0) 
 228         sizer_7
.Add(self
.selectionbrush
, 0, wx
.ADJUST_MINSIZE
, 0) 
 230         rightsizer
.Add(sizer_7
, 1, wx
.EXPAND
, 0) 
 232         label_8 
= wx
.StaticText(self
.panel
, -1, "Selection Pen Colour:") 
 233         sizer_8
.Add(label_8
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5) 
 234         sizer_8
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0) 
 235         sizer_8
.Add(self
.selectionpen
, 0, wx
.ADJUST_MINSIZE
, 0) 
 237         rightsizer
.Add(sizer_8
, 1, wx
.EXPAND
, 0) 
 239         label_9 
= wx
.StaticText(self
.panel
, -1, "Separator Colour:") 
 240         sizer_9
.Add(label_9
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5) 
 241         sizer_9
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0) 
 242         sizer_9
.Add(self
.separatorcolour
, 0, wx
.ADJUST_MINSIZE
, 0) 
 244         rightsizer
.Add(sizer_9
, 1, wx
.EXPAND
, 0) 
 246         coloursizer
.Add(rightsizer
, 0, wx
.ALL|wx
.ALIGN_CENTER_VERTICAL
, 5) 
 248         mainsizer
.Add(coloursizer
, 0, wx
.ALL|wx
.EXPAND
, 5) 
 250         label_10 
= wx
.StaticText(self
.panel
, -1, "Separator Size:") 
 251         sizer_10
.Add(label_10
, 0, wx
.ALL|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5) 
 252         sizer_10
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0) 
 253         sizer_10
.Add(self
.separatorspin
, 0, wx
.ALL|wx
.ADJUST_MINSIZE
, 5) 
 255         bottomsizer
.Add(sizer_10
, 1, wx
.EXPAND
, 0) 
 257         label_11 
= wx
.StaticText(self
.panel
, -1, "Margins Size:") 
 258         sizer_11
.Add(label_11
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5) 
 259         sizer_11
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0) 
 260         sizer_11
.Add(self
.marginspin
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ADJUST_MINSIZE
, 5) 
 262         bottomsizer
.Add(sizer_11
, 1, wx
.EXPAND
, 0) 
 264         label_12 
= wx
.StaticText(self
.panel
, -1, "Padding Size:") 
 265         sizer_12
.Add(label_12
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5) 
 266         sizer_12
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0) 
 267         sizer_12
.Add(self
.paddingspin
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ADJUST_MINSIZE
, 5) 
 269         bottomsizer
.Add(sizer_12
, 1, wx
.EXPAND
, 0) 
 271         label_13 
= wx
.StaticText(self
.panel
, -1, "Border Size:") 
 272         sizer_13
.Add(label_13
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ALIGN_CENTER_VERTICAL|wx
.ADJUST_MINSIZE
, 5) 
 273         sizer_13
.Add((0, 0), 1, wx
.EXPAND|wx
.ADJUST_MINSIZE
, 0) 
 274         sizer_13
.Add(self
.borderspin
, 0, wx
.LEFT|wx
.RIGHT|wx
.BOTTOM|wx
.ADJUST_MINSIZE
, 5) 
 276         bottomsizer
.Add(sizer_13
, 1, wx
.EXPAND
, 0) 
 278         mainsizer
.Add(bottomsizer
, 0, wx
.ALL|wx
.EXPAND
, 5) 
 280         self
.panel
.SetSizer(mainsizer
) 
 281         sizer 
= wx
.BoxSizer() 
 282         sizer
.Add(self
.panel
, 1, wx
.EXPAND
) 
 287     def CreateColorBitmap(self
, c
): 
 289         image 
= wx
.EmptyImage(25, 14) 
 294                 if x 
== 0 or x 
== 24 or y 
== 0 or y 
== 13: 
 297                 image
.SetRGB(x
, y
, pixcol
.Red(), pixcol
.Green(), pixcol
.Blue()) 
 299         return image
.ConvertToBitmap() 
 302     def UpdateColors(self
): 
 304         bk 
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_BACKGROUND_COLOR
) 
 305         self
.bakbrush
.SetBitmapLabel(self
.CreateColorBitmap(bk
)) 
 307         capfrom 
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_GRADIENT_COLOR_FROM
) 
 308         self
.gradientfrom
.SetBitmapLabel(self
.CreateColorBitmap(capfrom
)) 
 310         capto 
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_GRADIENT_COLOR_TO
) 
 311         self
.gradientto
.SetBitmapLabel(self
.CreateColorBitmap(capto
)) 
 313         captxt 
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_TEXT_COLOR
) 
 314         self
.captioncolour
.SetBitmapLabel(self
.CreateColorBitmap(captxt
)) 
 316         bor 
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_BORDER_COLOR
) 
 317         self
.bordercolour
.SetBitmapLabel(self
.CreateColorBitmap(bor
)) 
 319         btntext 
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_BUTTONTEXT_COLOR
) 
 320         self
.textbuttoncolour
.SetBitmapLabel(self
.CreateColorBitmap(btntext
)) 
 322         selb 
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_SELECTION_BRUSH_COLOR
) 
 323         self
.selectionbrush
.SetBitmapLabel(self
.CreateColorBitmap(selb
)) 
 325         selp 
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_SELECTION_PEN_COLOR
) 
 326         self
.selectionpen
.SetBitmapLabel(self
.CreateColorBitmap(selp
)) 
 328         sepc 
= self
.targetTitleBar
.GetBPArt().GetColor(bp
.BP_SEPARATOR_COLOR
) 
 329         self
.separatorcolour
.SetBitmapLabel(self
.CreateColorBitmap(sepc
)) 
 332     def OnDefaultStyle(self
, event
): 
 334         self
.verticalgradient
.Enable(False) 
 335         self
.horizontalgradient
.Enable(False) 
 336         self
.targetTitleBar
.SetStyle(bp
.BP_DEFAULT_STYLE
) 
 338         self
.targetTitleBar
.Refresh() 
 343     def OnGradientStyle(self
, event
):  
 345         self
.verticalgradient
.Enable(True) 
 346         self
.horizontalgradient
.Enable(True) 
 347         self
.targetTitleBar
.SetStyle(bp
.BP_USE_GRADIENT
) 
 348         self
.targetTitleBar
.Refresh() 
 353     def OnVerticalGradient(self
, event
): 
 355         self
.targetTitleBar
.GetBPArt().SetGradientType(bp
.BP_GRADIENT_VERTICAL
) 
 356         self
.targetTitleBar
.SetStyle(bp
.BP_USE_GRADIENT
) 
 357         self
.targetTitleBar
.Refresh() 
 362     def OnHorizontalGradient(self
, event
): 
 364         self
.targetTitleBar
.GetBPArt().SetGradientType(bp
.BP_GRADIENT_HORIZONTAL
) 
 365         self
.targetTitleBar
.SetStyle(bp
.BP_USE_GRADIENT
) 
 366         self
.targetTitleBar
.Refresh() 
 371     def OnSetColour(self
, event
): 
 373         dlg 
= wx
.ColourDialog(self
.parent
) 
 375         dlg
.SetTitle("Color Picker") 
 377         if dlg
.ShowModal() != wx
.ID_OK
: 
 381         if event
.GetId() == ID_BackgroundColour
: 
 382             var 
= bp
.BP_BACKGROUND_COLOR
 
 383         elif event
.GetId() == ID_GradientFrom
: 
 384             var 
= bp
.BP_GRADIENT_COLOR_FROM
 
 385         elif event
.GetId() == ID_GradientTo
: 
 386             var 
= bp
.BP_GRADIENT_COLOR_TO
 
 387         elif event
.GetId() == ID_BorderColour
: 
 388             var 
= bp
.BP_BORDER_COLOR
 
 389         elif event
.GetId() == ID_CaptionColour
: 
 390             var 
= bp
.BP_TEXT_COLOR
 
 391         elif event
.GetId() == ID_ButtonTextColour
: 
 392             var 
= bp
.BP_BUTTONTEXT_COLOR
 
 393         elif event
.GetId() == ID_SelectionBrush
: 
 394             var 
= bp
.BP_SELECTION_BRUSH_COLOR
 
 395         elif event
.GetId() == ID_SelectionPen
: 
 396             var 
= bp
.BP_SELECTION_PEN_COLOR
 
 397         elif event
.GetId() == ID_SeparatorColour
: 
 398             var 
= bp
.BP_SEPARATOR_COLOR
 
 402         self
.targetTitleBar
.GetBPArt().SetColor(var
, dlg
.GetColourData().GetColour()) 
 403         self
.targetTitleBar
.Refresh() 
 406         self
.parent
.useredited 
= True 
 409     def OnSeparator(self
, event
): 
 411         self
.targetTitleBar
.GetBPArt().SetMetric(bp
.BP_SEPARATOR_SIZE
, 
 414         self
.targetTitleBar
.DoLayout() 
 415         self
.parent
.mainPanel
.Layout() 
 416         self
.parent
.useredited 
= True 
 421     def OnMargins(self
, event
): 
 423         self
.targetTitleBar
.GetBPArt().SetMetric(bp
.BP_MARGINS_SIZE
, 
 424                                                  wx
.Size(event
.GetInt(), event
.GetInt())) 
 426         self
.targetTitleBar
.DoLayout() 
 427         self
.parent
.mainPanel
.Layout() 
 429         self
.parent
.useredited 
= True 
 434     def OnPadding(self
, event
): 
 436         self
.targetTitleBar
.GetBPArt().SetMetric(bp
.BP_PADDING_SIZE
, 
 437                                                  wx
.Size(event
.GetInt(), event
.GetInt())) 
 439         self
.targetTitleBar
.DoLayout() 
 440         self
.parent
.mainPanel
.Layout() 
 441         self
.parent
.useredited 
= True 
 446     def OnBorder(self
, event
): 
 448         self
.targetTitleBar
.GetBPArt().SetMetric(bp
.BP_BORDER_SIZE
, 
 451         self
.targetTitleBar
.DoLayout() 
 452         self
.parent
.mainPanel
.Layout() 
 454         self
.parent
.useredited 
= True 
 459     def OnClose(self
, event
): 
 461         self
.parent
.hassettingpanel 
= False 
 465 #---------------------------------------------------------------------- 
 467 class ButtonPanelDemo(wx
.Frame
): 
 469     def __init__(self
, parent
, id=wx
.ID_ANY
, title
="ButtonPanel wxPython Demo ;-)", 
 470                  pos
=wx
.DefaultPosition
, size
=(640, 400), style
=wx
.DEFAULT_FRAME_STYLE
): 
 472         wx
.Frame
.__init
__(self
, parent
, id, title
, pos
, size
, style
) 
 474         self
.useredited 
= False 
 475         self
.hassettingpanel 
= False 
 477         self
.SetIcon(GetMondrianIcon()) 
 480         self
.statusbar 
= self
.CreateStatusBar(2, wx
.ST_SIZEGRIP
) 
 481         self
.statusbar
.SetStatusWidths([-2, -1]) 
 483         statusbar_fields 
= [("ButtonPanel wxPython Demo, Andrea Gavana @ 02 Oct 2006"), 
 484                             ("Welcome To wxPython!")] 
 486         for i 
in range(len(statusbar_fields
)): 
 487             self
.statusbar
.SetStatusText(statusbar_fields
[i
], i
) 
 489         self
.mainPanel 
= wx
.Panel(self
, -1) 
 490         self
.logtext 
= wx
.TextCtrl(self
.mainPanel
, -1, "", style
=wx
.TE_MULTILINE|wx
.TE_READONLY
) 
 492         vSizer 
= wx
.BoxSizer(wx
.VERTICAL
)  
 493         self
.mainPanel
.SetSizer(vSizer
)  
 495         self
.alignments 
= [bp
.BP_ALIGN_LEFT
, bp
.BP_ALIGN_RIGHT
, bp
.BP_ALIGN_TOP
, bp
.BP_ALIGN_BOTTOM
] 
 497         self
.alignment 
= bp
.BP_ALIGN_LEFT
 
 498         self
.style 
= bp
.BP_USE_GRADIENT
 
 500         self
.titleBar 
= bp
.ButtonPanel(self
.mainPanel
, -1, "A Simple Test & Demo", 
 501                                        style
=self
.style
, alignment
=self
.alignment
) 
 504         self
.pngs 
= [ (images
.get_bp_btn1Bitmap(), 'label1'), 
 505                       (images
.get_bp_btn2Bitmap(), 'label2'), 
 506                       (images
.get_bp_btn3Bitmap(), 'label3'), 
 507                       (images
.get_bp_btn4Bitmap(), 'label4'), 
 513     def CreateMenuBar(self
): 
 517         file_menu 
= wx
.Menu() 
 519         item 
= wx
.MenuItem(file_menu
, wx
.ID_ANY
, "&Quit") 
 520         file_menu
.AppendItem(item
) 
 521         self
.Bind(wx
.EVT_MENU
, self
.OnClose
, item
) 
 523         edit_menu 
= wx
.Menu() 
 525         item 
= wx
.MenuItem(edit_menu
, wx
.ID_ANY
, "Set Bar Text") 
 526         edit_menu
.AppendItem(item
) 
 527         self
.Bind(wx
.EVT_MENU
, self
.OnSetBarText
, item
) 
 529         edit_menu
.AppendSeparator()         
 533         item 
= wx
.MenuItem(submenu
, wx
.ID_ANY
, "BP_ALIGN_LEFT", kind
=wx
.ITEM_RADIO
) 
 534         submenu
.AppendItem(item
) 
 536         self
.Bind(wx
.EVT_MENU
, self
.OnAlignment
, item
) 
 538         item 
= wx
.MenuItem(submenu
, wx
.ID_ANY
, "BP_ALIGN_RIGHT", kind
=wx
.ITEM_RADIO
) 
 539         submenu
.AppendItem(item
) 
 540         self
.Bind(wx
.EVT_MENU
, self
.OnAlignment
, item
) 
 542         item 
= wx
.MenuItem(submenu
, wx
.ID_ANY
, "BP_ALIGN_TOP", kind
=wx
.ITEM_RADIO
) 
 543         submenu
.AppendItem(item
) 
 544         self
.Bind(wx
.EVT_MENU
, self
.OnAlignment
, item
) 
 546         item 
= wx
.MenuItem(submenu
, wx
.ID_ANY
, "BP_ALIGN_BOTTOM", kind
=wx
.ITEM_RADIO
) 
 547         submenu
.AppendItem(item
) 
 548         self
.Bind(wx
.EVT_MENU
, self
.OnAlignment
, item
) 
 550         edit_menu
.AppendMenu(wx
.ID_ANY
, "&Alignment", submenu
) 
 554         item 
= wx
.MenuItem(submenu
, wx
.ID_ANY
, "Default Style", kind
=wx
.ITEM_RADIO
) 
 555         submenu
.AppendItem(item
) 
 556         self
.Bind(wx
.EVT_MENU
, self
.OnDefaultStyle
, item
) 
 558         item 
= wx
.MenuItem(submenu
, wx
.ID_ANY
, "Gradient Style", kind
=wx
.ITEM_RADIO
) 
 559         submenu
.AppendItem(item
) 
 561         self
.Bind(wx
.EVT_MENU
, self
.OnGradientStyle
, item
) 
 563         edit_menu
.AppendMenu(wx
.ID_ANY
, "&Styles", submenu
) 
 565         edit_menu
.AppendSeparator() 
 567         item 
= wx
.MenuItem(submenu
, wx
.ID_ANY
, "Settings Panel") 
 568         edit_menu
.AppendItem(item
) 
 569         self
.Bind(wx
.EVT_MENU
, self
.OnSettingsPanel
, item
) 
 571         demo_menu 
= wx
.Menu() 
 573         item 
= wx
.MenuItem(demo_menu
, wx
.ID_ANY
, "Default Demo", kind
=wx
.ITEM_RADIO
) 
 574         demo_menu
.AppendItem(item
) 
 575         self
.Bind(wx
.EVT_MENU
, self
.OnDefaultDemo
, item
) 
 577         item 
= wx
.MenuItem(demo_menu
, wx
.ID_ANY
, "Button Only Demo", kind
=wx
.ITEM_RADIO
) 
 578         demo_menu
.AppendItem(item
) 
 579         self
.Bind(wx
.EVT_MENU
, self
.OnButtonOnly
, item
) 
 581         help_menu 
= wx
.Menu() 
 583         item 
= wx
.MenuItem(help_menu
, wx
.ID_ANY
, "&About...") 
 584         help_menu
.AppendItem(item
) 
 585         self
.Bind(wx
.EVT_MENU
, self
.OnAbout
, item
) 
 587         mb
.Append(file_menu
, "&File") 
 588         mb
.Append(edit_menu
, "&Edit") 
 589         mb
.Append(demo_menu
, "&Demo") 
 590         mb
.Append(help_menu
, "&Help") 
 595     def CreateButtons(self
): 
 597         # Here we (re)create the buttons for the default startup demo 
 601             sizer 
= self
.mainPanel
.GetSizer() 
 604             wx
.CallAfter(self
.titleBar
.Destroy
) 
 605             self
.titleBar 
= bp
.ButtonPanel(self
.mainPanel
, -1, "A Simple Test & Demo", 
 606                                            style
=self
.style
, alignment
=self
.alignment
) 
 611         for count
, png 
in enumerate(self
.pngs
): 
 613             shortHelp 
= "Button %d"%(count
+1) 
 616                 # First 2 buttons are togglebuttons 
 618                 longHelp 
= "ButtonPanel Toggle Button No %d"%(count
+1) 
 620                 kind 
= wx
.ITEM_NORMAL
 
 621                 longHelp 
= "Simple Button without label No %d"%(count
+1)                 
 623             btn 
= bp
.ButtonInfo(self
.titleBar
, wx
.NewId(), 
 625                                 shortHelp
=shortHelp
, longHelp
=longHelp
) 
 627             self
.titleBar
.AddButton(btn
) 
 628             self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, id=btn
.GetId()) 
 630             self
.indices
.append(btn
.GetId()) 
 633                 # First 2 buttons have also a text 
 637                 # Append a separator after the second button 
 638                 self
.titleBar
.AddSeparator() 
 641                 # Add a wx.TextCtrl to ButtonPanel 
 642                 self
.titleBar
.AddControl(wx
.TextCtrl(self
.titleBar
, -1, "Hello wxPython!")) 
 643                 btn
.SetTextAlignment(bp
.BP_BUTTONTEXT_ALIGN_RIGHT
) 
 645         # Add a wx.Choice to ButtonPanel                         
 646         self
.titleBar
.AddControl(wx
.Choice(self
.titleBar
, -1, 
 647                                            choices
=["Hello", "From", "wxPython!"])) 
 649         self
.strings 
= ["First", "Second", "Third", "Fourth"] 
 653         self
.titleBar
.DoLayout() 
 658     def ButtonOnly(self
): 
 660         # Here we (re)create the buttons for the button-only demo 
 664             sizer 
= self
.mainPanel
.GetSizer() 
 667             wx
.CallAfter(self
.titleBar
.Destroy
) 
 668             self
.titleBar 
= bp
.ButtonPanel(self
.mainPanel
, -1, "A Simple Test & Demo", 
 669                                            style
=self
.style
, alignment
=self
.alignment
) 
 672         # Buttons are created completely random, with random images, toggle behavior 
 677         for count 
in xrange(8): 
 679             itemImage 
= random
.randint(0, 3) 
 680             hasText 
= random
.randint(0, 1) 
 681             itemKind 
= random
.randint(0, 1) 
 683             btn 
= bp
.ButtonInfo(self
.titleBar
, wx
.NewId(), self
.pngs
[itemImage
][0], 
 687                 btn
.SetText(self
.pngs
[itemImage
][1]) 
 688                 rightText 
= random
.randint(0, 1) 
 690                     btn
.SetTextAlignment(bp
.BP_BUTTONTEXT_ALIGN_RIGHT
) 
 692             self
.titleBar
.AddButton(btn
) 
 693             self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, id=btn
.GetId()) 
 695             self
.indices
.append(btn
.GetId()) 
 697             if count 
in [0, 3, 5]: 
 698                 self
.titleBar
.AddSeparator() 
 700         self
.strings 
= ["First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth"] 
 704         self
.titleBar
.DoLayout() 
 707     def ChangeLayout(self
): 
 709         # Change the layout after a switch in ButtonPanel alignment 
 712         if self
.alignment 
in [bp
.BP_ALIGN_LEFT
, bp
.BP_ALIGN_RIGHT
]: 
 713             vSizer 
= wx
.BoxSizer(wx
.VERTICAL
) 
 715             vSizer 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 717         self
.mainPanel
.SetSizer(vSizer
)  
 719         vSizer
.Add(self
.titleBar
, 0, wx
.EXPAND
) 
 721         vSizer
.Add(self
.logtext
, 1, wx
.EXPAND|wx
.ALL
, 5) 
 724         self
.mainPanel
.Layout() 
 728     def SetProperties(self
): 
 730         # No resetting if the user is using the Settings Panel 
 734         # Sets the colours for the two demos: called only if the user didn't 
 735         # modify the colours and sizes using the Settings Panel 
 736         bpArt 
= self
.titleBar
.GetBPArt() 
 738         if self
.style 
& bp
.BP_USE_GRADIENT
: 
 739             # set the color the text is drawn with 
 740             bpArt
.SetColor(bp
.BP_TEXT_COLOR
, wx
.WHITE
) 
 742             # These default to white and whatever is set in the system 
 743             # settings for the wx.SYS_COLOUR_ACTIVECAPTION.  We'll use 
 744             # some specific settings to ensure a consistent look for the 
 746             bpArt
.SetColor(bp
.BP_BORDER_COLOR
, wx
.Colour(120,23,224)) 
 747             bpArt
.SetColor(bp
.BP_GRADIENT_COLOR_FROM
, wx
.Colour(60,11,112)) 
 748             bpArt
.SetColor(bp
.BP_GRADIENT_COLOR_TO
, wx
.Colour(120,23,224)) 
 749             bpArt
.SetColor(bp
.BP_BUTTONTEXT_COLOR
, wx
.Colour(70,143,255)) 
 750             bpArt
.SetColor(bp
.BP_SEPARATOR_COLOR
, 
 751                            bp
.BrightenColour(wx
.Colour(60, 11, 112), 0.85)) 
 752             bpArt
.SetColor(bp
.BP_SELECTION_BRUSH_COLOR
, wx
.Color(225, 225, 255)) 
 753             bpArt
.SetColor(bp
.BP_SELECTION_PEN_COLOR
, wx
.SystemSettings_GetColour(wx
.SYS_COLOUR_ACTIVECAPTION
)) 
 757             background 
= self
.titleBar
.GetBackgroundColour()             
 758             bpArt
.SetColor(bp
.BP_TEXT_COLOR
, wx
.BLUE
) 
 759             bpArt
.SetColor(bp
.BP_BORDER_COLOR
, 
 760                            bp
.BrightenColour(background
, 0.85)) 
 761             bpArt
.SetColor(bp
.BP_SEPARATOR_COLOR
, 
 762                            bp
.BrightenColour(background
, 0.85)) 
 763             bpArt
.SetColor(bp
.BP_BUTTONTEXT_COLOR
, wx
.BLACK
) 
 764             bpArt
.SetColor(bp
.BP_SELECTION_BRUSH_COLOR
, wx
.Colour(242, 242, 235)) 
 765             bpArt
.SetColor(bp
.BP_SELECTION_PEN_COLOR
, wx
.Colour(206, 206, 195)) 
 767         self
.titleBar
.SetStyle(self
.style
) 
 770     def OnAlignment(self
, event
): 
 772         # Here we change the alignment property of ButtonPanel 
 773         current 
= event
.GetId() 
 774         edit_menu 
= self
.GetMenuBar().FindMenu("Edit") 
 775         edit_menu 
= self
.GetMenuBar().GetMenu(edit_menu
) 
 776         menu 
= edit_menu
.FindItem("BP_ALIGN_LEFT") 
 778         alignment 
= self
.alignments
[current 
- menu
] 
 779         self
.alignment 
= alignment
 
 782         self
.titleBar
.SetAlignment(alignment
) 
 783         self
.mainPanel
.Layout() 
 788     def OnDefaultStyle(self
, event
): 
 790         # Restore the ButtonPanel default style (no gradient) 
 791         self
.style 
= bp
.BP_DEFAULT_STYLE
 
 797     def OnGradientStyle(self
, event
): 
 799         # Use gradients to paint ButtonPanel background 
 800         self
.style 
= bp
.BP_USE_GRADIENT
 
 806     def OnDefaultDemo(self
, event
): 
 808         # Reload the default startup demo 
 813     def OnButtonOnly(self
, event
): 
 815         # Reload the button-only demo 
 820     def OnButton(self
, event
): 
 823         indx 
= self
.indices
.index(btn
) 
 825         self
.logtext
.AppendText("Event Fired From " + self
.strings
[indx
] + " Button\n") 
 829     def OnSetBarText(self
, event
): 
 831         dlg 
= wx
.TextEntryDialog(self
, "Enter The Text You Wish To Display On The Bar (Clear If No Text):", 
 832                                  "Set Text", self
.titleBar
.GetBarText()) 
 834         if dlg
.ShowModal() == wx
.ID_OK
: 
 837             self
.titleBar
.SetBarText(val
) 
 838             self
.titleBar
.DoLayout() 
 839             self
.mainPanel
.Layout() 
 842     def OnSettingsPanel(self
, event
): 
 844         if self
.hassettingpanel
: 
 845             self
.settingspanel
.Raise() 
 848         self
.settingspanel 
= SettingsPanel(self
, -1) 
 849         self
.settingspanel
.Show() 
 850         self
.hassettingpanel 
= True 
 853     def OnClose(self
, event
): 
 859     def OnAbout(self
, event
): 
 861         msg 
= "This Is The About Dialog Of The ButtonPanel Demo.\n\n" + \
 
 862               "Author: Andrea Gavana @ 02 Oct 2006\n\n" + \
 
 863               "Please Report Any Bug/Requests Of Improvements\n" + \
 
 864               "To Me At The Following Adresses:\n\n" + \
 
 865               "andrea.gavana@gmail.com\n" + "gavana@kpo.kz\n\n" + \
 
 866               "Based On Eran C++ Implementation (wxWidgets Forum).\n\n" + \
 
 867               "Welcome To wxPython " + wx
.VERSION_STRING 
+ "!!" 
 869         dlg 
= wx
.MessageDialog(self
, msg
, "ButtonPanel wxPython Demo", 
 870                                wx
.OK | wx
.ICON_INFORMATION
) 
 875 #---------------------------------------------------------------------- 
 877 class TestPanel(wx
.Panel
): 
 878     def __init__(self
, parent
, log
): 
 880         wx
.Panel
.__init
__(self
, parent
, -1) 
 882         b 
= wx
.Button(self
, -1, " Test ButtonPanel ", (50,50)) 
 883         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
 886     def OnButton(self
, evt
): 
 887         self
.win 
= ButtonPanelDemo(self
) 
 891 #---------------------------------------------------------------------- 
 893 def runTest(frame
, nb
, log
): 
 894     win 
= TestPanel(nb
, log
) 
 897 #---------------------------------------------------------------------- 
 901 overview 
= bp
.__doc
__ 
 905 if __name__ 
== '__main__': 
 908     run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])