AGW Logo

agw_title FlatMenuBar

Implements the generic owner-drawn menu bar for FlatMenu.

hierarchy Inheritance Diagram

Inheritance diagram for: FlatMenuBar

Inheritance diagram of FlatMenuBar


method_summary Methods Summary

__init__Default class constructor.
ActivateMenuActivates a menu.
ActivateNextMenuActivates next menu and make sure all others are non-active.
ActivatePreviousMenuActivates previous menu and make sure all others are non-active.
AddCheckToolAdds a new check (or toggle) tool to the toolbar.
AddControlAdds any control to the toolbar, typically e.g.
AddRadioToolAdds a new radio tool to the toolbar.
AddSeparatorAdds a separator for spacing groups of tools in toolbar.
AddToolAdds a tool to the toolbar.
AppendAdds the item to the end of the menu bar.
AppendToolbarItemAppends a tool to the FlatMenuBar.
ClearBitmapsRestores a wx.NullBitmap for all the items in the menu.
CreateMoreMenuCreates the drop down menu and populate it.
DoGiveHelpGives tooltips and help in wx.StatusBar.
DoMouseMoveHandles mouse move event.
DoToolbarActionPerforms a toolbar button pressed action.
DrawMoreButtonDraws ‘more’ button to the right side of the menu bar.
DrawToolbarDraws the toolbar (if present).
DrawToolbarItemDraws a toolbar item button.
FindMenuReturns the index of the menu with the given title or wx.NOT_FOUND if
FindMenuItemFinds the menu item object associated with the given menu item identifier.
GetActiveToolbarItemReturns the active toolbar item.
GetBackgroundColourReturns the menu bar background colour.
GetInvisibleMenuItemCountReturns the number of invisible menu items.
GetInvisibleToolbarItemCountReturns the number of invisible toolbar items.
GetLastVisibleMenuReturns the index of the last visible menu on the menu bar.
GetMenuReturns the menu at the specified index menuIdx (zero-based).
GetMenuCountReturns the number of menus in the menubar.
GetMoreMenuButtonRectReturns a rectangle region, as an instance of wx.Rect, surrounding the menu button.
GetOptionsReturns the FlatMenuBar options, whether to show a toolbar, to use LCD screen settings etc...
GetRendererReturns the renderer associated with this instance.
GetRendererManagerReturns the FlatMenuBar renderer manager.
HitTestHitTest method for FlatMenuBar.
InsertInserts the menu at the given position into the menu bar.
OnAccelCmdSingle function to handle any accelerator key used inside the menubar.
OnCustomizeDlgHandles the customize dialog here.
OnEraseBackgroundHandles the wx.EVT_ERASE_BACKGROUND event for FlatMenuBar.
OnIdleHandles the wx.EVT_IDLE event for FlatMenuBar.
OnLeaveMenuBarHandles the wx.EVT_LEAVE_WINDOW event for FlatMenuBar.
OnLeaveWindowHandles the wx.EVT_LEAVE_WINDOW event for FlatMenuBar.
OnLeftDownHandles the wx.EVT_LEFT_DOWN event for FlatMenuBar.
OnLeftUpHandles the wx.EVT_LEFT_UP event for FlatMenuBar.
OnMenuDismissedHandles the EVT_FLAT_MENU_DISMISSED event for FlatMenuBar.
OnMouseMoveHandles the wx.EVT_MOTION event for FlatMenuBar.
OnPaintHandles the wx.EVT_PAINT event for FlatMenuBar.
OnSizeHandles the wx.EVT_SIZE event for FlatMenuBar.
OnStatusBarTimerHandles the timer expiring to delete the longHelp string in the wx.StatusBar.
PopupMoreMenuPops up the ‘more’ menu.
PositionAUIPositions the control inside a wxAUI / PyAUI frame manager.
ProcessMouseMoveFromMenuThis function is called from child menus, this allow a child menu to pass the mouse movement event to the menu bar.
RemoveRemoves the menu from the menu bar and returns the menu object - the caller is responsible for deleting it.
RemoveHelpRemoves the tooltips and statusbar help (if any) for a button.
ResetToolbarItemsUsed internally.
SetBackgroundColourSets the menu bar background colour.
SetBarHeightRecalculates the FlatMenuBar height when its settings change.
SetLCDMonitorSets whether the PC monitor is an LCD or not.
SetMarginSets the margin above and below the menu bar text.
SetOptionsSets the FlatMenuBar options, whether to show a toolbar, to use LCD screen settings etc...
SetSpacingSets the spacing between the menubar items.
SetToolbarMarginSets the margin around the toolbar.
SetToolbarSpacingSets the spacing between the toolbar tools.
SetUpdateIntervalSets the UpdateUI interval for toolbar items. All UpdateUI events are
ShowCustomizeShows/hides the drop-down arrow which allows customization of FlatMenu.
UpdateAcceleratorTableUpdates the parent accelerator table.
UpdateItemAn item was modified.

API Class API

class FlatMenuBar(wx.Panel)[source]

Implements the generic owner-drawn menu bar for FlatMenu.



__init__(parent, id=wx.ID_ANY, iconSize=SmallIcons, spacer=SPACER, options=FM_OPT_SHOW_CUSTOMIZE|FM_OPT_IS_LCD)[source]

Default class constructor.

Parameters:
  • parent – the menu bar parent, must not be None;
  • id (integer) – the window identifier. If wx.ID_ANY, will automatically create an identifier;
  • iconSize (integer) – size of the icons in the toolbar. This can be one of the following values (in pixels):


    integer parameter settings
    iconSize Bit Value Description
    LargeIcons 32 Use large 32x32 icons
    SmallIcons 16 Use standard 16x16 icons
  • spacer (integer) – the space between the menu bar text and the menu bar border;
  • options (integer) – a combination of the following bits:


    integer parameter settings
    options Bit Hex Value Description
    FM_OPT_IS_LCD 0x1 Use this style if your computer uses a LCD screen
    FM_OPT_MINIBAR 0x2 Use this if you plan to use toolbar only
    FM_OPT_SHOW_CUSTOMIZE 0x4 Show “customize link” in more menus, you will need to write your own handler. See demo.
    FM_OPT_SHOW_TOOLBAR 0x8 Set this option is you are planing to use the toolbar


ActivateMenu(menuInfo)[source]

Activates a menu.

Parameters:menuInfo – an instance of MenuEntryInfo.


ActivateNextMenu()[source]

Activates next menu and make sure all others are non-active.



ActivatePreviousMenu()[source]

Activates previous menu and make sure all others are non-active.



AddCheckTool(toolId, label="", bitmap1=wx.NullBitmap, bitmap2=wx.NullBitmap, shortHelp="", longHelp="")[source]

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

See also

AddTool for parameter descriptions.



AddControl(control)[source]

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

Parameters:control – the control to be added, a subclass of wx.Window (but no wx.TopLevelWindow).


AddRadioTool(toolId, label= "", bitmap1=wx.NullBitmap, bitmap2=wx.NullBitmap, shortHelp="", longHelp="")[source]

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.

See also

AddTool for parameter descriptions.



AddSeparator()[source]

Adds a separator for spacing groups of tools in toolbar.



AddTool(toolId, label="", bitmap1=wx.NullBitmap, bitmap2=wx.NullBitmap, kind=wx.ITEM_NORMAL, shortHelp="", longHelp="")[source]

Adds a tool to the toolbar.

Parameters:
  • toolId (integer) – an integer by which the tool may be identified in subsequent operations;
  • label (string) – the tool label string;
  • kind (integer) – 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;
  • bitmap1 – the primary tool bitmap, an instance of wx.Bitmap;
  • bitmap2 – the bitmap used when the tool is disabled. If it is equal to wx.NullBitmap, the disabled bitmap is automatically generated by greing out the normal one;
  • shortHelp (string) – a string 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.



Append(menu, title)[source]

Adds the item to the end of the menu bar.

Parameters:
  • menu – the menu to which we are appending a new item, an instance of FlatMenu;
  • title (string) – the menu item label, must not be empty.

See also

Insert.



AppendToolbarItem(item)[source]

Appends a tool to the FlatMenuBar.

Warning

This method is now deprecated.

See also

AddTool



ClearBitmaps(start=0)[source]

Restores a wx.NullBitmap for all the items in the menu.

Parameters:start (integer) – the index at which to start resetting the bitmaps.


CreateMoreMenu()[source]

Creates the drop down menu and populate it.



DoGiveHelp(hit)[source]

Gives tooltips and help in wx.StatusBar.

Parameters:hit – the toolbar tool currently hovered by the mouse.


DoMouseMove(pt, leftIsDown)[source]

Handles mouse move event.

Parameters:
  • pt – an instance of wx.Point;
  • leftIsDown (bool) – True is the left mouse button is down, False otherwise.


DoToolbarAction(idx)[source]

Performs a toolbar button pressed action.

Parameters:idx (integer) – the tool index in the toolbar.


DrawMoreButton(dc, state)[source]

Draws ‘more’ button to the right side of the menu bar.

Parameters:
  • dc – an instance of wx.DC;
  • state (integer) – the ‘more’ button state.

See also

MenuEntryInfo.SetState() for a list of valid menu states.



DrawToolbar(dc, rect)[source]

Draws the toolbar (if present).

Parameters:
  • dc – an instance of wx.DC;

  • rect – the toolbar client rectangle, an instance of wx.Rect.



DrawToolbarItem(dc, idx, state)[source]

Draws a toolbar item button.

Parameters:
  • dc – an instance of wx.DC;

  • idx (integer) – the tool index in the toolbar;
  • state (integer) – the button state.

See also

MenuEntryInfo.SetState() for a list of valid menu states.



FindMenu(title)[source]

Returns the index of the menu with the given title or wx.NOT_FOUND if no such menu exists in this menubar.

Parameters:title (string) – may specify either the menu title (with accelerator characters, i.e. “&File”) or just the menu label (“File”) indifferently.


FindMenuItem(id)[source]

Finds the menu item object associated with the given menu item identifier.

Parameters:id (integer) – the identifier for the sought FlatMenuItem.
Returns:The found menu item object, or None if one was not found.


GetActiveToolbarItem()[source]

Returns the active toolbar item.



GetBackgroundColour()[source]

Returns the menu bar background colour.



GetInvisibleMenuItemCount()[source]

Returns the number of invisible menu items.

Note

Valid only after the wx.PaintEvent has been processed after a resize.



GetInvisibleToolbarItemCount()[source]

Returns the number of invisible toolbar items.

Note

Valid only after the wx.PaintEvent has been processed after a resize.



GetLastVisibleMenu()[source]

Returns the index of the last visible menu on the menu bar.



GetMenu(menuIdx)[source]

Returns the menu at the specified index menuIdx (zero-based).

Parameters:menuIdx (integer) – the index of the sought menu.
Returns:The found menu item object, or None if one was not found.


GetMenuCount()[source]

Returns the number of menus in the menubar.



GetMoreMenuButtonRect()[source]

Returns a rectangle region, as an instance of wx.Rect, surrounding the menu button.



GetOptions()[source]

Returns the FlatMenuBar options, whether to show a toolbar, to use LCD screen settings etc...

See also

SetOptions for a list of valid options.



GetRenderer()[source]

Returns the renderer associated with this instance.



GetRendererManager()[source]

Returns the FlatMenuBar renderer manager.



HitTest(pt)[source]

HitTest method for FlatMenuBar.

Parameters:pt – an instance of wx.Point, specifying the hit test position.

Returns:A tuple representing one of the following combinations:
integer parameter settings
Return Tuple Description
(-1, 0) The HitTest method didn’t find any item with the specified input point pt (NoWhere = 0)
(integer, 1) A menu item has been hit, its position specified by the tuple item integer (MenuItem = 1)
(integer, 2) A toolbar item has ben hit, its position specified by the tuple item integer (ToolbarItem = 2)
(-1, 3) The drop-down area button has been hit (DropDownArrowButton = 3)


Insert(pos, menu, title)[source]

Inserts the menu at the given position into the menu bar.

Parameters:
  • pos (integer) – the position of the new menu in the menu bar;
  • menu – the menu to add, an instance of FlatMenu. FlatMenuBar owns the menu and will free it;
  • title (string) – the title of the menu.

Note

Inserting menu at position 0 will insert it in the very beginning of it, inserting at position GetMenuCount is the same as calling Append.



OnAccelCmd(event)[source]

Single function to handle any accelerator key used inside the menubar.

Parameters:event – a FlatMenuEvent event to be processed.


OnCustomizeDlg(event)[source]

Handles the customize dialog here.

Parameters:event – a FlatMenuEvent event to be processed.


OnEraseBackground(event)[source]

Handles the wx.EVT_ERASE_BACKGROUND event for FlatMenuBar.

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

Note

This method is intentionally empty to reduce flicker.



OnIdle(event)[source]

Handles the wx.EVT_IDLE event for FlatMenuBar.

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


OnLeaveMenuBar(event)[source]

Handles the wx.EVT_LEAVE_WINDOW event for FlatMenuBar.

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

Note

This method is for MSW only.



OnLeaveWindow(event)[source]

Handles the wx.EVT_LEAVE_WINDOW event for FlatMenuBar.

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

Note

This method is for GTK only.



OnLeftDown(event)[source]

Handles the wx.EVT_LEFT_DOWN event for FlatMenuBar.

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



OnLeftUp(event)[source]

Handles the wx.EVT_LEFT_UP event for FlatMenuBar.

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



OnMenuDismissed(event)[source]

Handles the EVT_FLAT_MENU_DISMISSED event for FlatMenuBar.

Parameters:event – a FlatMenuEvent event to be processed.


OnMouseMove(event)[source]

Handles the wx.EVT_MOTION event for FlatMenuBar.

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



OnPaint(event)[source]

Handles the wx.EVT_PAINT event for FlatMenuBar.

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



OnSize(event)[source]

Handles the wx.EVT_SIZE event for FlatMenuBar.

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


OnStatusBarTimer()[source]

Handles the timer expiring to delete the longHelp string in the wx.StatusBar.



PopupMoreMenu()[source]

Pops up the ‘more’ menu.



PositionAUI(mgr, fixToolbar=True)[source]

Positions the control inside a wxAUI / PyAUI frame manager.

Parameters:


ProcessMouseMoveFromMenu(pt)[source]

This function is called from child menus, this allow a child menu to pass the mouse movement event to the menu bar.

Parameters:pt – an instance of wx.Point.



Remove(pos)[source]

Removes the menu from the menu bar and returns the menu object - the caller is responsible for deleting it.

Parameters:pos (integer) – the position of the menu in the menu bar.

Note

This function may be used together with Insert to change the menubar dynamically.



RemoveHelp()[source]

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



ResetToolbarItems()[source]

Used internally.



SetBackgroundColour(colour)[source]

Sets the menu bar background colour.

Parameters:colour – a valid wx.Colour.


SetBarHeight()[source]

Recalculates the FlatMenuBar height when its settings change.



SetLCDMonitor(lcd=True)[source]

Sets whether the PC monitor is an LCD or not.

Parameters:lcd (bool) – True to use the settings appropriate for a LCD monitor, False otherwise.


SetMargin(margin)[source]

Sets the margin above and below the menu bar text.

Parameters:margin (integer) – height in pixels of the margin.


SetOptions(options)[source]

Sets the FlatMenuBar options, whether to show a toolbar, to use LCD screen settings etc...

Parameters:options (integer) – a combination of the following bits:


integer parameter settings
options Bit Hex Value Description
FM_OPT_IS_LCD 0x1 Use this style if your computer uses a LCD screen
FM_OPT_MINIBAR 0x2 Use this if you plan to use toolbar only
FM_OPT_SHOW_CUSTOMIZE 0x4 Show “customize link” in more menus, you will need to write your own handler. See demo.
FM_OPT_SHOW_TOOLBAR 0x8 Set this option is you are planing to use the toolbar


SetSpacing(spacer)[source]

Sets the spacing between the menubar items.

Parameters:spacer (integer) – number of pixels between each menu item.


SetToolbarMargin(margin)[source]

Sets the margin around the toolbar.

Parameters:margin (integer) – width in pixels of the margin around the tools in the toolbar.


SetToolbarSpacing(spacer)[source]

Sets the spacing between the toolbar tools.

Parameters:spacer (integer) – number of pixels between each tool in the toolbar.


SetUpdateInterval(interval)[source]

Sets the UpdateUI interval for toolbar items. All UpdateUI events are sent from within OnIdle handler, the default is 20 milliseconds.

Parameters:interval (integer) – the updateUI interval in milliseconds.


ShowCustomize(show=True)[source]

Shows/hides the drop-down arrow which allows customization of FlatMenu.

Parameters:show (bool) – True to show the customize menu, False to hide it.


UpdateAcceleratorTable()[source]

Updates the parent accelerator table.



UpdateItem(item)[source]

An item was modified. This function is called by FlatMenu in case an item was modified directly and not via a wx.UpdateUIEvent event.

Parameters:item – an instance of FlatMenu.
Tree

Table Of Contents

Previous topic

FlatMenu

Next topic

FlatMenuBase