wx.ToolBar

Inheritance diagram for wx.ToolBar:



Description

The name wx.ToolBar is defined to be a synonym for one of the following classes:

  • wx.ToolBar95: The native Windows 95 toolbar. Used on Windows 95, NT 4 and above.
  • wx.ToolBarMSW: A Windows implementation. Used on 16-bit Windows.
  • wx.ToolBarGTK: The GTK toolbar.

Window Styles

Window Style Description
wx.TB_FLAT Gives the toolbar a flat look (Windows and GTK only).
wx.TB_DOCKABLE Makes the toolbar floatable and dockable (GTK only).
wx.TB_HORIZONTAL Specifies horizontal layout (default).
wx.TB_VERTICAL Specifies vertical layout.
wx.TB_TEXT Shows the text in the toolbar buttons; by default only icons are shown.
wx.TB_NOICONS Specifies no icons in the toolbar buttons; by default they are shown.
wx.TB_NODIVIDER Specifies no divider (border) above the toolbar (Windows only).
wx.TB_NOALIGN Specifies no alignment with the parent window (Windows only, not very useful).
wx.TB_HORZ_LAYOUT Shows the text and the icons alongside, not vertically stacked (Windows and GTK 2 only). This style must be used with wx.TB_TEXT.
wx.TB_HORZ_TEXT Combination of wx.TB_HORZ_LAYOUT and wx.TB_TEXT.
wx.TB_NO_TOOLTIPS Don’t show the short help tooltips for the tools when the mouse hovers over them.
wx.TB_BOTTOM Align the toolbar at the bottom of parent window.
wx.TB_RIGHT Align the toolbar at the right side of parent window.

Remarks

You may also create a toolbar that is managed by the frame, by calling wx.Frame.CreateToolBar. Under Pocket PC, you should always use this function for creating the toolbar to be managed by the frame, so that wxWidgets can use a combined menubar and toolbar. Where you manage your own toolbars, create a wx.ToolBar as usual.

The meaning of a “separator” is a vertical line under Windows and simple space under GTK+.

wx.ToolBar95: Note that this toolbar paints tools to reflect system-wide colours. If you use more than 16 colours in your tool bitmaps, you may wish to suppress this behaviour, otherwise system colours in your bitmaps will inadvertently be mapped to system colours. To do this, set the msw.remap system option before creating the toolbar:

wx.SystemOptions.SetOption("msw.remap", 0)

If you wish to use 32-bit images (which include an alpha channel for transparency) use:

wx.SystemOptions.SetOption("msw.remap", 2)

Then colour remapping is switched off, and a transparent background used. But only use this option under Windows XP with true colour:

theApp.GetComCtl32Version() >= 600 and wx.DisplayDepth() >= 32

Event Handling

The toolbar class emits menu commands in the same way that a frame menubar does, so you can use one wx.EVT_MENU event for both a menu item and a toolbar button. The event handler functions take a wx.CommandEvent argument. For most event, the identifier of the tool is passed, but for wx.EVT_TOOL_ENTER the toolbar window identifier is passed and the tool identifier is retrieved from the wx.CommandEvent.

This is because the identifier may be -1 when the mouse moves off a tool, and -1 is not allowed as an identifier in the event system.

Event Name Description
wx.EVT_TOOL(id, func) Process a wx.wxEVT_COMMAND_TOOL_CLICKED event (a synonym for wx.wxEVT_COMMAND_MENU_SELECTED). Pass the id of the tool.
wx.EVT_MENU(id, func) The same as EVT_TOOL.
wx.EVT_TOOL_RANGE(id1, id2, func) Process a wx.wxEVT_COMMAND_TOOL_CLICKED event for a range of identifiers. Pass the ids of the tools.
wx.EVT_MENU_RANGE(id1, id2, func) The same as EVT_TOOL_RANGE.
wx.EVT_TOOL_RCLICKED(id, func) Process a wx.wxEVT_COMMAND_TOOL_RCLICKED event. Pass the id of the tool.
wx.EVT_TOOL_RCLICKED_RANGE(id1, id2, func) Process a wx.wxEVT_COMMAND_TOOL_RCLICKED event for a range of ids. Pass the ids of the tools.
wx.EVT_TOOL_ENTER(id, func) Process a wx.wxEVT_COMMAND_TOOL_ENTER event. Pass the id of the toolbar itself. The value of wx.CommandEvent.GetSelection is the tool id, or -1 if the mouse cursor has moved off a tool.

Class API

Methods

__init__(parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=wx.NO_BORDER|wx.TB_HORIZONTAL, name=wx.ToolBarNameStr)

Constructs a toolbar.

Parameters:


Returns:

wx.ToolBar


AddCheckLabelTool(id, label, bitmap, bmpDisabled=wx.NullBitmap, shortHelp='', longHelp='', clientData=None)

Adds a new check (or toggle) tool to the toolbar.

Parameters:

  • id (int): An integer by which the tool may be identified in subsequent operations.
  • label (string): The tool label.
  • bitmap (wx.Bitmap): The primary tool bitmap.
  • bmpDisabled (wx.Bitmap): The bitmap used when the tool is disabled. If it is equal to wx.NullBitmap, the disabled bitmap is automatically generated by greing the normal one.
  • shortHelp (string): This string is used for the tools tooltip.
  • longHelp (string): This string is shown in the wx.StatusBar (if any) of the parent frame when the mouse pointer is inside the tool.
  • clientData (PyObject): An optional pointer to client data which can be retrieved later using GetToolClientData.

Returns:

wx.ToolBarToolBase

Note

After you have added tools to a toolbar, you must call Realize in order to have the tools appear

See also

AddTool


AddCheckTool(id, bitmap, bmpDisabled=wx.NullBitmap, shortHelp='', longHelp='', clientData=None)

Adds a new check (or toggle) tool to the toolbar.

Parameters:

  • id (int): An integer by which the tool may be identified in subsequent operations.
  • bitmap (wx.Bitmap): The primary tool bitmap.
  • bmpDisabled (wx.Bitmap): The bitmap used when the tool is disabled. If it is equal to wx.NullBitmap, the disabled bitmap is automatically generated by greing the normal one.
  • shortHelp (string): This string is used for the tools tooltip.
  • longHelp (string): This string is shown in the wx.StatusBar (if any) of the parent frame when the mouse pointer is inside the tool.
  • clientData (PyObject): An optional pointer to client data which can be retrieved later using GetToolClientData.

Returns:

wx.ToolBarToolBase

Note

After you have added tools to a toolbar, you must call Realize in order to have the tools appear

See also

AddTool


AddControl(control)

Adds any control to the toolbar, typically e.g. a combobox.

Parameters:


Returns:

bool


AddLabelTool(id, label, bitmap, bmpDisabled=wx.NullBitmap, kind=0, shortHelp='', longHelp='', clientData=None)

Adds a new label tool to the toolbar.

Parameters:

  • id (int): An integer by which the tool may be identified in subsequent operations.
  • label (string): The tool label.
  • bitmap (wx.Bitmap): The primary tool bitmap.
  • bmpDisabled (wx.Bitmap): The bitmap used when the tool is disabled. If it is equal to wx.NullBitmap, the disabled bitmap is automatically generated by greing the normal one.
  • kind (int): May be wx.ITEM_NORMAL for a normal button (default), wx.ITEM_CHECK for a checkable tool (such tool stays pressed after it had been toggled) or wx.ITEM_RADIO for a checkable tool which makes part of a radio group of tools each of which is automatically unchecked whenever another button in the group is checked.
  • shortHelp (string): This string is used for the tools tooltip.
  • longHelp (string): This string is shown in the wx.StatusBar (if any) of the parent frame when the mouse pointer is inside the tool.
  • clientData (PyObject): An optional pointer to client data which can be retrieved later using GetToolClientData.

Returns:

wx.ToolBarToolBase

Note

After you have added tools to a toolbar, you must call Realize in order to have the tools appear

See also

AddTool


AddRadioLabelTool(id, label, bitmap, bmpDisabled=wx.NullBitmap, shortHelp='', longHelp='', clientData=None)

Add a radio tool, i.e. a tool which can be toggled and releases any other toggled radio tools in the same group when it happens.

Parameters:

  • id (int): An integer by which the tool may be identified in subsequent operations.
  • label (string): The tool label.
  • bitmap (wx.Bitmap): The primary tool bitmap.
  • bmpDisabled (wx.Bitmap): The bitmap used when the tool is disabled. If it is equal to wx.NullBitmap, the disabled bitmap is automatically generated by greing the normal one.
  • shortHelp (string): This string is used for the tools tooltip.
  • longHelp (string): This string is shown in the wx.StatusBar (if any) of the parent frame when the mouse pointer is inside the tool.
  • clientData (PyObject): An optional pointer to client data which can be retrieved later using GetToolClientData.

Returns:

wx.ToolBarToolBase

Note

After you have added tools to a toolbar, you must call Realize in order to have the tools appear

See also

AddTool


AddRadioTool(id, bitmap, bmpDisabled=wx.NullBitmap, shortHelp='', longHelp='', clientData=None)

Adds a new radio tool to the toolbar. Consecutive radio tools form a radio group such that exactly one button in the group is pressed at any moment, in other words whenever a button in the group is pressed the previously pressed button is automatically released. You should avoid having the radio groups of only one element as it would be impossible for the user to use such button.

By default, the first button in the radio group is initially pressed, the others are not.

Parameters:

  • id (int): An integer by which the tool may be identified in subsequent operations.
  • bitmap (wx.Bitmap): The primary tool bitmap.
  • bmpDisabled (wx.Bitmap): The bitmap used when the tool is disabled. If it is equal to wx.NullBitmap, the disabled bitmap is automatically generated by greing the normal one.
  • shortHelp (string): This string is used for the tools tooltip.
  • longHelp (string): This string is shown in the wx.StatusBar (if any) of the parent frame when the mouse pointer is inside the tool.
  • clientData (PyObject): An optional pointer to client data which can be retrieved later using GetToolClientData.

Returns:

wx.ToolBarToolBase

Note

After you have added tools to a toolbar, you must call Realize in order to have the tools appear

See also

AddTool


AddSeparator()
Adds a separator for spacing groups of tools.

AddSimpleTool(id, bitmap, shortHelp='', longHelp='', kind=0)

Old way to add a new tool to the toolbar.

Parameters:

  • id (int): An integer by which the tool may be identified in subsequent operations.
  • bitmap (wx.Bitmap): The primary tool bitmap.
  • shortHelp (string): This string is used for the tools tooltip.
  • longHelp (string): This string is shown in the wx.StatusBar (if any) of the parent frame when the mouse pointer is inside the tool.
  • kind (int): May be wx.ITEM_NORMAL for a normal button (default), wx.ITEM_CHECK for a checkable tool (such tool stays pressed after it had been toggled) or wx.ITEM_RADIO for a checkable tool which makes part of a radio group of tools each of which is automatically unchecked whenever another button in the group is checked.

Returns:

wx.ToolBarToolBase

Note

After you have added tools to a toolbar, you must call Realize in order to have the tools appear


AddTool(id, bitmap, bmpDisabled=wx.NullBitmap, kind=0, shortHelp='', longHelp='', clientData=None)

Old way to add a new tool to the toolbar.

Parameters:

  • id (int): An integer by which the tool may be identified in subsequent operations.
  • bitmap (wx.Bitmap): The primary tool bitmap.
  • bmpDisabled (wx.Bitmap): The bitmap used when the tool is disabled. If it is equal to wx.NullBitmap, the disabled bitmap is automatically generated by greing the normal one.
  • kind (int): May be wx.ITEM_NORMAL for a normal button (default), wx.ITEM_CHECK for a checkable tool (such tool stays pressed after it had been toggled) or wx.ITEM_RADIO for a checkable tool which makes part of a radio group of tools each of which is automatically unchecked whenever another button in the group is checked.
  • shortHelp (string): This string is used for the tools tooltip.
  • longHelp (string): This string is shown in the wx.StatusBar (if any) of the parent frame when the mouse pointer is inside the tool.
  • clientData (PyObject): An optional pointer to client data which can be retrieved later using GetToolClientData.

Returns:

wx.ToolBarToolBase

Note

After you have added tools to a toolbar, you must call Realize in order to have the tools appear


AddToolItem(id, item)

Adds a wx.ToolBarToolBase item to the toolbar.

Parameters:

  • item (wx.ToolBarToolBase)

ClearTools()
Deletes all the tools in the toolbar.

DeleteTool(id)

Removes the specified tool from the toolbar and deletes it.

If you don’t want to delete the tool, but just to remove it from the toolbar (to possibly add it back later), you may use RemoveTool instead.

Returns True if the tool was deleted, False otherwise.

Parameters:

  • id (int): The tool id.

Returns:

bool

Note

Note that it is unnecessary to call Realize for the change to take place, it will happen immediately.

See also

DeleteToolByPos


DeleteToolByPos(pos)

This function behaves like DeleteTool but it deletes the tool at the specified position and not the one with the given id.

Parameters:

  • pos (int): The tool position in the wx.ToolBar.

Returns:

bool


EnableTool(toolId, enable)

Enables or disables the tool.

Parameters:

  • toolId (int): Tool to enable or disable.
  • enable (bool): If True, enables the tool, otherwise disables it.

Note

Some implementations will change the visible state of the tool to indicate that it is disabled.


FindById(id)

Returns a pointer to the tool identified by id or None if no corresponding tool is found.

Parameters:

  • id (int): The tool id.

Returns:

wxToolBarToolBase


FindControl(id)

Returns a pointer to the control identified by id or None if no corresponding control is found.

Parameters:

  • id (int): The control id.

Returns:

wx.Control


FindToolForPosition(x, y)

Finds a tool for the given mouse position.

Parameters:

  • x (int): X position.
  • y (int): Y position.

Returns:

wx.ToolBarToolBase

Note

Currently not implemented in wxGTK (always returns None there).


GetMargins()

Returns the left/right and top/bottom margins, which are also used for inter-toolspacing.


Returns:

wx.Size

See also

SetMargins


GetToolBitmapSize()

Returns the size of bitmap that the toolbar expects to have. The default bitmap size is 16 by 15 pixels.


Returns:

wx.Size

Note

Note that this is the size of the bitmap you pass to AddTool, and not the eventual size of the tool button.


GetToolClientData(toolId)

Get any client data associated with the tool.

Parameters:

  • toolId (int): Id of the tool, as passed to AddTool.

Returns:

wx.Object


GetToolEnabled(toolId)

Called to determine whether a tool is enabled (responds to user input).

Parameters:

  • toolId (int): Id of the tool in question.

Returns:

bool

See also

EnableTool


GetToolLongHelp(toolId)

Returns the long help for the given tool.

Parameters:

  • toolId (int): The tool in question.

Returns:

string


GetToolPacking()

Returns the value used for packing tools.


Returns:

int

See also

SetToolPacking


GetToolPos(toolId)

Returns the tool position in the toolbar, or wx.NOT_FOUND if the tool is not found.

Parameters:

  • toolId (int): The tool in question.

Returns:

int


GetToolSeparation()

Returns the default separator size.


Returns:

int


GetToolShortHelp(toolId)

Returns the short help for the given tool.

Parameters:

  • toolId (int): The tool in question.

Returns:

string


GetToolSize()

Returns the size of a whole button, which is usually larger than a tool bitmap because of added 3D effects.


Returns:

wx.Size


GetToolState(toolId)

Gets the on/off state of a toggle tool.

Parameters:

  • toolId (int): The tool in question.

Returns:

bool

See also

ToggleTool


GetToolsCount()

Returns the number of tools in the toolbar.


Returns:

int


InsertControl(pos, control)

Inserts the control into the toolbar at the given position.

You must call Realize for the change to take place.

Parameters:

  • pos (int): The control position in the wx.ToolBar.
  • control (wx.Control): The control to insert.

Returns:

wx.ToolBarToolBase


InsertLabelTool(pos, id, label, bitmap, bmpDisabled=wx.NullBitmap, kind=0, shortHelp='', longHelp='', clientData=None)

Inserts a new label tool to the toolbar at the specified position.

Parameters:

  • pos (int): The control position in the wx.ToolBar.
  • id (int): An integer by which the tool may be identified in subsequent operations.
  • label (string): The tool label.
  • bitmap (wx.Bitmap): The primary tool bitmap.
  • bmpDisabled (wx.Bitmap): The bitmap used when the tool is disabled. If it is equal to wx.NullBitmap, the disabled bitmap is automatically generated by greing the normal one.
  • kind (int): May be wx.ITEM_NORMAL for a normal button (default), wx.ITEM_CHECK for a checkable tool (such tool stays pressed after it had been toggled) or wx.ITEM_RADIO for a checkable tool which makes part of a radio group of tools each of which is automatically unchecked whenever another button in the group is checked.
  • shortHelp (string): This string is used for the tools tooltip.
  • longHelp (string): This string is shown in the wx.StatusBar (if any) of the parent frame when the mouse pointer is inside the tool.
  • clientData (PyObject): An optional pointer to client data which can be retrieved later using GetToolClientData.

Returns:

wx.ToolBarToolBase

Note

After you have added tools to a toolbar, you must call Realize in order to have the tools appear

See also

AddTool


InsertSeparator()

Inserts the separator into the toolbar at the given position. You must call Realize for the change to take place.


Returns:

wx.ToolBarToolBase


InsertSimpleTool(pos, id, bitmap, shortHelp='', longHelp='', kind=0)

Old way to insert a new tool to the toolbar.

Parameters:

  • pos (int): The control position in the wx.ToolBar.
  • id (int): An integer by which the tool may be identified in subsequent operations.
  • bitmap (wx.Bitmap): The primary tool bitmap.
  • shortHelp (string): This string is used for the tools tooltip.
  • longHelp (string): This string is shown in the wx.StatusBar (if any) of the parent frame when the mouse pointer is inside the tool.
  • kind (int): May be wx.ITEM_NORMAL for a normal button (default), wx.ITEM_CHECK for a checkable tool (such tool stays pressed after it had been toggled) or wx.ITEM_RADIO for a checkable tool which makes part of a radio group of tools each of which is automatically unchecked whenever another button in the group is checked.

Returns:

wx.ToolBarToolBase

Note

After you have added tools to a toolbar, you must call Realize in order to have the tools appear


InsertTool(pos, id, bitmap, bmpDisabled=wx.NullBitmap, kind=0, shortHelp='', longHelp='', clientData=None)

Old way to insert a new tool to the toolbar.

Parameters:

  • pos (int): The control position in the wx.ToolBar.
  • id (int): An integer by which the tool may be identified in subsequent operations.
  • bitmap (wx.Bitmap): The primary tool bitmap.
  • bmpDisabled (wx.Bitmap): The bitmap used when the tool is disabled. If it is equal to wx.NullBitmap, the disabled bitmap is automatically generated by greing the normal one.
  • kind (int): May be wx.ITEM_NORMAL for a normal button (default), wx.ITEM_CHECK for a checkable tool (such tool stays pressed after it had been toggled) or wx.ITEM_RADIO for a checkable tool which makes part of a radio group of tools each of which is automatically unchecked whenever another button in the group is checked.
  • shortHelp (string): This string is used for the tools tooltip.
  • longHelp (string): This string is shown in the wx.StatusBar (if any) of the parent frame when the mouse pointer is inside the tool.
  • clientData (PyObject): An optional pointer to client data which can be retrieved later using GetToolClientData.

Returns:

wx.ToolBarToolBase

Note

After you have added tools to a toolbar, you must call Realize in order to have the tools appear


InsertToolItem(pos, item)

Inserts a wx.ToolBarToolBase item to the toolbar in the specified position.

Parameters:

  • pos (int): The control position in the wx.ToolBar.
  • item (wx.ToolBarToolBase)

Realize()

This function should be called after you have added tools.


Returns:

bool


RemoveTool(toolId)

Removes the given tool from the toolbar but doesn’t delete it.

This allows to insert/add this tool back to this (or another) toolbar later.

Parameters:

  • toolId (int): The tool in question.

Returns:

wx.ToolBarToolBase

Note

Note that it is unnecessary to call Realize for the change to take place, it will happen immediately.

See also

DeleteTool


SetMargins(size)

Set the values to be used as margins for the toolbar.

Parameters:


Note

This must be called before the tools are added if absolute positioning is to be used, and the default (zero-size) margins are to be overridden.

See also

GetMargins, wx.Size


SetMarginsXY(x, y)

Set the values to be used as margins for the toolbar.

Parameters:

  • x (int): Margin size in x direction.
  • y (int): Margin size in y direction.

Note

This must be called before the tools are added if absolute positioning is to be used, and the default (zero-size) margins are to be overridden.

See also

GetMargins, wx.Size


SetToolBitmapSize(size)

Sets the default size of each tool bitmap. The default bitmap size is 16 by 15 pixels.

Parameters:

  • size (wx.Size): The size of the bitmaps in the toolbar.

Note

This should be called to tell the toolbar what the tool bitmap size is. Call it before you add tools.

Note

Note that this is the size of the bitmap you pass to AddTool, and not the eventual size of the tool button.


SetToolClientData(toolId, clientData)

Sets the client data associated with the tool.

Parameters:

  • toolId (int): The tool in question.
  • clientData (PyObject): A pointer to client data which can be retrieved later using GetToolClientData.

SetToolDisabledBitmap(id, bitmap)

Sets the bitmap to be used by the tool with the given id when the tool is in a disabled state. This can only be used on Button tools, not controls.

Parameters:

Note

The native toolbar classes on the main platforms all synthesize the disabled bitmap from the normal bitmap, so this function will have no effect on those platforms.


SetToolLongHelp(toolId, helpString)

Sets the long help for the given tool.

Parameters:

  • toolId (int): The tool in question.
  • helpString (string): A string for the long help.

Note

You might use the long help for displaying the tool purpose on the wx.StatusBar.


SetToolNormalBitmap(id, bitmap)

Sets the bitmap to be used by the tool with the given id. This can only be used on Button tools, not controls.

Parameters:


SetToolPacking(packing)

Sets the value used for spacing tools. The default value is 1.

Parameters:

  • packing (int): The value for packing.

Note

The packing is used for spacing in the vertical direction if the toolbar is horizontal, and for spacing in the horizontal direction if the toolbar is vertical.

See also

GetToolPacking


SetToolSeparation(separation)

Sets the default separator size. The default value is 5.

Parameters:

  • separation (int): The separator size.

See also

AddSeparator


SetToolShortHelp(toolId, helpString)

Sets the short help for the given tool.

Parameters:

  • toolId (int): The tool in question.
  • helpString (string): The string for the short help.

Note

An application might use short help for identifying the tool purpose in a tooltip.


ToggleTool(toolId, toggle)

Toggles a tool on or off. This does not cause any event to get emitted.

Parameters:

  • toolId (int): Tool in question.
  • toggle (bool): If True, toggles the tool on, otherwise toggles it off.

Note

Only applies to a tool that has been specified as a toggle tool.