PopupMenu (hwx.gui)#
- class PopupMenu(widget=None, onPopup=None, items=None, fontSize=None, advancedTooltip=None, **kwds)#
Bases:
Widget
A PopupMenu Widget.
The PopupMenu is a specialized control that has the abilty of being selected. You can add items and commands to the popup menu.
# Name
Type
property
# Name
Description
clear
(self)Remove all items.
getIDs
(self)insertItem
(self, text, menu=None, icon=None, command=None, enabled=True, visible=True, accel=None, checked=None, advancedTooltip=None)Inserts item and command into menu.
insertMenu
(self, text, menu=None)Adds and returns a cascading menu.
insertSeparator
(self)Inserts a separator in the Pop menu.
insertWidget
(self, widget)Inserts a widget into the menu
popup
(self, event=None)Shows the Popup menu.
setItemEnabled
(self, index, enabled=True)Enables or Disables the menu item at the specified index.
Example
from hwx import gui # - callbacks -------------------------------------------------------------- def onItem1(): gui.tellUser("onItem1 selected") def onItem2(): gui.tellUser("onItem2 selected") def onItem3(): gui.tellUser("onItem3 selected") def onClick(event): # This method is called when the menu button is pushed. button.text = "Un-display the menu" if button.checked else "Display the menu" popup.show() if button.checked else popup.hide() # Create a button that displays a pop up menu, generate a message dialog box # when each menu item is selected button = gui.ToggleButton('Display the menu', command=onClick, ) # Create a empty pop-up menu, populate it with some items popup = gui.PopupMenu() popup.insertItem("Item 1", command=onItem1) popup.insertItem("Item 2", command=onItem2) popup.insertItem("Item 3", command=onItem3) popup.hide() frame = gui.HFrame((button, "<->"), 5, popup) show(frame)
- clear()#
Remove all items.
- insertItem(text, menu=None, icon=None, command=None, enabled=True, visible=True, accel=None, checked=None, advancedTooltip=None)#
Inserts item and command into menu.
- Parameters:
text (str) – The item text to be displayed.
menu (PopupMenu) – The menu object to insert.
icon (str) – The icon file to be inserted on the left side of text.
command (callback) – The callback method to be executed when item is clicked.
enabled (bool) – Determines whether to enable the inserted item.
visible (bool) – Determines whether the inserted item is visible.
accel (str) – Keyboard accelerator to execute the command (e.g. ‘Del’)
checked (bool) – Determines if the item is checkable. True or False makes it checkable.
advancedTooltip (str) – UUID to display advanced tooltips.
- Returns:
The index where the item has been inserted.
- Return type:
int
- insertWidget(widget)#
Inserts a widget into the menu
- insertSeparator()#
Inserts a separator in the Pop menu.
- property numOfItems#
Returns the number of items in the popup menu.
- setItemEnabled(index, enabled=True)#
Enables or Disables the menu item at the specified index.
- insertMenu(text, menu=None)#
Adds and returns a cascading menu.
- popup(event=None)#
Shows the Popup menu.
- Parameters:
event (MouseEvent) – The event to get the mouse position.