def GetMenuPath(self, path, path_items = None, appdata = None): """Walk the items in this menu to find the item specified by 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 the zero based index of the item to return prefaced by # e.g. #1. These can be mixed as necessary. For Example: "#0 -> Save As", "Tools -> #0 -> Configure" Text matching is done using a 'best match' fuzzy algorithm, so you don't have to add all puntuation, elipses, etc. """ if path_items is None: path_items = [] # get the first part (and remainder) parts = path.split("->", 1) current_part = parts[0] if current_part.startswith("#"): index = int(current_part[1:]) best_item = self.Item(index) else: # get the text names from the menu items if appdata is None: item_texts = [item.Text() for item in self.Items()] else: item_texts = [item['Text'] for item in appdata] # find the item that best matches the current part best_item = findbestmatch.find_best_match( current_part, item_texts, self.Items()) path_items.append(best_item) # if there are more parts - then get the next level if parts[1:]: if appdata: appdata = appdata[best_item.Index()]['MenuItems'] if best_item.SubMenu() is not None: best_item.SubMenu().GetMenuPath( "->".join(parts[1:]), path_items, appdata) return path_items
def GetMenuPath(self, path, path_items=None, appdata=None): """Walk the items in this menu to find the item specified by 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 the zero based index of the item to return prefaced by # e.g. #1. These can be mixed as necessary. For Example: "#0 -> Save As", "Tools -> #0 -> Configure" Text matching is done using a 'best match' fuzzy algorithm, so you don't have to add all puntuation, elipses, etc. """ if path_items is None: path_items = [] # get the first part (and remainder) parts = path.split("->", 1) current_part = parts[0] if current_part.startswith("#"): index = int(current_part[1:]) best_item = self.Item(index) else: # get the text names from the menu items if appdata is None: item_texts = [item.Text() for item in self.Items()] else: item_texts = [item['Text'] for item in appdata] # find the item that best matches the current part best_item = findbestmatch.find_best_match(current_part, item_texts, self.Items()) path_items.append(best_item) # if there are more parts - then get the next level if parts[1:]: if appdata: appdata = appdata[best_item.Index()]['MenuItems'] if best_item.SubMenu() is not None: best_item.SubMenu().GetMenuPath("->".join(parts[1:]), path_items, appdata) return path_items
def GetMenuPath(self, path, path_items = None, appdata = None): "Walk the items in this menu to find the item specified by path" if path_items is None: path_items = [] # get the first part (and remainder) parts = path.split("->", 1) current_part = parts[0] if current_part.startswith("#"): index = int(current_part[1:]) best_item = self.Item(index) else: # get the text names from the menu items if appdata is None: item_texts = [item.Text() for item in self.Items()] else: item_texts = [item['Text'] for item in appdata] # find the item that best matches the current part best_item = findbestmatch.find_best_match( current_part, item_texts, self.Items()) path_items.append(best_item) # if there are more parts - then get the next level if parts[1:]: if appdata: appdata = appdata[best_item.Index()]['MenuItems'] if best_item.SubMenu() is not None: best_item.SubMenu().GetMenuPath( "->".join(parts[1:]), path_items, appdata) return path_items