A Flat popup menu generic implementation.
wx.lib.agw.flatmenu.FlatMenuBase
Default class constructor. |
|
Internal function to add the item to this menu. The item must |
|
Advance forward or backward the current selection. |
|
Appends an item to this menu. |
|
Adds a checkable item to the end of the menu. |
|
Appends an item to this menu. |
|
Adds a pull-right submenu to the end of the menu. |
|
Adds a radio item to the end of the menu. |
|
Appends a separator item to the end of this menu. |
|
Adds a pull-right submenu to the end of the menu. |
|
Clears the menu items. |
|
Closes a child sub-menu. |
|
Destroy(self) -> bool |
|
Deletes the menu item from the menu. If the item is a submenu, it will be |
|
Dismisses the popup window. |
|
Performs an action based on user selection. |
|
Redraws the menu. |
|
Finds the menu item object associated with the given menu item identifier and, |
|
Finds an item and its position inside the menu based on its id. |
|
Finds an item and its position inside the menu based on its id. |
|
Returns a list filled with the accelerator entries for the menu. |
|
Returns the menu accelerator table, an instance of |
|
Internal function to help recurse through all the menu items. |
|
Returns the background bitmap for this particular |
|
Returns the menu border x-width, in pixels. |
|
Returns the menu border y-width, in pixels. |
|
Returns this |
|
Returns the height of a particular item, in pixels. |
|
Returns this |
|
Returns the label of a |
|
Returns the menu left margin width, in pixels. |
|
Returns the menubar associated with this menu item. |
|
Returns the menubar associated with this menu item. |
|
Returns the number of items in the |
|
Returns the list of menu items in the menu. |
|
Returns the width of a particular item. |
|
Returns the menu client rectangle. |
|
Returns the menu width in pixels. |
|
Returns the number of columns for a menu window. |
|
Returns the menu right margin width, in pixels. |
|
Used internally. |
|
HitTest method for |
|
Inserts the given item before the position pos. |
|
Inserts an item into the menu. |
|
Inserts a separator at the given position. |
|
Handles key events for |
|
Handles the |
|
Handles the |
|
Handles the |
|
Handles the |
|
Handles the |
|
Handles the |
|
Handles the |
|
Handles the |
|
Handles the |
|
Handles the |
|
Handles the |
|
Open an item’s context menu (if any). |
|
Pops up the menu. |
|
Prepends an item to this menu. |
|
Prepends an item to this menu. |
|
Processes mouse left clicks. |
|
Processes mouse left clicks. |
|
Processes mouse movements. |
|
Processes mouse right clicks. |
|
In some cases, we need to perform a recursive refresh for all opened submenu |
|
Removes the menu item from the menu but doesn’t delete the associated menu |
|
Resizes the menu to the correct size. |
|
Scrolls the menu down (for very tall menus). |
|
Scrolls the menu up (for very tall menus). |
|
Actually sends menu command events. |
|
Sends the |
|
Actually sends menu UI events. |
|
Sets a background bitmap for this particular |
|
Sets the |
|
Sets the |
|
Sets the label of a |
|
Attaches this menu to a menubar. |
|
Sets the number of columns for a menu window. |
|
Attaches this menu to a menubar. |
|
If itemIdx is an item with submenu, open it. |
|
Used internally. |
|
Updates an item. |
|
Updates a group of radio items. |
FlatMenu
(FlatMenuBase)¶A Flat popup menu generic implementation.
__init__
(self, parent=None)¶Default class constructor.
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.
menuItem – an instance of FlatMenuItem
.
AdvanceSelection
(self, down=True)¶Advance forward or backward the current selection.
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.
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.
menuItem – an instance of FlatMenuItem
.
AppendMenu
(self, id, item, subMenu, helpString="")¶Adds a pull-right submenu to the end of the menu.
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.
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.
Destroy
(self, *args, **kwargs)¶Destroy(self) -> bool
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).
item – can be either a menu item identifier or a plain FlatMenuItem
.
Dismiss
(self, dismissParent, resetOwner)¶Dismisses the popup window.
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.
itemIdx (integer) – the index of the item for which we want to perform the action.
DrawSelection
(self, dc, oldSelection=-1)¶Redraws the menu.
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.
itemId (integer) – menu item identifier;
menu – if not None
, it will be filled with the item’s parent menu
(if the item was found).
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.
itemId (integer) – menu item identifier;
menu – if not None
, it will be filled with the item’s parent menu
(if the item was found).
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.
item – an instance of FlatMenuItem
.
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.
menu – the menu from which we start accumulating items;
items (list) – the array which is recursively filled with menu items.
a list of FlatMenuItem
.
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.
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.
itemId (integer) – the menu item identifier.
GetLabel
(self, itemId)¶Returns the label of a FlatMenuItem
.
id (integer) – the menu item identifier;
See also
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.
GetMenuItems
(self)¶Returns the list of menu items in the menu.
GetMenuItemWidth
(self, menuItem)¶Returns the width of a particular item.
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.
item – an instance of FlatMenuItem
.
HitTest
(self, pos)¶HitTest method for FlatMenu
.
pos – an instance of wx.Point
, a point to test for hits.
A tuple representing one of the following combinations:
Return Tuple |
Description |
---|---|
(0, -1) |
The |
(1, integer) |
A menu item has been hit ( |
(2, -1) |
The Scroll Up button has been hit ( |
(3, -1) |
The Scroll Down button has been hit ( |
Insert
(self, pos, id, item, helpString="", kind=wx.ITEM_NORMAL)¶Inserts the given item before the position pos.
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.
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.
pos (integer) – the index at which we want to insert the separator.
OnChar
(self, key)¶Handles key events for FlatMenu
.
key – the keyboard key integer code.
OnEraseBackground
(self, event)¶Handles the wx.EVT_ERASE_BACKGROUND
event for FlatMenu
.
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
.
event – a KeyEvent
event to be processed.
OnKillFocus
(self, event)¶Handles the wx.EVT_KILL_FOCUS
event for FlatMenu
.
event – a FocusEvent
event to be processed.
OnMouseEnterWindow
(self, event)¶Handles the wx.EVT_ENTER_WINDOW
event for FlatMenu
.
event – a MouseEvent
event to be processed.
OnMouseLeaveWindow
(self, event)¶Handles the wx.EVT_LEAVE_WINDOW
event for FlatMenu
.
event – a MouseEvent
event to be processed.
OnMouseLeftDown
(self, event)¶Handles the wx.EVT_LEFT_DOWN
event for FlatMenu
.
event – a MouseEvent
event to be processed.
OnMouseLeftUp
(self, event)¶Handles the wx.EVT_LEFT_UP
event for FlatMenu
.
event – a MouseEvent
event to be processed.
OnMouseMove
(self, event)¶Handles the wx.EVT_MOTION
event for FlatMenu
.
event – a MouseEvent
event to be processed.
OnMouseRightDown
(self, event)¶Handles the wx.EVT_RIGHT_DOWN
event for FlatMenu
.
event – a MouseEvent
event to be processed.
OnPaint
(self, event)¶Handles the wx.EVT_PAINT
event for FlatMenu
.
event – a PaintEvent
event to be processed.
OnTimer
(self, event)¶Handles the wx.EVT_TIMER
event for FlatMenu
.
event – a TimerEvent
event to be processed.
OpenItemContextMenu
(self, itemIdx)¶Open an item’s context menu (if any).
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.
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.
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.
menuItem – an instance of FlatMenuItem
.
ProcessMouseLClick
(self, pos)¶Processes mouse left clicks.
pos – the position at which the mouse left button was pressed,
an instance of wx.Point
.
ProcessMouseLClickEnd
(self, pos)¶Processes mouse left clicks.
pos – the position at which the mouse left button was pressed,
an instance of wx.Point
.
ProcessMouseMove
(self, pos)¶Processes mouse movements.
pos – the position at which the mouse was moved, an instance of wx.Point
.
ProcessMouseRClick
(self, pos)¶Processes mouse right clicks.
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).
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.
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.
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.
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
.
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.
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.
itemId (integer) – the menu item identifier;
colour – an instance of a valid wx.Colour
.
SetLabel
(self, itemId, label)¶Sets the label of a FlatMenuItem
.
itemId (integer) – the menu item identifier;
label (string) – the menu item label to set.
See also
SetMenuBar
(self, mb)¶Attaches this menu to a menubar.
mb – an instance of FlatMenuBar
.
SetNumberColumns
(self, numCols)¶Sets the number of columns for a menu window.
numCols (integer) – the number of columns for this FlatMenu
window.
SetSubMenuBar
(self, mb)¶Attaches this menu to a menubar.
mb – an instance of FlatMenuBar
.
TryOpenSubMenu
(self, itemIdx, selectFirst=False)¶If itemIdx is an item with submenu, open it.
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.
item – an instance of FlatMenuItem
.
UpdateRadioGroup
(self, item)¶Updates a group of radio items.
item – an instance of FlatMenuItem
.