phoenix_title wx.lib.agw.flatmenu.FlatMenu

A Flat popup menu generic implementation.


class_hierarchy Class Hierarchy

Inheritance diagram for class FlatMenu:

method_summary Methods Summary

__init__

Default class constructor.

AddItem

Internal function to add the item to this menu. The item must

AdvanceSelection

Advance forward or backward the current selection.

Append

Appends an item to this menu.

AppendCheckItem

Adds a checkable item to the end of the menu.

AppendItem

Appends an item to this menu.

AppendMenu

Adds a pull-right submenu to the end of the menu.

AppendRadioItem

Adds a radio item to the end of the menu.

AppendSeparator

Appends a separator item to the end of this menu.

AppendSubMenu

Adds a pull-right submenu to the end of the menu.

Clear

Clears the menu items.

CloseSubMenu

Closes a child sub-menu.

DestroyItem

Deletes the menu item from the menu. If the item is a submenu, it will be

Dismiss

Dismisses the popup window.

DoAction

Performs an action based on user selection.

DrawSelection

Redraws the menu.

FindItem

Finds the menu item object associated with the given menu item identifier and,

FindMenuItemPos

Finds an item and its position inside the menu based on its id.

FindMenuItemPosSimple

Finds an item and its position inside the menu based on its id.

GetAccelArray

Returns a list filled with the accelerator entries for the menu.

GetAccelTable

Returns the menu accelerator table, an instance of AcceleratorTable.

GetAllItems

Internal function to help recurse through all the menu items.

GetBackgroundBitmap

Returns the background bitmap for this particular FlatMenu, if any.

GetBorderXWidth

Returns the menu border x-width, in pixels.

GetBorderYWidth

Returns the menu border y-width, in pixels.

GetItemFont

Returns this FlatMenuItem font.

GetItemHeight

Returns the height of a particular item, in pixels.

GetItemTextColour

Returns this FlatMenuItem foreground text colour.

GetLabel

Returns the label of a FlatMenuItem.

GetLeftMarginWidth

Returns the menu left margin width, in pixels.

GetMenuBar

Returns the menubar associated with this menu item.

GetMenuBarForSubMenu

Returns the menubar associated with this menu item.

GetMenuItemCount

Returns the number of items in the FlatMenu.

GetMenuItems

Returns the list of menu items in the menu.

GetMenuItemWidth

Returns the width of a particular item.

GetMenuRect

Returns the menu client rectangle.

GetMenuWidth

Returns the menu width in pixels.

GetNumberColumns

Returns the number of columns for a menu window.

GetRightMarginWidth

Returns the menu right margin width, in pixels.

GetSiblingGroupItem

Used internally.

HitTest

HitTest method for FlatMenu.

Insert

Inserts the given item before the position pos.

InsertItem

Inserts an item into the menu.

InsertSeparator

Inserts a separator at the given position.

OnChar

Handles key events for FlatMenu.

OnEraseBackground

Handles the wx.EVT_ERASE_BACKGROUND event for FlatMenu.

OnKeyDown

Handles the wx.EVT_KEY_DOWN event for FlatMenu.

OnKillFocus

Handles the wx.EVT_KILL_FOCUS event for FlatMenu.

OnMouseEnterWindow

Handles the wx.EVT_ENTER_WINDOW event for FlatMenu.

OnMouseLeaveWindow

Handles the wx.EVT_LEAVE_WINDOW event for FlatMenu.

OnMouseLeftDown

Handles the wx.EVT_LEFT_DOWN event for FlatMenu.

OnMouseLeftUp

Handles the wx.EVT_LEFT_UP event for FlatMenu.

OnMouseMove

Handles the wx.EVT_MOTION event for FlatMenu.

OnMouseRightDown

Handles the wx.EVT_RIGHT_DOWN event for FlatMenu.

OnPaint

Handles the wx.EVT_PAINT event for FlatMenu.

OnTimer

Handles the wx.EVT_TIMER event for FlatMenu.

OpenItemContextMenu

Open an item’s context menu (if any).

Popup

Pops up the menu.

Prepend

Prepends an item to this menu.

PrependItem

Prepends an item to this menu.

ProcessMouseLClick

Processes mouse left clicks.

ProcessMouseLClickEnd

Processes mouse left clicks.

ProcessMouseMove

Processes mouse movements.

ProcessMouseRClick

Processes mouse right clicks.

RefreshChilds

In some cases, we need to perform a recursive refresh for all opened submenu

Remove

Removes the menu item from the menu but doesn’t delete the associated menu

ResizeMenu

Resizes the menu to the correct size.

ScrollDown

Scrolls the menu down (for very tall menus).

ScrollUp

Scrolls the menu up (for very tall menus).

SendCmdEvent

Actually sends menu command events.

SendOverItem

Sends the EVT_FLAT_MENU_ITEM_MOUSE_OVER and EVT_FLAT_MENU_ITEM_MOUSE_OUT

SendUIEvent

Actually sends menu UI events.

SetBackgroundBitmap

Sets a background bitmap for this particular FlatMenu.

SetItemFont

Sets the FlatMenuItem font.

SetItemTextColour

Sets the FlatMenuItem foreground text colour.

SetLabel

Sets the label of a FlatMenuItem.

SetMenuBar

Attaches this menu to a menubar.

SetNumberColumns

Sets the number of columns for a menu window.

SetSubMenuBar

Attaches this menu to a menubar.

TryOpenSubMenu

If itemIdx is an item with submenu, open it.

TryScrollButtons

Used internally.

UpdateItem

Updates an item.

UpdateRadioGroup

Updates a group of radio items.


api Class API

class FlatMenu(FlatMenuBase)

A Flat popup menu generic implementation.


Methods

__init__(self, parent=None)

Default class constructor.

Parameters

parent – the FlatMenu parent window (used to initialize the underlying ShadowPopupWindow).



AddItem(self, menuItem)

Internal function to add the item to this menu. The item must already be in the self._itemsArr attribute.

Parameters

menuItem – an instance of FlatMenuItem.



AdvanceSelection(self, down=True)

Advance forward or backward the current selection.

Parameters

down (bool) – True to advance the selection forward, False otherwise.



Append(self, id, item, helpString="", kind=wx.ITEM_NORMAL)

Appends an item to this menu.

Parameters
  • id (integer) – the menu item identifier;

  • item (string) – the string to appear on the menu item;

  • helpString (string) – an optional help string associated with the item. By default, the handler for the EVT_FLAT_MENU_ITEM_MOUSE_OVER event displays this string in the status line;

  • 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;



AppendCheckItem(self, id, item, helpString="")

Adds a checkable item to the end of the menu.

See also

Append for the explanation of the input parameters.



AppendItem(self, menuItem)

Appends an item to this menu.

Parameters

menuItem – an instance of FlatMenuItem.



AppendMenu(self, id, item, subMenu, helpString="")

Adds a pull-right submenu to the end of the menu.

Parameters
  • id (integer) – the menu item identifier;

  • item (string) – the string to appear on the menu item;

  • subMenu – an instance of FlatMenu, the submenu to append;

  • helpString (string) – an optional help string associated with the item. By default, the handler for the EVT_FLAT_MENU_ITEM_MOUSE_OVER event displays this string in the status line.



AppendRadioItem(self, id, item, helpString="")

Adds a radio item to the end of the menu.

All consequent radio items form a group and when an item in the group is checked, all the others are automatically unchecked.

See also

Append for the explanation of the input parameters.



AppendSeparator(self)

Appends a separator item to the end of this menu.



AppendSubMenu(self, subMenu, item, helpString="")

Adds a pull-right submenu to the end of the menu.

This function is added to duplicate the API of wx.Menu.

See also

AppendMenu for an explanation of the input parameters.



Clear(self)

Clears the menu items.



CloseSubMenu(self, itemIdx, alwaysClose=False)

Closes a child sub-menu.

Parameters
  • itemIdx (integer) – the index of the item for which we want to close the submenu;

  • alwaysClose (bool) – if True, always close the submenu irrespectively of other conditions.



DestroyItem(self, item)

Deletes the menu item from the menu. If the item is a submenu, it will be deleted. Use Remove if you want to keep the submenu (for example, to reuse it later).

Parameters

item – can be either a menu item identifier or a plain FlatMenuItem.



Dismiss(self, dismissParent, resetOwner)

Dismisses the popup window.

Parameters
  • dismissParent (bool) – whether to dismiss the parent menu or not;

  • resetOwner (bool) – True to delete the link between this menu and the owner menu, False otherwise.



DoAction(self, itemIdx)

Performs an action based on user selection.

Parameters

itemIdx (integer) – the index of the item for which we want to perform the action.



DrawSelection(self, dc, oldSelection=-1)

Redraws the menu.

Parameters
  • dc – an instance of wx.DC;

  • oldSelection (integer) – if non-negative, the index representing the previous selected menu item.



FindItem(self, itemId, menu=None)

Finds the menu item object associated with the given menu item identifier and, optionally, the (sub)menu it belongs to.

Parameters
  • itemId (integer) – menu item identifier;

  • menu – if not None, it will be filled with the item’s parent menu (if the item was found).

Returns

The found menu item object, or None if one was not found.



FindMenuItemPos(self, itemId, menu=None)

Finds an item and its position inside the menu based on its id.

Parameters
  • itemId (integer) – menu item identifier;

  • menu – if not None, it will be filled with the item’s parent menu (if the item was found).

Returns

The found menu item object, or None if one was not found.



FindMenuItemPosSimple(self, item)

Finds an item and its position inside the menu based on its id.

Parameters

item – an instance of FlatMenuItem.

Returns

An integer specifying the index found menu item object, or wx.NOT_FOUND if one was not found.



GetAccelArray(self)

Returns a list filled with the accelerator entries for the menu.



GetAccelTable(self)

Returns the menu accelerator table, an instance of AcceleratorTable.



GetAllItems(self, menu=None, items=[])

Internal function to help recurse through all the menu items.

Parameters
  • menu – the menu from which we start accumulating items;

  • items (list) – the array which is recursively filled with menu items.

Returns

a list of FlatMenuItem.



GetBackgroundBitmap(self)

Returns the background bitmap for this particular FlatMenu, if any.



GetBorderXWidth(self)

Returns the menu border x-width, in pixels.



GetBorderYWidth(self)

Returns the menu border y-width, in pixels.



GetItemFont(self, itemId)

Returns this FlatMenuItem font.

Parameters

itemId (integer) – the menu item identifier.



GetItemHeight(self)

Returns the height of a particular item, in pixels.



GetItemTextColour(self, itemId)

Returns this FlatMenuItem foreground text colour.

Parameters

itemId (integer) – the menu item identifier.



GetLabel(self, itemId)

Returns the label of a FlatMenuItem.

Parameters

id (integer) – the menu item identifier;

See also

SetLabel.



GetLeftMarginWidth(self)

Returns the menu left margin width, in pixels.



GetMenuBar(self)

Returns the menubar associated with this menu item.



GetMenuBarForSubMenu(self)

Returns the menubar associated with this menu item.



GetMenuItemCount(self)

Returns the number of items in the FlatMenu.



GetMenuItems(self)

Returns the list of menu items in the menu.



GetMenuItemWidth(self, menuItem)

Returns the width of a particular item.

Parameters

menuItem – an instance of FlatMenuItem.



GetMenuRect(self)

Returns the menu client rectangle.



GetMenuWidth(self)

Returns the menu width in pixels.



GetNumberColumns(self)

Returns the number of columns for a menu window.



GetRightMarginWidth(self)

Returns the menu right margin width, in pixels.



GetSiblingGroupItem(self, item)

Used internally.

Parameters

item – an instance of FlatMenuItem.



HitTest(self, pos)

HitTest method for FlatMenu.

Parameters

pos – an instance of wx.Point, a point to test for hits.

Returns

A tuple representing one of the following combinations:

Return Tuple

Description

(0, -1)

The HitTest method didn’t find any item with the specified input point pt (MENU_HT_NONE = 0)

(1, integer)

A menu item has been hit (MENU_HT_ITEM = 1)

(2, -1)

The Scroll Up button has been hit (MENU_HT_SCROLL_UP = 2)

(3, -1)

The Scroll Down button has been hit (MENU_HT_SCROLL_DOWN = 3)



Insert(self, pos, id, item, helpString="", kind=wx.ITEM_NORMAL)

Inserts the given item before the position pos.

Parameters
  • pos (integer) – the position at which to insert the new menu item;

  • id (integer) – the menu item identifier;

  • item (string) – the string to appear on the menu item;

  • helpString (string) – an optional help string associated with the item. By default, the handler for the EVT_FLAT_MENU_ITEM_MOUSE_OVER event displays this string in the status line;

  • 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;



InsertItem(self, pos, item)

Inserts an item into the menu.

Parameters
  • pos (integer) – the position at which to insert the new menu item;

  • item – an instance of FlatMenuItem.



InsertSeparator(self, pos)

Inserts a separator at the given position.

Parameters

pos (integer) – the index at which we want to insert the separator.



OnChar(self, key)

Handles key events for FlatMenu.

Parameters

key – the keyboard key integer code.



OnEraseBackground(self, event)

Handles the wx.EVT_ERASE_BACKGROUND event for FlatMenu.

Parameters

event – a EraseEvent event to be processed.

Note

This method is intentionally empty to avoid flicker.



OnKeyDown(self, event)

Handles the wx.EVT_KEY_DOWN event for FlatMenu.

Parameters

event – a KeyEvent event to be processed.



OnKillFocus(self, event)

Handles the wx.EVT_KILL_FOCUS event for FlatMenu.

Parameters

event – a FocusEvent event to be processed.



OnMouseEnterWindow(self, event)

Handles the wx.EVT_ENTER_WINDOW event for FlatMenu.

Parameters

event – a MouseEvent event to be processed.



OnMouseLeaveWindow(self, event)

Handles the wx.EVT_LEAVE_WINDOW event for FlatMenu.

Parameters

event – a MouseEvent event to be processed.



OnMouseLeftDown(self, event)

Handles the wx.EVT_LEFT_DOWN event for FlatMenu.

Parameters

event – a MouseEvent event to be processed.



OnMouseLeftUp(self, event)

Handles the wx.EVT_LEFT_UP event for FlatMenu.

Parameters

event – a MouseEvent event to be processed.



OnMouseMove(self, event)

Handles the wx.EVT_MOTION event for FlatMenu.

Parameters

event – a MouseEvent event to be processed.



OnMouseRightDown(self, event)

Handles the wx.EVT_RIGHT_DOWN event for FlatMenu.

Parameters

event – a MouseEvent event to be processed.



OnPaint(self, event)

Handles the wx.EVT_PAINT event for FlatMenu.

Parameters

event – a PaintEvent event to be processed.



OnTimer(self, event)

Handles the wx.EVT_TIMER event for FlatMenu.

Parameters

event – a TimerEvent event to be processed.



OpenItemContextMenu(self, itemIdx)

Open an item’s context menu (if any).

Parameters

itemIdx (integer) – the index of the item for which we want to open the context menu.



Popup(self, pt, owner=None, parent=None)

Pops up the menu.

Parameters
  • pt – the point at which the menu should be popped up (an instance of wx.Point);

  • owner – the owner of the menu. The owner does not necessarly mean the menu parent, it can also be the window that popped up it;

  • parent – the menu parent window.



Prepend(self, id, item, helpString="", kind=wx.ITEM_NORMAL)

Prepends an item to this menu.

Parameters
  • id (integer) – the menu item identifier;

  • item (string) – the string to appear on the menu item;

  • helpString (string) – an optional help string associated with the item. By default, the handler for the EVT_FLAT_MENU_ITEM_MOUSE_OVER event displays this string in the status line;

  • 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;



PrependItem(self, menuItem)

Prepends an item to this menu.

Parameters

menuItem – an instance of FlatMenuItem.



ProcessMouseLClick(self, pos)

Processes mouse left clicks.

Parameters

pos – the position at which the mouse left button was pressed, an instance of wx.Point.



ProcessMouseLClickEnd(self, pos)

Processes mouse left clicks.

Parameters

pos – the position at which the mouse left button was pressed, an instance of wx.Point.



ProcessMouseMove(self, pos)

Processes mouse movements.

Parameters

pos – the position at which the mouse was moved, an instance of wx.Point.



ProcessMouseRClick(self, pos)

Processes mouse right clicks.

Parameters

pos – the position at which the mouse right button was pressed, an instance of wx.Point.



RefreshChilds(self)

In some cases, we need to perform a recursive refresh for all opened submenu from this.



Remove(self, item)

Removes the menu item from the menu but doesn’t delete the associated menu object. This allows to reuse the same item later by adding it back to the menu (especially useful with submenus).

Parameters

item – can be either a menu item identifier or a plain FlatMenuItem.



ResizeMenu(self)

Resizes the menu to the correct size.



ScrollDown(self)

Scrolls the menu down (for very tall menus).



ScrollUp(self)

Scrolls the menu up (for very tall menus).



SendCmdEvent(self, itemIdx)

Actually sends menu command events.

Parameters

itemIdx (integer) – the menu item index for which we want to send a command event.



SendOverItem(self, itemIdx, over)

Sends the EVT_FLAT_MENU_ITEM_MOUSE_OVER and EVT_FLAT_MENU_ITEM_MOUSE_OUT events.

Parameters
  • itemIdx (integer) – the menu item index for which we want to send an event;

  • over (bool) – True to send a EVT_FLAT_MENU_ITEM_MOUSE_OVER event, False to send a EVT_FLAT_MENU_ITEM_MOUSE_OUT event.



SendUIEvent(self, itemIdx)

Actually sends menu UI events.

Parameters

itemIdx (integer) – the menu item index for which we want to send a UI event.



SetBackgroundBitmap(self, bitmap=None)

Sets a background bitmap for this particular FlatMenu.

Parameters

bitmap – an instance of wx.Bitmap. Set bitmap to None if you wish to remove the background bitmap altogether.

Note

the bitmap is rescaled to fit the menu width and height.



SetItemFont(self, itemId, font=None)

Sets the FlatMenuItem font.

Parameters
  • itemId (integer) – the menu item identifier;

  • font – an instance of a valid wx.Font.



SetItemTextColour(self, itemId, colour=None)

Sets the FlatMenuItem foreground text colour.

Parameters
  • itemId (integer) – the menu item identifier;

  • colour – an instance of a valid wx.Colour.



SetLabel(self, itemId, label)

Sets the label of a FlatMenuItem.

Parameters
  • itemId (integer) – the menu item identifier;

  • label (string) – the menu item label to set.

See also

GetLabel.



SetMenuBar(self, mb)

Attaches this menu to a menubar.

Parameters

mb – an instance of FlatMenuBar.



SetNumberColumns(self, numCols)

Sets the number of columns for a menu window.

Parameters

numCols (integer) – the number of columns for this FlatMenu window.



SetSubMenuBar(self, mb)

Attaches this menu to a menubar.

Parameters

mb – an instance of FlatMenuBar.



TryOpenSubMenu(self, itemIdx, selectFirst=False)

If itemIdx is an item with submenu, open it.

Parameters
  • itemIdx (integer) – the index of the item for which we want to open the submenu;

  • selectFirst (bool) – if True, the first item of the submenu will be shown as selected.



TryScrollButtons(self, event)

Used internally.



UpdateItem(self, item)

Updates an item.

Parameters

item – an instance of FlatMenuItem.



UpdateRadioGroup(self, item)

Updates a group of radio items.

Parameters

item – an instance of FlatMenuItem.