pywinauto.controls.menuwrapper¶
Wrapper around Menu’s and Menu items
These wrappers allow you to work easily with menu items. You can select or click on items and check if they are checked or unchecked.
- class
pywinauto.controls.menuwrapper.
Menu
(owner_ctrl, menuhandle, is_main_menu=True, owner_item=None)¶Bases:
object
A simple wrapper around a menu handle
A menu supports methods for querying the menu and getting it’s menu items.
get_menu_path
(path, path_items=None, appdata=None, exact=False)¶Walk the items in this menu to find the item specified by a path
The path is specified by a list of items separated by ‘->’. Each item can be either a string (can include spaces) e.g. “Save As” or a zero based index of the item to return prefaced by # e.g. #1 or an ID of the item prefaced by $ specifier.
- These can be mixed as necessary. For example:
- “#0 -> Save As”,
- “$23453 -> Save As”,
- “Tools -> #0 -> Configure”
Text matching is done using a ‘best match’ fuzzy algorithm, so you don’t have to add all punctuation, ellipses, etc. ID matching is performed against wID field of MENUITEMINFO structure (https://msdn.microsoft.com/en-us/library/windows/desktop/ms647578(v=vs.85).aspx)
get_properties
()¶Return the properties for the menu as a list of dictionaries
This method is actually recursive. It calls get_properties() for each of the items. If the item has a sub menu it will call this get_properties to get the sub menu items.
item
(index, exact=False)¶Return a specific menu item
- index is the 0 based index or text of the menu item you want.
- exact is True means exact matching for item text,
- False means best matching.
item_count
()¶Return the count of items in this menu
items
()¶Return a list of all the items in this menu
- exception
pywinauto.controls.menuwrapper.
MenuInaccessible
¶Bases:
RuntimeError
Raised when a menu has handle but inaccessible.
- class
pywinauto.controls.menuwrapper.
MenuInfo
¶Bases:
object
A holder for Menu Info
- class
pywinauto.controls.menuwrapper.
MenuItem
(ctrl, menu, index, on_main_menu=False)¶Bases:
object
Wrap a menu item
click
()¶Select the menu item
This will send a message to the parent window that the item was picked.
click_input
()¶Click on the menu item in a more realistic way
If the menu is open it will click with the mouse event on the item. If the menu is not open each of it’s parent’s will be opened until the item is visible.
friendly_class_name
()¶Return friendly class name
get_properties
()¶Return the properties for the item as a dict
If this item opens a sub menu then call Menu.get_properties() to return the list of items in the sub menu. This is avialable under the ‘menu_items’ key.
index
()¶Return the index of this menu item
is_checked
()¶Return True if the item is checked.
is_enabled
()¶Return True if the item is enabled.
item_id
()¶Return the ID of this menu item
item_type
()¶Return the Type of this menu item
Main types are MF_STRING, MF_BITMAP, MF_SEPARATOR.
See https://msdn.microsoft.com/en-us/library/windows/desktop/ms647980.aspx for further information.
rectangle
()¶Get the rectangle of the menu item
select
()¶Select the menu item
This will send a message to the parent window that the item was picked.
state
()¶Return the state of this menu item
sub_menu
()¶Return the SubMenu or None if no submenu
text
()¶Return the text of this menu item
- class
pywinauto.controls.menuwrapper.
MenuItemInfo
¶Bases:
object
A holder for Menu Item Info
- exception
pywinauto.controls.menuwrapper.
MenuItemNotEnabled
¶Bases:
RuntimeError
Raised when a menu item is not enabled
pywinauto.controls.menuwrapper.
ensure_accessible
(method)¶Decorator for Menu instance methods