def select_menuitem_action(ctrl, path, items=None): "Select the menuitem specifed in path" verify_enabled(ctrl) # if the menu items haven't been passed in then # get them from the window if not items: items = ctrl.MenuItems # get the text names from the menu items item_texts = [item['Text'] for item in items] # get the first part (and remainder) parts = path.split("->", 1) current_part = parts[0] # find the item that best matches the current part item = findbestmatch.find_best_match(current_part, item_texts, items) # if there are more parts - then get the next level if parts[1:]: select_menuitem_action(ctrl, "->".join(parts[1:]), item['MenuItems']) else: # unfortunately this is not always reliable :-( #if item['State'] & MF_DISABLED or item['State'] & MF_GRAYED: # raise "TODO - replace with correct exception: " \ # "Menu item is not enabled" #ctrl.PostMessage(WM_MENURBUTTONUP, win32functions.GetMenu(ctrl)) #ctrl.PostMessage(WM_COMMAND, 0, item['ID']) ctrl.NotifyMenuSelect(item['ID']) time.sleep(delay_after_menuselect)
def select_menuitem_action(ctrl, path, items = None): "Select the menuitem specifed in path" verify_enabled(ctrl) # if the menu items haven't been passed in then # get them from the window if not items: items = ctrl.MenuItems # get the text names from the menu items item_texts = [item['Text'] for item in items] # get the first part (and remainder) parts = path.split("->", 1) current_part = parts[0] # find the item that best matches the current part item = findbestmatch.find_best_match(current_part, item_texts, items) # if there are more parts - then get the next level if parts[1:]: select_menuitem_action(ctrl, "->".join(parts[1:]), item['MenuItems']) else: # unfortunately this is not always reliable :-( #if item['State'] & MF_DISABLED or item['State'] & MF_GRAYED: # raise "TODO - replace with correct exception: " \ # "Menu item is not enabled" #ctrl.PostMessage(WM_MENURBUTTONUP, win32functions.GetMenu(ctrl)) #ctrl.PostMessage(WM_COMMAND, 0, item['ID']) ctrl.NotifyMenuSelect(item['ID']) time.sleep(delay_after_menuselect)
def select_tab_action(ctrl, tab): "Select the specified tab on teh tab control" verify_enabled(ctrl) if isinstance(tab, basestring): # find the string in the tab control bestText = findbestmatch.find_best_match(tab, ctrl.Texts, ctrl.Texts) tab = ctrl.Texts.index(bestText) - 1 ctrl.SendMessage(win32defines.TCM_SETCURFOCUS, tab)