Package wx :: Package lib :: Module buttonpanel
[frames | no frames]

Module wx.lib.buttonpanel

With ButtonPanel class you have a panel with gradient coloring on it and with the possibility to place some buttons on it. Using a standard panel with normal wx.Buttons leads to an ugly result: the buttons are placed correctly on the panel - but with grey area around them. Gradient coloring is kept behind the images - this was achieved due to the PNG format and the transparency of the bitmaps.

The image are functioning like a buttons and can be caught in your code using the usual self.Bind(wx.EVT_BUTTON, self.OnButton) method.

The control is generic, and support theming (well, I tested it under Windows with the three defauls themes: grey, blue, silver and the classic look).

Usage

ButtonPanel supports 4 alignments: left, right, top, bottom, which have a different meaning and behavior wrt wx.Toolbar. The easiest thing is to try the demo to understand, but I'll try to explain how it works.

CASE 1: ButtonPanel has a main caption text

Left alignment means ButtonPanel is horizontal, with the text aligned to the left. When you shrink the demo frame, if there is not enough room for all the controls to be shown, the controls closest to the text are hidden;

Right alignment means ButtonPanel is horizontal, with the text aligned to the right. Item layout as above;

Top alignment means ButtonPanel is vertical, with the text aligned to the top. Item layout as above;

Bottom alignment means ButtonPanel is vertical, with the text aligned to the bottom. Item layout as above.

CASE 2: ButtonPanel has no main caption text In this case, left and right alignment are the same (as top and bottom are the same), but the layout strategy changes: now if there is not enough room for all the controls to be shown, the last added items are hidden ("last" means on the far right for horizontal ButtonPanels and far bottom for vertical ButtonPanels).

The following example shows a simple implementation that uses ButtonPanel inside a very simple frame:

class MyFrame(wx.Frame):

    def __init__(self, parent, id=-1, title="ButtonPanel", pos=wx.DefaultPosition,
                 size=(800, 600), style=wx.DEFAULT_FRAME_STYLE):
               
        wx.Frame.__init__(self, parent, id, title, pos, size, style)

        mainPanel = wx.Panel(self, -1)
        self.logtext = wx.TextCtrl(mainPanel, -1, "", style=wx.TE_MULTILINE)

        vSizer = wx.BoxSizer(wx.VERTICAL) 
        mainPanel.SetSizer(vSizer) 

        alignment = BP_ALIGN_RIGHT 

        titleBar = ButtonPanel(mainPanel, -1, "A Simple Test & Demo")

        btn1 = ButtonInfo(wx.NewId(), wx.Bitmap("png4.png", wx.BITMAP_TYPE_PNG))
        titleBar.AddButton(btn1)
        self.Bind(wx.EVT_BUTTON, self.OnButton, btn1)

        btn2 = ButtonInfo(wx.NewId(), wx.Bitmap("png3.png", wx.BITMAP_TYPE_PNG))
        titleBar.AddButton(btn2)
        self.Bind(wx.EVT_BUTTON, self.OnButton, btn2)

        btn3 = ButtonInfo(wx.NewId(), wx.Bitmap("png2.png", wx.BITMAP_TYPE_PNG))
        titleBar.AddButton(btn3)
        self.Bind(wx.EVT_BUTTON, self.OnButton, btn3)

        btn4 = ButtonInfo(wx.NewId(), wx.Bitmap("png1.png", wx.BITMAP_TYPE_PNG))
        titleBar.AddButton(btn4)
        self.Bind(wx.EVT_BUTTON, self.OnButton, btn4)

        vSizer.Add(titleBar, 0, wx.EXPAND)
        vSizer.Add((20, 20))
        vSizer.Add(self.logtext, 1, wx.EXPAND|wx.ALL, 5)

        vSizer.Layout()

# our normal wxApp-derived class, as usual

app = wx.PySimpleApp()

frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()

app.MainLoop()

License And Version:

ButtonPanel Is Freeware And Distributed Under The wxPython License.

Latest Revision: Andrea Gavana @ 12 Oct 2006, 17.00 GMT Version 0.3.


Classes
BoxSizer  
BPArt BPArt is an art provider class which does all of the drawing for ButtonPanel.
ButtonInfo  
ButtonPanel  
ButtonPanelText  
Control  
Separator  
Sizer Sizer
StatusBarTimer Timer used for deleting StatusBar long help after _DELAY seconds.

Function Summary
  BrightenColour(color, factor)
Bright the input colour by a factor.
  GrayOut(anImage)
Convert the given image (in place) to a grayed-out version, appropriate for a 'Disabled' appearance.
  MakeGray((r, g, b), factor, maskColor)
Make a pixel grayed-out.

Variable Summary
int BP_ALIGN_BOTTOM = 8                                                                     
int BP_ALIGN_LEFT = 2                                                                     
int BP_ALIGN_RIGHT = 1                                                                     
int BP_ALIGN_TOP = 4                                                                     
int BP_BACKGROUND_COLOR = 0                                                                     
int BP_BORDER_COLOR = 3                                                                     
int BP_BORDER_SIZE = 16                                                                    
int BP_BUTTONTEXT_ALIGN_BOTTOM = 12                                                                    
int BP_BUTTONTEXT_ALIGN_RIGHT = 13                                                                    
int BP_BUTTONTEXT_COLOR = 5                                                                     
int BP_BUTTONTEXT_FONT = 11                                                                    
int BP_BUTTONTEXT_INACTIVE_COLOR = 6                                                                     
int BP_DEFAULT_STYLE = 1                                                                     
int BP_GRADIENT_COLOR_FROM = 1                                                                     
int BP_GRADIENT_COLOR_TO = 2                                                                     
int BP_GRADIENT_HORIZONTAL = 2                                                                     
int BP_GRADIENT_NONE = 0                                                                     
int BP_GRADIENT_VERTICAL = 1                                                                     
int BP_HT_BUTTON = 200                                                                   
int BP_HT_NONE = 201                                                                   
int BP_MARGINS_SIZE = 15                                                                    
int BP_PADDING_SIZE = 17                                                                    
int BP_SELECTION_BRUSH_COLOR = 7                                                                     
int BP_SELECTION_PEN_COLOR = 8                                                                     
int BP_SEPARATOR_COLOR = 9                                                                     
int BP_SEPARATOR_SIZE = 14                                                                    
int BP_TEXT_COLOR = 4                                                                     
int BP_TEXT_FONT = 10                                                                    
int BP_USE_GRADIENT = 2                                                                     

Function Details

BrightenColour(color, factor)

Bright the input colour by a factor.

GrayOut(anImage)

Convert the given image (in place) to a grayed-out version, appropriate for a 'Disabled' appearance.

MakeGray((r, g, b), factor, maskColor)

Make a pixel grayed-out. If the pixel matches the maskColor, it won't be changed.


Variable Details

BP_ALIGN_BOTTOM

Type:
int
Value:
8                                                                     

BP_ALIGN_LEFT

Type:
int
Value:
2                                                                     

BP_ALIGN_RIGHT

Type:
int
Value:
1                                                                     

BP_ALIGN_TOP

Type:
int
Value:
4                                                                     

BP_BACKGROUND_COLOR

Type:
int
Value:
0                                                                     

BP_BORDER_COLOR

Type:
int
Value:
3                                                                     

BP_BORDER_SIZE

Type:
int
Value:
16                                                                    

BP_BUTTONTEXT_ALIGN_BOTTOM

Type:
int
Value:
12                                                                    

BP_BUTTONTEXT_ALIGN_RIGHT

Type:
int
Value:
13                                                                    

BP_BUTTONTEXT_COLOR

Type:
int
Value:
5                                                                     

BP_BUTTONTEXT_FONT

Type:
int
Value:
11                                                                    

BP_BUTTONTEXT_INACTIVE_COLOR

Type:
int
Value:
6                                                                     

BP_DEFAULT_STYLE

Type:
int
Value:
1                                                                     

BP_GRADIENT_COLOR_FROM

Type:
int
Value:
1                                                                     

BP_GRADIENT_COLOR_TO

Type:
int
Value:
2                                                                     

BP_GRADIENT_HORIZONTAL

Type:
int
Value:
2                                                                     

BP_GRADIENT_NONE

Type:
int
Value:
0                                                                     

BP_GRADIENT_VERTICAL

Type:
int
Value:
1                                                                     

BP_HT_BUTTON

Type:
int
Value:
200                                                                   

BP_HT_NONE

Type:
int
Value:
201                                                                   

BP_MARGINS_SIZE

Type:
int
Value:
15                                                                    

BP_PADDING_SIZE

Type:
int
Value:
17                                                                    

BP_SELECTION_BRUSH_COLOR

Type:
int
Value:
7                                                                     

BP_SELECTION_PEN_COLOR

Type:
int
Value:
8                                                                     

BP_SEPARATOR_COLOR

Type:
int
Value:
9                                                                     

BP_SEPARATOR_SIZE

Type:
int
Value:
14                                                                    

BP_TEXT_COLOR

Type:
int
Value:
4                                                                     

BP_TEXT_FONT

Type:
int
Value:
10                                                                    

BP_USE_GRADIENT

Type:
int
Value:
2                                                                     

Generated by Epydoc 2.1.20050511.rpd on Thu Mar 22 12:07:08 2007 http://epydoc.sf.net