AGW Logo

agw_title FlatMenu

A Flat popup menu generic implementation.

hierarchy Inheritance Diagram

Inheritance diagram for: FlatMenu

Inheritance diagram of FlatMenu


supclasses Known Superclasses


appearance Control Appearance


FlatMenu

FlatMenu


method_summary Methods Summary

__init__Default class constructor.
AddItemInternal function to add the item to this menu.
AdvanceSelectionAdvance forward or backward the current selection.
AppendAppends an item to this menu.
AppendCheckItemAdds a checkable item to the end of the menu.
AppendItemAppends an item to this menu.
AppendMenuAdds a pull-right submenu to the end of the menu.
AppendRadioItemAdds a radio item to the end of the menu.
AppendSeparatorAppends a separator item to the end of this menu.
AppendSubMenuAdds a pull-right submenu to the end of the menu.
ClearClears the menu items.
CloseSubMenuCloses a child sub-menu.
DeleteRemoves the menu item from the menu but doesn’t delete the associated menu object.
DestroyDeletes the menu item from the menu.
DismissDismisses the popup window.
DoActionPerforms an action based on user selection.
DrawSelectionRedraws the menu.
FindItemFinds the menu item object associated with the given menu item identifier and, optionally, the (sub)menu it belongs to.
FindMenuItemPosFinds an item and its position inside the menu based on its id.
FindMenuItemPosSimpleFinds an item and its position inside the menu based on its id.
GetAccelArrayReturns a list filled with the accelerator entries for the menu.
GetAccelTableReturns the menu accelerator table, an instance of wx.AcceleratorTable.
GetAllItemsInternal function to help recurse through all the menu items.
GetBackgroundBitmapReturns the background bitmap for this particular FlatMenu, if any.
GetBorderXWidthReturns the menu border x-width, in pixels.
GetBorderYWidthReturns the menu border y-width, in pixels.
GetItemFontReturns this FlatMenuItem font.
GetItemHeightReturns the height of a particular item, in pixels.
GetItemTextColourReturns this FlatMenuItem foreground text colour.
GetLabelReturns the label of a FlatMenuItem.
GetLeftMarginWidthReturns the menu left margin width, in pixels.
GetMenuBarReturns the menubar associated with this menu item.
GetMenuBarForSubMenuReturns the menubar associated with this menu item.
GetMenuItemCountReturns the number of items in the FlatMenu.
GetMenuItemWidthReturns the width of a particular item.
GetMenuItemsReturns the list of menu items in the menu.
GetMenuRectReturns the menu client rectangle.
GetMenuWidthReturns the menu width in pixels.
GetNumberColumnsReturns the number of columns for a menu window.
GetRightMarginWidthReturns the menu right margin width, in pixels.
GetSiblingGroupItemUsed internally.
HitTestHitTest method for FlatMenu.
InsertInserts the given item before the position pos.
InsertItemInserts an item into the menu.
InsertSeparatorInserts a separator at the given position.
OnCharHandles key events for FlatMenu.
OnEraseBackgroundHandles the wx.EVT_ERASE_BACKGROUND event for FlatMenu.
OnKeyDownHandles the wx.EVT_KEY_DOWN event for FlatMenu.
OnKillFocusHandles the wx.EVT_KILL_FOCUS event for FlatMenu.
OnMouseEnterWindowHandles the wx.EVT_ENTER_WINDOW event for FlatMenu.
OnMouseLeaveWindowHandles the wx.EVT_LEAVE_WINDOW event for FlatMenu.
OnMouseLeftDownHandles the wx.EVT_LEFT_DOWN event for FlatMenu.
OnMouseLeftUpHandles the wx.EVT_LEFT_UP event for FlatMenu.
OnMouseMoveHandles the wx.EVT_MOTION event for FlatMenu.
OnMouseRightDownHandles the wx.EVT_RIGHT_DOWN event for FlatMenu.
OnPaintHandles the wx.EVT_PAINT event for FlatMenu.
OnTimerHandles the wx.EVT_TIMER event for FlatMenu.
OpenItemContextMenuOpen an item’s context menu (if any).
PopupPops up the menu.
PrependPrepends an item to this menu.
PrependItemPrepends an item to this menu.
ProcessMouseLClickProcesses mouse left clicks.
ProcessMouseLClickEndProcesses mouse left clicks.
ProcessMouseMoveProcesses mouse movements.
ProcessMouseRClickProcesses mouse right clicks.
RefreshChildsIn some cases, we need to perform a recursive refresh for all opened submenu
RemoveRemoves the menu item from the menu but doesn’t delete the associated menu object.
ResizeMenuResizes the menu to the correct size.
ScrollDownScrolls the menu down (for very tall menus).
ScrollUpScrolls the menu up (for very tall menus).
SendCmdEventActually sends menu command events.
SendOverItemSends the EVT_FLAT_MENU_ITEM_MOUSE_OVER and EVT_FLAT_MENU_ITEM_MOUSE_OUT
SendUIEventActually sends menu UI events.
SetBackgroundBitmapSets a background bitmap for this particular FlatMenu.
SetItemFontSets the FlatMenuItem font.
SetItemTextColourSets the FlatMenuItem foreground text colour.
SetLabelSets the label of a FlatMenuItem.
SetMenuBarAttaches this menu to a menubar.
SetNumberColumnsSets the number of columns for a menu window.
SetSubMenuBarAttaches this menu to a menubar.
TryOpenSubMenuIf itemIdx is an item with submenu, open it.
TryScrollButtonsUsed internally.
UpdateItemUpdates an item.
UpdateRadioGroupUpdates a group of radio items.
_DestroyByIdUsed internally.
_RemoveByIdUsed internally.

API Class API

class FlatMenu(FlatMenuBase)[source]

A Flat popup menu generic implementation.



__init__(parent=None)[source]

Default class constructor.

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


AddItem(menuItem)[source]

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(down=True)[source]

Advance forward or backward the current selection.

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


Append(id, item, helpString="", kind=wx.ITEM_NORMAL)[source]

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(id, item, helpString='')[source]

Adds a checkable item to the end of the menu.

See also

Append for the explanation of the input parameters.



AppendItem(menuItem)[source]

Appends an item to this menu.

Parameters:menuItem – an instance of FlatMenuItem.


AppendMenu(id, item, subMenu, helpString='')[source]

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(id, item, helpString='')[source]

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()[source]

Appends a separator item to the end of this menu.



AppendSubMenu(subMenu, item, helpString='')[source]

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()[source]

Clears the menu items.



CloseSubMenu(itemIdx, alwaysClose=False)[source]

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.


Delete(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.


Destroy(item)[source]

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(dismissParent, resetOwner)[source]

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(itemIdx)[source]

Performs an action based on user selection.

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


DrawSelection(dc, oldSelection=-1)[source]

Redraws the menu.

Parameters:
  • dc – an instance of wx.DC;
  • oldSelection (integer) – if non-negative, the index representing the previous selected menu item.


FindItem(itemId, menu=None)[source]

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(itemId, menu=None)[source]

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(item)[source]

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()[source]

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



GetAccelTable()[source]

Returns the menu accelerator table, an instance of wx.AcceleratorTable.



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

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()[source]

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



GetBorderXWidth()[source]

Returns the menu border x-width, in pixels.



GetBorderYWidth()[source]

Returns the menu border y-width, in pixels.



GetItemFont(itemId)[source]

Returns this FlatMenuItem font.

Parameters:itemId (integer) – the menu item identifier.


GetItemHeight()[source]

Returns the height of a particular item, in pixels.



GetItemTextColour(itemId)[source]

Returns this FlatMenuItem foreground text colour.

Parameters:itemId (integer) – the menu item identifier.


GetLabel(itemId)[source]

Returns the label of a FlatMenuItem.

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

See also

SetLabel.



GetLeftMarginWidth()[source]

Returns the menu left margin width, in pixels.



GetMenuBar()[source]

Returns the menubar associated with this menu item.



GetMenuBarForSubMenu()[source]

Returns the menubar associated with this menu item.



GetMenuItemCount()[source]

Returns the number of items in the FlatMenu.



GetMenuItemWidth(menuItem)[source]

Returns the width of a particular item.

Parameters:menuItem – an instance of FlatMenuItem.


GetMenuItems()[source]

Returns the list of menu items in the menu.



GetMenuRect()[source]

Returns the menu client rectangle.



GetMenuWidth()[source]

Returns the menu width in pixels.



GetNumberColumns()[source]

Returns the number of columns for a menu window.



GetRightMarginWidth()[source]

Returns the menu right margin width, in pixels.



GetSiblingGroupItem(item)[source]

Used internally.

Parameters:item – an instance of FlatMenuItem.


HitTest(pos)[source]

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:
integer parameter settings
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(pos, id, item, helpString="", kind=wx.ITEM_NORMAL)[source]

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(pos, item)[source]

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(pos)[source]

Inserts a separator at the given position.

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


OnChar(key)[source]

Handles key events for FlatMenu.

Parameters:key – the keyboard key integer code.


OnEraseBackground(event)[source]

Handles the wx.EVT_ERASE_BACKGROUND event for FlatMenu.

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

Note

This method is intentionally empty to avoid flicker.



OnKeyDown(event)[source]

Handles the wx.EVT_KEY_DOWN event for FlatMenu.

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


OnKillFocus(event)[source]

Handles the wx.EVT_KILL_FOCUS event for FlatMenu.

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


OnMouseEnterWindow(event)[source]

Handles the wx.EVT_ENTER_WINDOW event for FlatMenu.

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


OnMouseLeaveWindow(event)[source]

Handles the wx.EVT_LEAVE_WINDOW event for FlatMenu.

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



OnMouseLeftDown(event)[source]

Handles the wx.EVT_LEFT_DOWN event for FlatMenu.

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



OnMouseLeftUp(event)[source]

Handles the wx.EVT_LEFT_UP event for FlatMenu.

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



OnMouseMove(event)[source]

Handles the wx.EVT_MOTION event for FlatMenu.

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



OnMouseRightDown(event)[source]

Handles the wx.EVT_RIGHT_DOWN event for FlatMenu.

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



OnPaint(event)[source]

Handles the wx.EVT_PAINT event for FlatMenu.

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


OnTimer(event)[source]

Handles the wx.EVT_TIMER event for FlatMenu.

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


OpenItemContextMenu(itemIdx)[source]

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(pt, owner=None, parent=None)[source]

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(id, item, helpString="", kind=wx.ITEM_NORMAL)[source]

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(menuItem)[source]

Prepends an item to this menu.

Parameters:menuItem – an instance of FlatMenuItem.


ProcessMouseLClick(pos)[source]

Processes mouse left clicks.

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



ProcessMouseLClickEnd(pos)[source]

Processes mouse left clicks.

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



ProcessMouseMove(pos)[source]

Processes mouse movements.

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



ProcessMouseRClick(pos)[source]

Processes mouse right clicks.

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



RefreshChilds()[source]

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



Remove(item)[source]

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()[source]

Resizes the menu to the correct size.



ScrollDown()[source]

Scrolls the menu down (for very tall menus).



ScrollUp()[source]

Scrolls the menu up (for very tall menus).



SendCmdEvent(itemIdx)[source]

Actually sends menu command events.

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


SendOverItem(itemIdx, over)[source]

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(itemIdx)[source]

Actually sends menu UI events.

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


SetBackgroundBitmap(bitmap=None)[source]

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(itemId, font=None)[source]

Sets the FlatMenuItem font.

Parameters:
  • itemId (integer) – the menu item identifier;
  • font – an instance of a valid wx.Font.


SetItemTextColour(itemId, colour=None)[source]

Sets the FlatMenuItem foreground text colour.

Parameters:
  • itemId (integer) – the menu item identifier;
  • colour – an instance of a valid wx.Colour.


SetLabel(itemId, label)[source]

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(mb)[source]

Attaches this menu to a menubar.

Parameters:mb – an instance of FlatMenuBar.


SetNumberColumns(numCols)[source]

Sets the number of columns for a menu window.

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


SetSubMenuBar(mb)[source]

Attaches this menu to a menubar.

Parameters:mb – an instance of FlatMenuBar.


TryOpenSubMenu(itemIdx, selectFirst=False)[source]

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(event)[source]

Used internally.



UpdateItem(item)[source]

Updates an item.

Parameters:item – an instance of FlatMenuItem.


UpdateRadioGroup(item)[source]

Updates a group of radio items.

Parameters:item – an instance of FlatMenuItem.
Tree

Table Of Contents

Previous topic

FileHistory

Next topic

FlatMenuBar