def main(): # Menu Format thin = Dimension(width=40, height=40) # Use a Dimension to limit the "screen width" to 40 characters menu_format = MenuFormatBuilder(max_dimension=thin) # Set the border style to use heavy outer borders and light inner borders menu_format.set_border_style_type(MenuBorderStyleType.DOUBLE_LINE_OUTER_LIGHT_INNER_BORDER) menu_format.set_title_align('center') # Center the menu title (by default it's left-aligned) menu_format.set_prologue_text_align('center') # Center the prologue text (by default it's left-aligned) menu_format.show_prologue_bottom_border(True) # Show a border under the prologue # Create the root menu menu = ConsoleMenu("Menu With Item Borders", prologue_text=("This menu example shows how menu items can be separated into categories.")) menu.formatter = menu_format # Create some menu items menu_item_1 = MenuItem("Menu Item 1") menu_item_2 = MenuItem("Menu Item 2") menu_item_3 = MenuItem("Menu Item 3") menu_item_4 = MenuItem("Menu Item 4") menu_item_5 = MenuItem("Menu Item 5") menu_item_6 = MenuItem("Menu Item 6") menu_item_7 = MenuItem("Menu Item 7") menu_item_8 = MenuItem("Menu Item 8") menu_format.show_item_top_border(menu_item_2.text, True) # Show a border above item 2 menu_format.show_item_top_border(menu_item_4.text, True) # Show a border above item 4 menu_format.show_item_bottom_border(menu_item_5.text, True) # Show a border *below* item 4 # To separate the exit item from other menu items, you can either put a bottom border on the # last item you added to the menu (menu_item_8 in this example), or, you can put a top # border on the exit_item.text property of the menu instance. menu_format.show_item_top_border(menu.exit_item.text, True) # Add menu items to menu menu.append_item(menu_item_1) menu.append_item(menu_item_2) menu.append_item(menu_item_3) menu.append_item(menu_item_4) menu.append_item(menu_item_5) menu.append_item(menu_item_6) menu.append_item(menu_item_7) menu.append_item(menu_item_8) # Show the menu menu.show(True)
def __init__(self, max_dimension=None): if max_dimension is None: max_dimension = Dimension(width=80, height=40) self.__max_dimension = max_dimension self.__border_style_factory = MenuBorderStyleFactory() self.__header = MenuHeader(menu_style=MenuStyle(), max_dimension=max_dimension) self.__prologue = MenuTextSection(menu_style=MenuStyle(), max_dimension=max_dimension) self.__items_section = MenuItemsSection(menu_style=MenuStyle(), max_dimension=max_dimension) self.__epilogue = MenuTextSection(menu_style=MenuStyle(), max_dimension=max_dimension) self.__footer = MenuFooter(menu_style=MenuStyle(), max_dimension=max_dimension) self.__prompt = MenuPrompt(menu_style=MenuStyle(), max_dimension=max_dimension) # Indent items deeper than other sections self.__items_section.style.padding.left = 3 # Change default top border of prompt to 0, so it hugs the bottom of the menu self.__prompt.style.padding.top = 0
def main(): header = ". _ _____.__ __ _____ . " \ ". (_) _/ ____\__|______ _______/ |_ _/ ____\___________ _____ ____ . " \ ". _ \ __\| \_ __ \/ ___/\ __\ \ __\ _ __ \__ \ / \_/ __ \\ . " \ ". (_) | | | || | \/\___ \ | | | | | | \// __ \| Y Y \ ___/ . " \ ". |__| |__||__| /____ > |__| |__| |__| (____ /__|_| /\___ > . " \ ". \/ \/ \/ \/ . " menu_format = MenuFormatBuilder(max_dimension=Dimension(width=120))\ .set_border_style_type(MenuBorderStyleType.HEAVY_BORDER) \ .set_prompt(">>> ") \ .set_title_align('center') \ .set_subtitle_align('center') \ .set_left_margin(4) \ .set_right_margin(4) \ .show_header_bottom_border(True) # Create the root menu menu = ConsoleMenu('BulkChanger', 'Version 0.3 by Florian Gemperle', prologue_text=header, formatter=menu_format) bulk = MenuItem('Start BulkChanger', menu) info = MenuItem('Start InfoCollector', menu) function_item = FunctionItem('Visit Homepage', webbrowser.open('https://www.firstframe.net')) # Create a menu item that calls a system command, based on OS type if sys.platform.startswith('win'): command_item = CommandItem( "Command", 'cmd /c \"echo this is a shell. Press enter to continue." && set /p=\"' ) else: command_item = CommandItem( "Command", 'sh -c \'echo "this is a shell. Press enter to continue."; read\'') # Create a submenu using a Selection Menu, which takes a list of strings to create the menu items. submenu = SelectionMenu( ["item1", "item2", "item3"], title="Selection Menu", subtitle="These menu items return to the previous menu") # Create the menu item that opens the Selection submenu submenu_item = SubmenuItem("Submenu item", submenu=submenu) submenu_item.set_menu(menu) # Create a second submenu, but this time use a standard ConsoleMenu instance submenu_2 = ConsoleMenu("Another Submenu Title", "Submenu subtitle.") function_item_2 = FunctionItem("Fun item", Screen().input, ["Enter an input: "]) item2 = MenuItem("Another Item") submenu_2.append_item(function_item_2) submenu_2.append_item(item2) submenu_item_2 = SubmenuItem("Another submenu", submenu=submenu_2) submenu_item_2.set_menu(menu) # Add all the items to the root menu menu.append_item(bulk) menu.append_item(info) menu.append_item(function_item) # Show the menu menu.start() menu.join()