def __init__(self, controller: Any) -> None: self.controller = controller widths = [(len(binding['help_text']) + 4, len(", ".join(binding['keys']))) for binding in KEY_BINDINGS.values()] max_widths = [max(width) for width in zip(*widths)] self.width = sum(max_widths) self.log = urwid.SimpleFocusListWalker([urwid.Text('')] + [ urwid.LineBox( urwid.Columns([ urwid.Text(binding['help_text']), (max_widths[1], urwid.Text(", ".join(binding['keys']))) ], dividechars=2), tlcorner='', brcorner='', trcorner='', blcorner='', rline=' ', lline=' ', bline='-', tline='', ) for binding in KEY_BINDINGS.values() ]) super(HelpView, self).__init__(self.log)
def __init__(self, controller: Any) -> None: self.controller = controller widths = [(len(binding['help_text']) + 4, len(", ".join(binding['keys']))) for binding in KEY_BINDINGS.values()] max_widths = [max(width) for width in zip(*widths)] self.width = sum(max_widths) help_menu_content = [] # type: List[urwid.AttrWrap] for category in HELP_CATEGORIES: if len(help_menu_content) > 0: # Separate categories by newline help_menu_content.append(urwid.Text('')) help_menu_content.append( urwid.Text(('category', HELP_CATEGORIES[category]))) keys_in_category = (binding for binding in KEY_BINDINGS.values() if binding['key_category'] == category) for help_item_number, binding in enumerate(keys_in_category): help_menu_content.append( urwid.AttrWrap( urwid.Columns([ urwid.Text(binding['help_text']), (max_widths[1], urwid.Text(", ".join(binding['keys']))) ], dividechars=2), None if help_item_number % 2 else 'help')) self.log = urwid.SimpleFocusListWalker(help_menu_content) self.height = len(self.log) super().__init__(self.log)
def __init__(self, controller: Any) -> None: self.controller = controller widths = [(len(binding['help_text'])+4, len(", ".join(binding['keys']))) for binding in KEY_BINDINGS.values()] max_widths = [max(width) for width in zip(*widths)] self.width = sum(max_widths) self.log = urwid.SimpleFocusListWalker( [urwid.AttrWrap( urwid.Columns([ urwid.Text(binding['help_text']), (max_widths[1], urwid.Text(", ".join(binding['keys']))) ], dividechars=2), None if index % 2 else 'bar') for index, binding in enumerate(KEY_BINDINGS.values())]) self.number_of_actions = len(self.log) super(HelpView, self).__init__(self.log)
def __init__(self, controller: Any) -> None: self.controller = controller self.log = urwid.SimpleFocusListWalker( [urwid.Text('')] + [urwid.Columns([urwid.LineBox( urwid.Text(text), tlcorner='', brcorner='', trcorner='', blcorner='', rline=' ', lline=' ', bline='-', tline='', ) for text in (binding['help_text'], ", ".join(binding['keys']))]) for binding in KEY_BINDINGS.values()]) super(HelpView, self).__init__(self.log)
def __init__(self, controller: Any, title: str) -> None: help_menu_content = [] for category in HELP_CATEGORIES: keys_in_category = (binding for binding in KEY_BINDINGS.values() if binding['key_category'] == category) key_bindings = [] for binding in keys_in_category: key_bindings.append( (binding['help_text'], ', '.join(binding['keys']))) help_menu_content.append((HELP_CATEGORIES[category], key_bindings)) popup_width, column_widths = self.calculate_table_widths( help_menu_content, len(title)) widgets = self.make_table_with_categories(help_menu_content, column_widths) super().__init__(controller, widgets, 'HELP', popup_width, title)
#!/usr/bin/env python3 from pathlib import Path, PurePath from zulipterminal.config.keys import HELP_CATEGORIES, KEY_BINDINGS categories = { category: { item['help_text']: item['keys'] for item in KEY_BINDINGS.values() if item['key_category'] == category } for category in HELP_CATEGORIES.keys() } OUTPUT_FILE = Path(__file__).resolve().parent.parent / 'docs' / 'hotkeys.md' SCRIPT_NAME = PurePath(__file__).name with open(OUTPUT_FILE, "w") as mdFile: mdFile.write(f"<!--- Generated automatically by tools/{SCRIPT_NAME} -->\n" "<!--- Do not modify -->\n\n# Hot Keys\n") for action in categories.keys(): mdFile.write(f"## {HELP_CATEGORIES[action]}\n" "|Command|Key Combination|\n" "| :--- | :---: |\n") for help_text, key_combinations_list in categories[action].items(): various_key_combinations = " / ".join([ " + ".join( [f"<kbd>{key}</kbd>" for key in key_combination.split()]) for key_combination in key_combinations_list ]) mdFile.write(f"|{help_text}|{various_key_combinations}|\n") mdFile.write("\n")
#!/usr/bin/env python3 from pathlib import Path, PurePath from zulipterminal.config.keys import HELP_CATEGORIES, KEY_BINDINGS categories = { category: { item["help_text"]: item["keys"] for item in KEY_BINDINGS.values() if item["key_category"] == category } for category in HELP_CATEGORIES.keys() } OUTPUT_FILE = Path(__file__).resolve().parent.parent / "docs" / "hotkeys.md" SCRIPT_NAME = PurePath(__file__).name with open(OUTPUT_FILE, "w") as mdFile: mdFile.write(f"<!--- Generated automatically by tools/{SCRIPT_NAME} -->\n" "<!--- Do not modify -->\n\n# Hot Keys\n") for action in categories.keys(): mdFile.write(f"## {HELP_CATEGORIES[action]}\n" "|Command|Key Combination|\n" "| :--- | :---: |\n") for help_text, key_combinations_list in categories[action].items(): various_key_combinations = " / ".join([ " + ".join( [f"<kbd>{key}</kbd>" for key in key_combination.split()]) for key_combination in key_combinations_list ]) mdFile.write(f"|{help_text}|{various_key_combinations}|\n") mdFile.write("\n")