phoenix_title wx.lib.agw.flatmenu.FlatMenuBar

Implements the generic owner-drawn menu bar for FlatMenu.


class_hierarchy Class Hierarchy

Inheritance diagram for class FlatMenuBar:

appearance Control Appearance


wxMSW

wxMSW

wxMAC

wxMAC

wxGTK

wxGTK


super_classes Known Superclasses

wx.Panel


method_summary Methods Summary

__init__

Default class constructor.

ActivateMenu

Activates a menu.

ActivateNextMenu

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

ActivatePreviousMenu

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

AddCheckTool

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

AddControl

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

AddRadioTool

Adds a new radio tool to the toolbar.

AddSeparator

Adds a separator for spacing groups of tools in toolbar.

AddTool

Adds a tool to the toolbar.

Append

Adds the item to the end of the menu bar.

AppendToolbarItem

Appends a tool to the FlatMenuBar.

ClearBitmaps

Restores a NullBitmap for all the items in the menu.

CreateMoreMenu

Creates the drop down menu and populate it.

DoGiveHelp

Gives tooltips and help in StatusBar.

DoMouseMove

Handles mouse move event.

DoToolbarAction

Performs a toolbar button pressed action.

DrawMoreButton

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

DrawToolbar

Draws the toolbar (if present).

DrawToolbarItem

Draws a toolbar item button.

FindMenu

Returns the index of the menu with the given title or wx.NOT_FOUND if

FindMenuItem

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

GetActiveToolbarItem

Returns the active toolbar item.

GetBackgroundColour

Returns the menu bar background colour.

GetInvisibleMenuItemCount

Returns the number of invisible menu items.

GetInvisibleToolbarItemCount

Returns the number of invisible toolbar items.

GetLastVisibleMenu

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

GetMenu

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

GetMenuCount

Returns the number of menus in the menubar.

GetMoreMenuButtonRect

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

GetOptions

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

GetRenderer

Returns the renderer associated with this instance.

GetRendererManager

Returns the FlatMenuBar renderer manager.

HitTest

HitTest method for FlatMenuBar.

Insert

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

OnAccelCmd

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

OnCustomizeDlg

Handles the customize dialog here.

OnEraseBackground

Handles the wx.EVT_ERASE_BACKGROUND event for FlatMenuBar.

OnIdle

Handles the wx.EVT_IDLE event for FlatMenuBar.

OnLeaveMenuBar

Handles the wx.EVT_LEAVE_WINDOW event for FlatMenuBar.

OnLeaveWindow

Handles the wx.EVT_LEAVE_WINDOW event for FlatMenuBar.

OnLeftDown

Handles the wx.EVT_LEFT_DOWN event for FlatMenuBar.

OnLeftUp

Handles the wx.EVT_LEFT_UP event for FlatMenuBar.

OnMenuDismissed

Handles the EVT_FLAT_MENU_DISMISSED event for FlatMenuBar.

OnMouseMove

Handles the wx.EVT_MOTION event for FlatMenuBar.

OnPaint

Handles the wx.EVT_PAINT event for FlatMenuBar.

OnSize

Handles the wx.EVT_SIZE event for FlatMenuBar.

OnStatusBarTimer

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

PopupMoreMenu

Pops up the ‘more’ menu.

PositionAUI

Positions the control inside a wxAUI / PyAUI frame manager.

ProcessMouseMoveFromMenu

This function is called from child menus, this allow a child menu to

Remove

Removes the menu from the menu bar and returns the menu object - the

RemoveHelp

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

ResetToolbarItems

Used internally.

SetBackgroundColour

Sets the menu bar background colour.

SetBarHeight

Recalculates the FlatMenuBar height when its settings change.

SetLCDMonitor

Sets whether the PC monitor is an LCD or not.

SetMargin

Sets the margin above and below the menu bar text.

SetOptions

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

SetSpacing

Sets the spacing between the menubar items.

SetToolbarMargin

Sets the margin around the toolbar.

SetToolbarSpacing

Sets the spacing between the toolbar tools.

SetUpdateInterval

Sets the UpdateUI interval for toolbar items. All UpdateUI events are

ShowCustomize

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

UpdateAcceleratorTable

Updates the parent accelerator table.

UpdateItem

An item was modified. This function is called by FlatMenu in case


api Class API

class FlatMenuBar(wx.Panel)

Implements the generic owner-drawn menu bar for FlatMenu.


Methods

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

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):

    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:

    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(self, menuInfo)

Activates a menu.

Parameters

menuInfo – an instance of wx.MenuEntryInfo.



ActivateNextMenu(self)

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



ActivatePreviousMenu(self)

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



AddCheckTool(self, toolId, label="", bitmap1=wx.NullBitmap, bitmap2=wx.NullBitmap, shortHelp="", longHelp="")

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

See also

AddTool for parameter descriptions.



AddControl(self, control)

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 TopLevelWindow).



AddRadioTool(self, toolId, label= "", bitmap1=wx.NullBitmap, bitmap2=wx.NullBitmap, shortHelp="", longHelp="")

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(self)

Adds a separator for spacing groups of tools in toolbar.



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

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 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 StatusBar (if any) of the parent frame when the mouse pointer is inside the tool.



Append(self, menu, title)

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(self, item)

Appends a tool to the FlatMenuBar.

Deprecated since version 0.9.5: This method is now deprecated.

See also

AddTool



ClearBitmaps(self, start=0)

Restores a NullBitmap for all the items in the menu.

Parameters

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



CreateMoreMenu(self)

Creates the drop down menu and populate it.



DoGiveHelp(self, hit)

Gives tooltips and help in StatusBar.

Parameters

hit – the toolbar tool currently hovered by the mouse.



DoMouseMove(self, pt, leftIsDown)

Handles mouse move event.

Parameters
  • pt – an instance of wx.Point;

  • leftIsDown (bool) – True is the left mouse button is down, False otherwise.



DoToolbarAction(self, idx)

Performs a toolbar button pressed action.

Parameters

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



DrawMoreButton(self, dc, state)

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

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



DrawToolbar(self, dc, rect)

Draws the toolbar (if present).

Parameters
  • dc – an instance of wx.DC;

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



DrawToolbarItem(self, dc, idx, state)

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

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



FindMenu(self, title)

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(self, id)

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(self)

Returns the active toolbar item.



GetBackgroundColour(self)

Returns the menu bar background colour.



GetInvisibleMenuItemCount(self)

Returns the number of invisible menu items.

Note

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



GetInvisibleToolbarItemCount(self)

Returns the number of invisible toolbar items.

Note

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



GetLastVisibleMenu(self)

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



GetMenu(self, menuIdx)

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(self)

Returns the number of menus in the menubar.



GetMoreMenuButtonRect(self)

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



GetOptions(self)

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(self)

Returns the renderer associated with this instance.



GetRendererManager(self)

Returns the FlatMenuBar renderer manager.



HitTest(self, pt)

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:

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(self, pos, menu, title)

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(self, event)

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

Parameters

event – a FlatMenuEvent event to be processed.



OnCustomizeDlg(self, event)

Handles the customize dialog here.

Parameters

event – a FlatMenuEvent event to be processed.



OnEraseBackground(self, event)

Handles the wx.EVT_ERASE_BACKGROUND event for FlatMenuBar.

Parameters

event – a EraseEvent event to be processed.

Note

This method is intentionally empty to reduce flicker.



OnIdle(self, event)

Handles the wx.EVT_IDLE event for FlatMenuBar.

Parameters

event – a IdleEvent event to be processed.



OnLeaveMenuBar(self, event)

Handles the wx.EVT_LEAVE_WINDOW event for FlatMenuBar.

Parameters

event – a MouseEvent event to be processed.

Note

This method is for MSW only.



OnLeaveWindow(self, event)

Handles the wx.EVT_LEAVE_WINDOW event for FlatMenuBar.

Parameters

event – a MouseEvent event to be processed.

Note

This method is for GTK only.



OnLeftDown(self, event)

Handles the wx.EVT_LEFT_DOWN event for FlatMenuBar.

Parameters

event – a MouseEvent event to be processed.



OnLeftUp(self, event)

Handles the wx.EVT_LEFT_UP event for FlatMenuBar.

Parameters

event – a MouseEvent event to be processed.



OnMenuDismissed(self, event)

Handles the EVT_FLAT_MENU_DISMISSED event for FlatMenuBar.

Parameters

event – a FlatMenuEvent event to be processed.



OnMouseMove(self, event)

Handles the wx.EVT_MOTION event for FlatMenuBar.

Parameters

event – a MouseEvent event to be processed.



OnPaint(self, event)

Handles the wx.EVT_PAINT event for FlatMenuBar.

Parameters

event – a PaintEvent event to be processed.



OnSize(self, event)

Handles the wx.EVT_SIZE event for FlatMenuBar.

Parameters

event – a wx.SizeEvent event to be processed.



OnStatusBarTimer(self)

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



PopupMoreMenu(self)

Pops up the ‘more’ menu.



PositionAUI(self, mgr, fixToolbar=True)

Positions the control inside a wxAUI / PyAUI frame manager.

Parameters
  • mgr – an instance of AuiManager or framemanager;

  • fixToolbar (bool) – True if FlatMenuBar can not be floated.



ProcessMouseMoveFromMenu(self, pt)

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(self, pos)

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(self)

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



ResetToolbarItems(self)

Used internally.



SetBackgroundColour(self, colour)

Sets the menu bar background colour.

Parameters

colour – a valid wx.Colour.



SetBarHeight(self)

Recalculates the FlatMenuBar height when its settings change.



SetLCDMonitor(self, lcd=True)

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(self, margin)

Sets the margin above and below the menu bar text.

Parameters

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



SetOptions(self, options)

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

Parameters

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

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(self, spacer)

Sets the spacing between the menubar items.

Parameters

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



SetToolbarMargin(self, margin)

Sets the margin around the toolbar.

Parameters

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



SetToolbarSpacing(self, spacer)

Sets the spacing between the toolbar tools.

Parameters

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



SetUpdateInterval(self, interval)

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(self, show=True)

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(self)

Updates the parent accelerator table.



UpdateItem(self, item)

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

Parameters

item – an instance of FlatMenu.