AGW Logo

agw_title ButtonPanel

A custom panel class with gradient background shading with the possibility to add buttons and controls still respecting the gradient background.

hierarchy Inheritance Diagram

Inheritance diagram for: ButtonPanel

Inheritance diagram of ButtonPanel


appearance Control Appearance


ButtonPanel

ButtonPanel


method_summary Methods Summary

__init__Default class constructor.
AddButtonAdds a button to ButtonPanel.
AddControlAdds a wxPython control to ButtonPanel.
AddSeparatorAdds a separator line to ButtonPanel.
AddSpacerAdds a spacer (stretchable or fixed-size) to ButtonPanel.
ClearClears the ButtonPanel.
DoGetBestSizeGets the size which best suits ButtonPanel: for a control, it would be
DoGiveHelpShows tooltips and long help strings in wx.StatusBar.
DoLayoutDo the Layout for ButtonPanel.
FlexibleLayoutLayout the items when the main caption exists.
GetAlignmentReturns the buttons alignment.
GetBPArtReturns the associated BPArt art provider.
GetBarTextReturns the main caption text.
GetControlsReturns the wxPython controls that belongs to ButtonPanel.
GetItemSizeReturns the size of an item in the main ButtonPanel sizer.
GetNonFlexibleChildrenReturns all the ButtonPanel main sizer’s children that are not
GetStyleReturns the ButtonPanel window style.
GetUseHelpReturns whether or not short and long help strings should be displayed as tooltips
HasBarTextReturns whether ButtonPanel has a main caption text or not.
HitTestHitTest method for ButtonPanel.
IsStandardReturns whether ButtonPanel is aligned “Standard” (left/top) or not.
IsVerticalReturns whether ButtonPanel is vertically aligned or not.
LayoutItemsLayout the items using a different algorithms depending on the existance
OnEraseBackgroundHandles the wx.EVT_ERASE_BACKGROUND event for ButtonPanel.
OnLeftDownHandles the wx.EVT_LEFT_DOWN event for ButtonPanel.
OnLeftUpHandles the wx.EVT_LEFT_UP event for ButtonPanel.
OnMouseEnterWindowHandles the wx.EVT_ENTER_WINDOW event for ButtonPanel.
OnMouseLeaveHandles the wx.EVT_LEAVE_WINDOW event for ButtonPanel.
OnMouseMoveHandles the wx.EVT_MOTION event for ButtonPanel.
OnPaintHandles the wx.EVT_PAINT event for ButtonPanel.
OnSizeHandles the wx.EVT_SIZE event for ButtonPanel.
OnStatusBarTimerHandles the timer expiring to delete the long help string in wx.StatusBar.
ReCreateSizerRecreates the ButtonPanel sizer accordingly to the alignment specified.
RemoveAllButtonsRemove all the buttons from ButtonPanel.
RemoveAllSeparatorsRemove all the separators from ButtonPanel.
RemoveHelpRemoves the tooltips and statusbar help (if any) for a button.
RemoveTextRemoves the main caption text.
RepaintOldSelectionRepaints the old selected/hovered button.
SetAlignmentSets the buttons alignment.
SetBPArtSets a new BPArt art provider to ButtonPanel.
SetBarTextSets the main caption text.
SetStyleSets the ButtonPanel window style.
SetUseHelpSets whether or not short and long help strings should be displayed as tooltips
SizeLayoutLayout the items when no main caption exists.

API Class API

class ButtonPanel(wx.PyPanel)[source]

A custom panel class with gradient background shading with the possibility to add buttons and controls still respecting the gradient background.



__init__(parent, id=wx.ID_ANY, text="", agwStyle=BP_DEFAULT_STYLE, alignment=BP_ALIGN_LEFT, name="buttonPanel")[source]

Default class constructor.

Parameters:
  • parent (wx.Window) – the parent window. Must not be None;
  • id (integer) – window identifier. If wx.ID_ANY, will automatically create an identifier;
  • text (string) – the main caption text for ButtonPanel;
  • agwStyle (integer) – the AGW-specific window style (one of BP_DEFAULT_STYLE, BP_USE_GRADIENT);
  • alignment (integer) – alignment of buttons (left or right);
  • name (string) – window class name.


AddButton(btnInfo)[source]

Adds a button to ButtonPanel.

Parameters:btnInfo – an instance of ButtonInfo.

Note

Remember to pass a ButtonInfo instance to this method, and not a standard wx.Button or a wx.ToolBar tool.



AddControl(control, proportion=0, flag=wx.ALIGN_CENTER|wx.ALL, border=None)[source]

Adds a wxPython control to ButtonPanel.

Parameters:
  • control – an instance of wx.Window;
  • proportion (integer) – the control proportion (0 for fixed-size, 1 or more for a stretchable one);
  • flag (integer) – one of the wx.BoxSizer flags;
  • border (integer) – the control border width (in pixels), if the flag parameter is set to include any border flag.


AddSeparator()[source]

Adds a separator line to ButtonPanel.



AddSpacer(size=(0, 0), proportion=1, flag=wx.EXPAND)[source]

Adds a spacer (stretchable or fixed-size) to ButtonPanel.

Parameters:
  • size (tuple) – the spacer size as a tuple;
  • proportion (integer) – the spacer proportion (0 for fixed-size, 1 or more for a stretchable one);
  • flag (integer) – one of the wx.BoxSizer flags.



Clear()[source]

Clears the ButtonPanel.

Can be used to reset the ButtonPanel if you’d like have a new set of buttons on the panel.



DoGetBestSize()[source]

Gets the size which best suits ButtonPanel: for a control, it would be the minimal size which doesn’t truncate the control, for a panel - the same size as it would have after a call to Fit().

Returns:An instance of wx.Size.

Note

Overridden from wx.PyPanel.



DoGiveHelp(hit)[source]

Shows tooltips and long help strings in wx.StatusBar.

Parameters:hit – an instance of ButtonInfo where the mouse is hovering.


DoLayout()[source]

Do the Layout for ButtonPanel.

Note

Call this method every time you make a modification to the layout or to the customizable sizes of the pseudo controls.



FlexibleLayout(nonspacers, allchildren)[source]

Layout the items when the main caption exists.

Parameters:
  • nonspacers (list) – a list of items which are not spacers;
  • allchildren (list) – a list of all the children of ButtonPanel.


GetAlignment()[source]

Returns the buttons alignment.

Returns:An integer specifying the buttons alignment.

See also

SetAlignment for a set of valid alignment bits.



GetBPArt()[source]

Returns the associated BPArt art provider.



GetBarText()[source]

Returns the main caption text.

Returns:A string representing the caption text.


GetControls()[source]

Returns the wxPython controls that belongs to ButtonPanel.

Returns:A list of items inside ButtonPanel that are wxPython controls.


GetItemSize(item, isVertical)[source]

Returns the size of an item in the main ButtonPanel sizer.

Parameters:
  • item – an instance of ButtonInfo;
  • isVertical (bool) – True if ButtonPanel is in vertical orientation, False otherwise.
Returns:

An instance of wx.Size.



GetNonFlexibleChildren()[source]

Returns all the ButtonPanel main sizer’s children that are not flexible spacers.

Returns:A list of items inside ButtonPanel that are not flexible spacers.


GetStyle()[source]

Returns the ButtonPanel window style.

See also

SetStyle for a list of valid window styles.



GetUseHelp()[source]

Returns whether or not short and long help strings should be displayed as tooltips and wx.StatusBar items respectively.

Returns:True if the short and long help strings should be displayed as tooltips and wx.StatusBar items respectively, False otherwise.


HasBarText()[source]

Returns whether ButtonPanel has a main caption text or not.

Returns:True if ButtonPanel has a main caption text, False otherwise.


HitTest(pt)[source]

HitTest method for ButtonPanel.

Parameters:pt – the mouse position, an instance of wx.Point.
Returns:an instance of ButtonInfo and the hit flag BP_HT_BUTTON if a button client rectangle contains the input point pt, or wx.NOT_FOUND and BP_HT_NONE.


IsStandard()[source]

Returns whether ButtonPanel is aligned “Standard” (left/top) or not.

Returns:True if ButtonPanel is aligned “standard”, False otherwise.


IsVertical()[source]

Returns whether ButtonPanel is vertically aligned or not.

Returns:True if ButtonPanel is vertically aligned, False otherwise.


LayoutItems()[source]

Layout the items using a different algorithms depending on the existance of the main caption.



OnEraseBackground(event)[source]

Handles the wx.EVT_ERASE_BACKGROUND event for ButtonPanel.

Parameters:event – a wx.EraseEvent event to be processed.

Note

This is intentionally empty to reduce flicker.



OnLeftDown(event)[source]

Handles the wx.EVT_LEFT_DOWN event for ButtonPanel.

Parameters:event – a wx.MouseEvent event to be processed.


OnLeftUp(event)[source]

Handles the wx.EVT_LEFT_UP event for ButtonPanel.

Parameters:event – a wx.MouseEvent event to be processed.



OnMouseEnterWindow(event)[source]

Handles the wx.EVT_ENTER_WINDOW event for ButtonPanel.

Parameters:event – a wx.MouseEvent event to be processed.



OnMouseLeave(event)[source]

Handles the wx.EVT_LEAVE_WINDOW event for ButtonPanel.

Parameters:event – a wx.MouseEvent event to be processed.



OnMouseMove(event)[source]

Handles the wx.EVT_MOTION event for ButtonPanel.

Parameters:event – a wx.MouseEvent event to be processed.



OnPaint(event)[source]

Handles the wx.EVT_PAINT event for ButtonPanel.

Parameters:event – a wx.PaintEvent event to be processed.


OnSize(event)[source]

Handles the wx.EVT_SIZE event for ButtonPanel.

Parameters:event – a wx.SizeEvent event to be processed.

Todo

Improve the chain of methods OnSize ==> DoLayout ==> LayoutItems to avoid multiple calls to LayoutItems.



OnStatusBarTimer()[source]

Handles the timer expiring to delete the long help string in wx.StatusBar.



ReCreateSizer(text=None)[source]

Recreates the ButtonPanel sizer accordingly to the alignment specified.

Parameters:text (string) – the text to display as main caption. If text is set to None, the main caption will not be displayed.


RemoveAllButtons()[source]

Remove all the buttons from ButtonPanel.

Note

This function is for internal use only. If you are interested in manipulating a ButtonPanel in real time (ie. removing things on it) have a look at the Clear method.



RemoveAllSeparators()[source]

Remove all the separators from ButtonPanel.

Note

This function is for internal use only. If you are interested in manipulating a ButtonPanel in real time (ie. removing things on it) have a look at the Clear method.



RemoveHelp()[source]

Removes the tooltips and statusbar help (if any) for a button.



RemoveText()[source]

Removes the main caption text.



RepaintOldSelection()[source]

Repaints the old selected/hovered button.



SetAlignment(alignment)[source]

Sets the buttons alignment.

Parameters:alignment (integer) – can be one of the following bits:


integer parameter settings
Alignment Flag Value Description
BP_ALIGN_RIGHT 1 Buttons are aligned on the right
BP_ALIGN_LEFT 2 Buttons are aligned on the left
BP_ALIGN_TOP 4 Buttons are aligned at the top
BP_ALIGN_BOTTOM 8 Buttons are aligned at the bottom


SetBPArt(art)[source]

Sets a new BPArt art provider to ButtonPanel.

Parameters:art – an instance of BPArt.


SetBarText(text)[source]

Sets the main caption text.

Parameters:text (string) – the main caption text label. An empty string erases the main caption text.


SetStyle(agwStyle)[source]

Sets the ButtonPanel window style.

Parameters:agwStyle (integer) – one of the following bits:


integer parameter settings
Window Styles Hex Value Description
BP_DEFAULT_STYLE 0x1 ButtonPanel has a plain solid background.
BP_USE_GRADIENT 0x2 ButtonPanel has a gradient shading background.


SetUseHelp(useHelp=True)[source]

Sets whether or not short and long help strings should be displayed as tooltips and wx.StatusBar items respectively.

Parameters:useHelp (bool) – True to display short and long help strings as tooltips and wx.StatusBar items respectively, False otherwise.



SizeLayout(nonspacers, children)[source]

Layout the items when no main caption exists.

Parameters:
  • nonspacers (list) – a list of items which are not spacers;
  • children (list) – a list of all the children of ButtonPanel.
Tree

Table Of Contents

Previous topic

ButtonInfo

Next topic

ButtonPanelText