Example #1
0
def show_first_menu():
    # Record which models are in the models folder
    models_list = [
        f for f in listdir(models_path)
        if isfile(join(models_path, f)) and f[-4:] == ".dat"
    ]

    first_menu = ConsoleMenu("Main menu")

    submenu = SelectionMenu(models_list, "Load Model")
    submenu_item = SubmenuItem("Load a model",
                               submenu,
                               menu=first_menu,
                               should_exit=True)

    first_menu.append_item(submenu_item)

    first_menu.start()
    first_menu.join()

    if submenu.selected_option >= len(models_list):
        show_first_menu()
        return
    elif submenu.selected_option == -1:
        return

    selected_model = models_list[submenu.selected_option]

    net, jtree = util.load_model(models_path + selected_model)
    if net is not None and jtree is not None:
        jtree.initialize_tables(net)
        print("Model loaded succesfully")
        show_loaded_model_menu(selected_model, net, jtree)
    else:
        show_first_menu()
def select_scan():

    global lightsheetPackages, lightsheetScanPaths, displayNames

    scanIndex = SelectionMenu.get_selection(displayNames)

    if scanIndex >= len(displayNames):
        return None

    scanName = displayNames[scanIndex]
    scan = lightsheetPackages[scanIndex]
    attribs = scan.get_filled_attr_dict()

    # TODO: Open the scan and spawn the GUI showing the metadata and thumbnail

    analysisList = ['3D Density Map', 'Stroke Volume', 'Vessel Diameter']

    scanMenu = ConsoleMenu(scanName, exit_option_text="Close Scan")
    viewAttribsItem = FunctionItem("View Metadata", show_scan_metadata,
                                   [attribs])
    viewMaxProjItem = FunctionItem("View Max-Proj", show_scan_maxproj,
                                   [attribs['maxProjPath'], attribs['name']])
    #selectAnalysisPackageItem = FunctionItem("View Analysis", select_existing_analysis, [analysisList])
    #createNewAnalysisPackageItem = FunctionItem("Import Analysis", perform_new_analysis, [analysisList])
    downloadScanItem = FunctionItem("Download Copy", download_scan,
                                    [scan.get_uniqueID()])
    scanMenu.append_item(viewAttribsItem)
    scanMenu.append_item(viewMaxProjItem)
    #scanMenu.append_item(selectAnalysisPackageItem)
    #scanMenu.append_item(createNewAnalysisPackageItem)
    scanMenu.append_item(downloadScanItem)
    scanMenu.show()
 def _create_menu(desc, epilogue_text, menu_items):
     console_menu = ConsoleMenu(
         "Getting and Setting Channel Values API Demo",
         desc,
         epilogue_text=epilogue_text)
     for name, fn, args, opts in menu_items:
         menu_item = FunctionItem(name, fn, args, **opts)
         console_menu.append_item(menu_item)
     return console_menu
Example #4
0
 def _create_menu(desc, epilogue_text, menu_items):
     console_menu = ConsoleMenu("Test Session API Demo",
                                desc,
                                epilogue_text=epilogue_text)
     console_menu.append_item(refresh_test_session_state)
     for name, fn, args, opts in menu_items:
         menu_item = FunctionItem(name, fn, args, **opts)
         console_menu.append_item(menu_item)
     return console_menu
Example #5
0
 def test_remove_menu_item(self):
     menu = ConsoleMenu("menu1", "test_currently_active_menu_1")
     item1 = MenuItem(text='itemText', menu=menu)
     item2 = MenuItem(text='itemText2', menu=menu)
     menu.append_item(item1)
     menu.append_item(item2)
     self.assertIn(item1, menu.items)
     self.assertIn(item2, menu.items)
     menu.remove_item(item1)
     self.assertNotIn(item1, menu.items)
     self.assertIn(item2, menu.items)
Example #6
0
def vm_menu():
    menu = ConsoleMenu("Virtual Machine", "Created with Python")

    submenu = ConsoleMenu("About Us")
    submenu.prologue_text = "This is Virtual Machine. Created by Vilnius Gediminas " \
          "Technical University PRIfs 18/6 student - Rimvydas Kanapka." \
                            " This program is created for Architecture of Computers and Computer Networks."

    menu.append_item(FunctionItem("Start VM", main))  # First menu item
    menu.append_item(SubmenuItem("About Us", submenu,
                                 menu=menu))  # Second menu item
    menu.show()
Example #7
0
def tm_menu():
    menu = ConsoleMenu("Turing Machine Simulator", "Created with Python")

    submenu = ConsoleMenu("About Us")
    submenu.prologue_text = "This is Turing Machine Simulator created by Vilnius Gediminas Technical University " \
                            "PRIfs 18/6 student - Rimvydas Kanapka." \
                            " This program is created for Architecture of Computers and Computer Networks."

    menu.append_item(FunctionItem("RUN Turing Machine",
                                  action))  # First menu item
    menu.append_item(SubmenuItem("About Us", submenu,
                                 menu=menu))  # Second menu item
    menu.show()
Example #8
0
def process_data(name, data, page, nested=None):
    if isinstance(data, Exception):
        Screen().input(f"DError: {data}")
        return
    subtitle = "".join(f"{i} " for i in columns[name])
    arr = [f" Page {page - 1}", f" Page {page + 1}"]
    for en in data:
        arr.append(" ".join(map(str, en)))
    sel = SelectionMenu.get_selection(arr, subtitle)
    if sel in range(2, len(arr)):
        subtitle = ""
        for i in range(len(columns[name])):
            subtitle += f"{columns[name][i]}: {data[sel - 2][i]}; "
        menu = ConsoleMenu("Item actions", subtitle)
        if name == "Seller" and nested == None:
            menu.append_item(
                FunctionItem("Find products", find_products,
                             [data[sel - 2][0], 1]))
        elif name == "Product" and nested == None:
            menu.append_item(
                FunctionItem("Find sellers", find_sellers,
                             [data[sel - 2][0], 1]))
        menu.append_item(
            FunctionItem("Edit", update,
                         [name, columns[name][0], data[sel - 2][0]]))
        menu.append_item(
            FunctionItem("Delete", delete,
                         [name, columns[name][0], data[sel - 2][0]]))
        menu.show()
    elif sel < 2:
        return sel + 1
Example #9
0
def manually_mod_settings(set_dict):
    #quick and dirsty workaround - older settings files don't include rand, d.
    if 'RANDOM_DISABLE_CHANCE' not in set_dict.keys():
        set_dict['RANDOM_DISABLE_CHANCE'] = RANDOM_DISABLE_CHANCE
    menu = ConsoleMenu("Tune parameters", "[original value] / <new value>")
    menu_items = []
    for idx, (key, val) in enumerate(set_dict.items()):
        desc = f"{key}[{val}]"
        prompt = f"{key}[{val}] : "

        def prompt_func(text, set_key):
            value = input(text)
            if set_key in ['PID_ENABLED', 'COLLISION']:
                set_dict[set_key] = True if value.startswith(
                    ('T', 't')) else False
            elif set_key == 'PID_PARAMS':
                set_dict[set_key] = [
                    float(x) for x in value.replace(' ', ',').split(',')
                ]
            elif isInt(float(value)):
                set_dict[set_key] = int(value)
            else:
                set_dict[set_key] = float(value)
            return value

        if key in ['PID_ENABLED', 'COLLISION']:
            prompt = f"{key}[{val}](F/T) : "
        if key == 'PID_PARAMS':
            prompt = "PID <P I D>: "
            menu_items.append(FunctionItemMod(desc, prompt_func,
                                              [prompt, key]))
        else:
            menu_items.append(FunctionItemMod(desc, prompt_func,
                                              [prompt, key]))

        menu.append_item(menu_items[idx])

    def print_sett():
        for key, item in set_dict.items():
            print(f"{key} : {item}")
        input('\nPress any key to return!')

    menu.append_item(FunctionItem("PRINT CURRENT SETTINGS", print_sett))
    menu.show()
    return set_dict
Example #10
0
def main():

    if len(argv) < 2:
        menu = ConsoleMenu("Mechanism Types",
                           "Choose which mechanism you are characterizing")

        for mechanism, tools in tool_dict.items():
            tool_menu = ConsoleMenu(f"Characterization Tools: {mechanism}")
            for tool, function in tools.items():
                tool_menu.append_item(
                    FunctionItem(tool, function, menu=tool_menu))

            menu.append_item(SubmenuItem(mechanism, tool_menu, menu))

        menu.show()

    else:
        parser = argparse.ArgumentParser(
            description="FRC characterization tools CLI")
        parser.add_argument(
            "mech_type",
            choices=list(tool_dict.keys()),
            help="Mechanism type being characterized",
        )
        parser.add_argument(
            "tool_type",
            choices=list(list(tool_dict.values())[0].keys()),
            help=
            "Create new project, start data recorder/logger, or start data analyzer",
        )
        parser.add_argument(
            "project_directory",
            help=
            "Location for the project directory (if creating a new project)",
            nargs="?",
            default=None,
        )
        argcomplete.autocomplete(parser)

        args = parser.parse_args()
        tool_dict[args.mech_type][args.tool_type](
            directory=args.project_directory)
Example #11
0
    def test_action(self):
        root_menu = ConsoleMenu("root_menu", "test_action")
        submenu1 = ConsoleMenu("submenu1", "test_action")
        submenu2 = ConsoleMenu("submenu2", "test_action")
        submenu_item_1 = SubmenuItem("submenu_item_1", submenu1, menu=root_menu)
        submenu_item_2 = SubmenuItem("submenu_item_2", submenu2, menu=root_menu)

        root_menu.append_item(submenu_item_1)
        root_menu.append_item(submenu_item_2)

        root_menu.start()
        root_menu.wait_for_start(timeout=10)
        self.assertIs(ConsoleMenu.currently_active_menu, root_menu)
        submenu_item_1.action()
        submenu1.wait_for_start(timeout=10)
        self.assertIs(ConsoleMenu.currently_active_menu, submenu1)
        ConsoleMenu.currently_active_menu.exit()
        submenu1.join(timeout=10)
        self.assertIs(ConsoleMenu.currently_active_menu, root_menu)
        submenu_item_2.action()
        submenu2.wait_for_start(timeout=10)
        self.assertIs(ConsoleMenu.currently_active_menu, submenu2)
Example #12
0
def manage_devices(devices):
    """
    Enable/disable a device
    :param devices: A device object
    """
    prologue_text = "\n".join([
        "{} ({})".format(d.name, "Enabled" if d.is_enabled else "Disabled")
        for d in devices
    ])
    menu = ConsoleMenu(title="Emulation > Devices",
                       prologue_text=prologue_text)
    menu.append_item(
        FunctionItem("Enable",
                     api.toggle_devices,
                     args=[devices, True],
                     should_exit=True))
    menu.append_item(
        FunctionItem("Disable",
                     api.toggle_devices,
                     args=[devices, False],
                     should_exit=True))

    menu.show()
def main():
    #List containing the choices of the user
    desired_properties: List[DesiredProperty] = []

    #Load ontology
    amsterdam_neighbourhoods = pd.read_csv("data/amsterdam.csv")

    # Create the menu
    menu = ConsoleMenu("AreA", "An advisor on Amsterdam's residential areas")

    # Menu Items
    desired_prop_item = FunctionItem("Add desired property",
                                     desired_prorerty_submenu,
                                     [desired_properties])
    view_sugg_item = FunctionItem(
        "Get suggestions", view_suggestions_func,
        [amsterdam_neighbourhoods, desired_properties])

    # Once we're done creating them, we just add the items to the menu
    menu.append_item(desired_prop_item)
    menu.append_item(view_sugg_item)

    # start menu
    menu.show()
Example #14
0
def menu():
    """
    Make use of an interactive menu.

    """
    interactive_menu = ConsoleMenu("Welcome to qr-rocket menu",
                                   "Select an option")
    interactive_menu.append_item(
        CommandItem("Create a new PDF file", "rocketqr create"))
    interactive_menu.append_item(
        CommandItem("Delete all auto generated files", "rocketqr delete"))
    interactive_menu.append_item(
        CommandItem("Go to templates menu", "rocketqr templates menu"))
    interactive_menu.show()
Example #15
0
def utf_menu():
    menu = ConsoleMenu("Decimal number convertor & File Decoder",
                       "Created with Python")

    submenu = ConsoleMenu("About Us")
    submenu.prologue_text = "This is Decimal number convertor which takes a decimal number as a input and shows " \
          "number's Unicode, UTF-8 and single character. Created by Vilnius Gediminas " \
          "Technical University PRIfs 18/6 student - Rimvydas Kanapka." \
                            " This program is created for Architecture of Computers and Computer Networks."

    menu.append_item(
        FunctionItem("GET Unicode, UTF-8 & Char of a Decimal Number",
                     get_info))  # First menu item
    menu.append_item(FunctionItem("Decode File", decode))  # Second menu item
    menu.append_item(SubmenuItem("About Us", submenu,
                                 menu=menu))  # Third menu item
    menu.show()
Example #16
0
def output_console_menu():
    start_directory = os.getcwd()
    directory_content = get_directory_content(start_directory, False)
    file_selection_menu = ConsoleMenu("Select file from:", start_directory)
    for current_dir_item in directory_content:
        current_dir_item_path = start_directory + os.path.sep + current_dir_item
        if os.path.isfile(current_dir_item_path):
            file_selection_menu.append_item(FunctionItem(current_dir_item,
                                                         get_statistic,
                                                         [current_dir_item_path, tasks_list]))
        elif os.path.isdir(current_dir_item_path):
            current_sub_menu = ConsoleMenu("Select file from:", current_dir_item_path)
            for current_subdir_item in get_directory_content(current_dir_item_path, True):
                current_sub_menu.append_item(FunctionItem(current_subdir_item,
                                                          get_statistic,
                                                          [
                                                              current_dir_item_path + os.path.sep + current_subdir_item, tasks_list]))
            file_selection_menu.append_item(SubmenuItem(current_dir_item + os.path.sep, current_sub_menu))
    file_selection_menu.show()
Example #17
0
    def init_menu(self):
        titulo = "Menú principal"
        subtitulo = "Programa para cifrar ficheros con AES 256 GCM"
        prologue = "Para poder encriptar ficheros tiene que estar situados en la carpeta files."\
            " Los ficheros *.encrypted y *.decrypted se situarán en la misma carpeta."

        if not os.path.exists("./my_keystore.jks"):
            prologue += " PARA HACER USO DE LAS FUNCIONES DE ENCRIPTADO Y DESENCRIPTADO, DEBE CREAR UN ALMACÉN DE CLAVES Y UNA CLAVE (3)."

        menu = ConsoleMenu(titulo, subtitulo, prologue_text=prologue)

        cifrado = FunctionItem("Cifrado del fichero", self.encrypt)
        descifrado = FunctionItem("Descifrado del fichero", self.decrypt)
        generado_claves = FunctionItem("Generar nueva clave privada",
                                       self.generate_key)

        menu.append_item(cifrado)
        menu.append_item(descifrado)
        menu.append_item(generado_claves)

        menu.show()
Example #18
0
def main():
    init()

    # Define main menu
    menu = ConsoleMenu(
        title="Music Library Manager",
        subtitle="Main Menu",
    )
    # Define add menu
    addMenu = ConsoleMenu(
        title="Music Library Manager",
        subtitle="Where would you like to add a new track?",
        exit_option_text="Back"
    )

    # Define main menu options
    opt_display = FunctionItem(
        "Display Music Library", wait_func, [displayLibrary])
    opt_add = SubmenuItem("Add a new track", addMenu)

    # Define add menu options
    opt_add_start = FunctionItem(
        "At the beginning of the list", wait_func, [addTune])

    # Add options to the main menu
    menu.append_item(opt_add)
    menu.append_item(opt_display)

    # Add options to the add menu
    addMenu.append_item(opt_add_start)

    # Display the menu and wait for user input
    menu.show()

    # Print when user runs the 'Exit' option
    print("Exiting...")
Example #19
0
    discovering_website = Project()
    load_or_new = input('Do you want to load a project from disk? (y/n) ')
    if load_or_new == 'y':
        path = input('Path: ')
        discovering_website.load(path)
    else:
        name = input('Name: ')
        description = input('Description: ')
        discovering_website = Project(name, description)

    interface = ConsoleInterfaceWrapper(discovering_website)

    m_main = ConsoleMenu('WebSiDis console interface')

    m_notes = ConsoleMenu('Notes')
    m_notes.append_item(FunctionItem('Add new note', interface.wrapAddNote))
    m_notes.append_item(
        FunctionItem('Remove existed note', interface.wrapRemNote))
    m_notes.append_item(
        FunctionItem('Show notes', interface.wrapShow, ['notes']))

    m_related = ConsoleMenu('Sites')
    m_related.append_item(
        FunctionItem('Add new related site', interface.wrapAddRelated))
    m_related.append_item(
        FunctionItem('Remove existed related site', interface.wrapRemRelated))
    m_related.append_item(
        FunctionItem('Show related sites', interface.wrapShow, ['related']))

    m_structure = ConsoleMenu('Structure')
    m_structure.append_item(FunctionItem('Add new page',
Example #20
0
    stream = f.read()
    temp = yaml.load(stream)

config = napalm_yang.base.Root()
config.add_model(napalm_yang.models.openconfig_interfaces())
config.load_dict(temp)

def show_data(args):
    if "yaml" in args:
        print(stream)
    elif "dict" in args:
        pretty_print(temp)
    elif "yang" in args:
        pretty_print(napalm_yang.utils.model_to_dict(config))
    elif "gen" in args:
        pretty_print(config.get(filter=True))
    elif "junos" in args:
        print(config.translate_config(profile=["junos"]))
    elif "ios" in args:
        print(config.translate_config(profile=["ios"]))
    else:
        return
    input("Press Enter")

menu = ConsoleMenu("Menu")
menu_dict = {"yaml":"YAML data model", "dict": "python dictionary", "yang": "YANG model.  Warning: long output.", "gen": "generated YANG data", "junos":"JunOS config", "ios":"IOS config"}
for key, value in menu_dict.items():
    function_item = FunctionItem("View the " + value, show_data, [key])
    menu.append_item(function_item)
menu.show()
Example #21
0
    task = Thread(target=main, args=args)
    task_menu = FunctionItem(name,
                             terminate_task, [task, name],
                             should_exit=True)
    task_menu.args.append(task_menu)
    tasks_menu.append_item(task_menu)
    task.start()
    print('Started successfully.')
    input()


Client.login()

gen_menu = ConsoleMenu('Send messages and files')
gen_menu.append_item(FunctionItem('Send message', Client.send_message))
gen_menu.append_item(FunctionItem('Send file', Client.send_file))
gen_menu.append_item(FunctionItem('Bulk send', Client.bulk_send))
gen_menu.append_item(FunctionItem('User info', Client.user_info))
gen_menu.append_item(FunctionItem('Server list', Client.get_servers))
gen_menu.append_item(FunctionItem('Member list', Client.create_list))
gen_menu.append_item(FunctionItem('Download avatar', Client.download_avatar))

exploit_menu = ConsoleMenu('Exploits and misc features')
exploit_menu.append_item(
    FunctionItem('Infinite typing', create_task,
                 ['Infinite typing', Exploits.typing, 'Channel ID']))
exploit_menu.append_item(
    FunctionItem('Status changer', create_task,
                 ['Status changer', Exploits.status_changer]))
exploit_menu.append_item(FunctionItem('Friend finder', Exploits.friend_list))
Example #22
0
def main():
    """
    Run the intial setup script, check for an input file and show the main menu
    """

    init_script()
    read_info_file()

    # Define Menu
    menu = ConsoleMenu(
        title="AWS EC2 and S3 Webserver Configuration Script",
        subtitle="Developer Operations Assignment 1 - Dylan Gore",
    )

    # Define menu options and what they do
    opt_full_run = FunctionItem("Run automatic configuration", wait_func,
                                [full_run])
    opt_user_input = FunctionItem("Input custom settings", wait_func,
                                  [accept_user_input])
    opt_active = FunctionItem("List running instances/active buckets",
                              wait_func, [list_active])
    opt_monitoring = FunctionItem("Display monitoring info", wait_func,
                                  [display_monitor])
    # opt_website = FunctionItem("Check if web server is running", wait_func, [check_website])
    # opt_iam = FunctionItem("Create IAM role & policy", wait_func, [check_for_iam_role, iam, sts_client])
    opt_configure_aws = CommandItem("Configure AWS credentials and Settigns",
                                    "aws configure")
    opt_load_config_file = FunctionItem("Load configuration file", wait_func,
                                        [read_info_file])
    opt_cleanup = FunctionItem("Cleanup AWS", wait_func, [cleanup])
    opt_clear_logs = FunctionItem("Clear logs", wait_func, [clear_logs])

    # Add options to menu
    menu.append_item(opt_full_run)
    menu.append_item(opt_user_input)
    menu.append_item(opt_active)
    menu.append_item(opt_monitoring)
    # menu.append_item(opt_website)
    # menu.append_item(opt_iam)
    menu.append_item(opt_configure_aws)
    menu.append_item(opt_load_config_file)
    menu.append_item(opt_cleanup)
    menu.append_item(opt_clear_logs)

    # Display the menu and wait for user input
    menu.show()

    # Print when user runs the 'Exit' option
    print("Exiting...")
Example #23
0
from consolemenu import ConsoleMenu
from consolemenu.items import FunctionItem, SubmenuItem, CommandItem

menu = ConsoleMenu(title='Menu Title', subtitle='Subtitle')

command_item = CommandItem('Run a console command!', 'touch.txt')
function_item = FunctionItem('call a function', input, ['enter input'])

submenu = ConsoleMenu('a submenu')
submenu_item = SubmenuItem('show a submenu', submenu, menu=menu)

menu.append_item(command_item)
menu.append_item(function_item)
menu.append_item(submenu_item)

# menu.start()

# menu.join()

menu.show()

                             epilogue_text=lightsheetEpilogue,
                             exit_option_text="Main Menu")
lightsheetItem = SubmenuItem("Lightsheet Data", lightsheetMenu, mainMenu)
ephysMenu = ConsoleMenu("EPhys Data [Not Implemented]",
                        exit_option_text="Main Menu")
ephysItem = SubmenuItem("Ephys Data", ephysMenu, mainMenu)
confocalMenu = ConsoleMenu("Confocal Data [Not Implemented]",
                           exit_option_text="Main Menu")
confocalItem = SubmenuItem("Confocal Data", confocalMenu, mainMenu)
behaviorMenu = ConsoleMenu("Behavior Data [Not Implemented]",
                           exit_option_text="Main Menu")
behaviorItem = SubmenuItem("Behavior Data", behaviorMenu, mainMenu)
cellCultureMenu = ConsoleMenu("Cell Culture Data [Not Implemented]",
                              exit_option_text="Main Menu")
cellCultureItem = SubmenuItem("Cell Culture Data", cellCultureMenu, mainMenu)

openScanMenuItem = FunctionItem("Open Scan",
                                select_scan, [],
                                menu=lightsheetMenu)
importScanMenuItem = FunctionItem("Import Scan", create_scan, [])

mainMenu.append_item(lightsheetItem)
mainMenu.append_item(ephysItem)
mainMenu.append_item(confocalItem)
mainMenu.append_item(behaviorItem)
mainMenu.append_item(cellCultureItem)
lightsheetMenu.append_item(openScanMenuItem)
lightsheetMenu.append_item(importScanMenuItem)

mainMenu.show()
Example #25
0
def show_loaded_model_menu(model, net, jtree):
    # Record which models are in the models folder
    models_list = [
        f for f in listdir(models_path)
        if isfile(join(models_path, f)) and str(f)[-4:] == ".dat"
    ]

    menu = ConsoleMenu("Main menu - " + model)

    describe_bnet = FunctionItem("Describe Bayesian Net",
                                 function=lambda net: print(str(net)),
                                 args=[net])

    describe_jtree = FunctionItem("Describe Junction Tree",
                                  function=lambda jtree: print(str(jtree)),
                                  args=[jtree])

    visualize = FunctionItem(
        "Visualize Bayesian Net and Junction Tree",
        function=lambda path: os.system("visualize.py " + path),
        args=[models_path + model])

    propagate = FunctionItem(
        "Propagate evidence",
        function=lambda jtree:
        [jtree.sum_propagate(),
         print("Evidence propagated")],
        args=[jtree])

    load_new_model = SelectionMenu(models_list, "Load New Model")
    load_new_model_item = SubmenuItem("Load a new model",
                                      load_new_model,
                                      menu=menu,
                                      should_exit=True)

    add_evidence = FunctionItem("Add evidence",
                                function=add_evidence_option,
                                args=[jtree])
    get_probability = FunctionItem("Get probability of a variable",
                                   function=get_probability_option,
                                   args=[jtree])
    reset_model = FunctionItem(
        "Reset Model",
        function=lambda net, jtree:
        [jtree.initialize_tables(net),
         print("Tables reinitialized")],
        args=[net, jtree])

    menu.append_item(describe_bnet)
    menu.append_item(describe_jtree)
    menu.append_item(visualize)
    menu.append_item(add_evidence)
    menu.append_item(get_probability)
    menu.append_item(propagate)
    menu.append_item(reset_model)
    menu.append_item(load_new_model_item)

    menu.start()
    menu.join()

    if load_new_model.selected_option >= len(models_list):
        show_loaded_model_menu(model, net, jtree)
        return
    elif load_new_model.selected_option == -1:
        return

    selected_model = models_list[load_new_model.selected_option]
    net, jtree = util.load_model(models_path + selected_model)
    if net is not None and jtree is not None:
        jtree.initialize_tables(net)
        print("Model loaded succesfully")
        show_loaded_model_menu(selected_model, net, jtree)
    else:
        show_first_menu()
Example #26
0
def templates_menu():
    templates_menu = ConsoleMenu("You are in qr-rocket templates menu", "Select an option")
    templates_menu.append_item(CommandItem("Show templates", "rocketqr templates show"))
    templates_menu.append_item(CommandItem("Create new template", "rocketqr templates create"))
    templates_menu.append_item(CommandItem("Go back to main menu", "rocketqr menu"))
    templates_menu.show()
Example #27
0
def main():
    # Create the menu
    menu = ConsoleMenu(
        "Lena's Bank main menu",
        "Welcome to Lena's Bank! Please select from the following menu:")

    # A FunctionItem runs a Python function when selected
    list_of_all_customers_function = FunctionItem("List of all customers",
                                                  bank.list_of_all_customers)
    find_customer_function = FunctionItem("Find customer by SSN",
                                          bank.find_customer)
    update_customer_info_function = FunctionItem("Update customer info",
                                                 bank.update_customer)
    remove_customer_function = FunctionItem("Remove customer",
                                            bank.remove_customer)
    add_new_customer_function = FunctionItem("Add new customer",
                                             bank.add_new_customer)

    get_balance_function = FunctionItem("Get balance", bank.get_balance)
    open_new_account_function = FunctionItem("Open New Account",
                                             bank.open_new_account)
    close_account_function = FunctionItem("Close account", bank.close_account)

    add_new_transaction_function = FunctionItem("Add new transaction",
                                                bank.add_new_transaction)
    view_transaction_history_function = FunctionItem(
        "View transaction history", bank.transaction_history)

    list_of_all_customers_submenu_item = SelectionMenu([])
    list_of_all_customers_submenu_item.append_item(
        list_of_all_customers_function)
    list_of_all_customers_submenu_item.append_item(find_customer_function)
    list_of_all_customers_submenu_item.append_item(
        update_customer_info_function)
    list_of_all_customers_submenu_item.append_item(add_new_customer_function)
    list_of_all_customers_submenu_item.append_item(remove_customer_function)

    work_with_accounts_selection_menu = SelectionMenu([])
    work_with_accounts_selection_menu.append_item(get_balance_function)
    work_with_accounts_selection_menu.append_item(open_new_account_function)
    work_with_accounts_selection_menu.append_item(close_account_function)

    process_transactions_selection_menu = SelectionMenu([])
    process_transactions_selection_menu.append_item(
        add_new_transaction_function)
    process_transactions_selection_menu.append_item(
        view_transaction_history_function)

    manage_customers_submenu_item = SubmenuItem(
        "Manage customers", list_of_all_customers_submenu_item, menu)

    accounts_submenu_item = SubmenuItem("Work with accounts",
                                        work_with_accounts_selection_menu,
                                        menu)
    process_transactions_submenu_item = SubmenuItem(
        "Process Transactions", process_transactions_selection_menu, menu)

    menu.append_item(manage_customers_submenu_item)
    menu.append_item(accounts_submenu_item)
    menu.append_item(process_transactions_submenu_item)

    models.create_lenas_bank()
    menu.show()
menu = ConsoleMenu("WJSTX Transceiver Control ", "FT8 and FT4")
resp_submenu = ConsoleMenu("Respond with: ", "", exit_option_text="Go back")

#Main menu
cq_item = FunctionItem("Call CQ", call_cq, [False])
continue_cq_item = FunctionItem("Continue Call CQ", call_cq, [True])
retransmit_item = FunctionItem("Retransmit last", transmit, [])
resp_new_item = FunctionItem("Respond to new callsign", resp_new, [])
submenu_item = FunctionItem("Respond to last callsign", resp_last, [])
chfreq_item = FunctionItem("Change TX frequency", change_freq, [])
chft4_item = FunctionItem("Change mode to FT4", change_mode, [])
chft8_item = FunctionItem("Change mode to FT8", change_mode, [])

resp_grid_item = FunctionItem("Respond with grid", respond, ['grid'])
resp_signal_item = FunctionItem("Respond with R + signal strenght", respond,
                                ['signal'])
resp_73_item = FunctionItem("Respond with RR73", respond, ['RR73'])

resp_submenu.append_item(resp_grid_item)
resp_submenu.append_item(resp_signal_item)
resp_submenu.append_item(resp_73_item)

menu.append_item(cq_item)
menu.append_item(continue_cq_item)
menu.append_item(resp_new_item)
menu.append_item(submenu_item)
menu.append_item(retransmit_item)
menu.append_item(chfreq_item)
menu.append_item(chft4_item)

menu.show()
class TestSampleMenu(BaseTestCase):
    def setUp(self):
        super(TestSampleMenu, self).setUp()

        self.menu = ConsoleMenu("self.menu", "TestSampleMenu")
        self.item1 = MenuItem("self.item1", self.menu)
        self.item2 = MenuItem("self.item2", self.menu)
        self.menu.append_item(self.item1)
        self.menu.append_item(self.item2)
        self.menu.start()
        self.menu.wait_for_start(timeout=10)

    def tearDown(self):
        super(TestSampleMenu, self).tearDown()
        self.menu.exit()
        self.menu.join(timeout=10)

    def test_go_down(self):
        self.menu.go_down()
        self.assertEqual(self.menu.current_option, 1)
        self.assertIs(self.menu.current_item, self.item2)
        self.menu.go_down()
        self.assertEqual(self.menu.current_option, 2)
        self.assertEqual(self.menu.current_item, self.menu.exit_item)
        self.menu.go_down()
        self.assertEqual(self.menu.current_option, 0)
        self.assertIs(self.menu.current_item, self.item1)

    def test_go_up(self):
        self.menu.go_up()
        self.assertEqual(self.menu.current_option, 2)
        self.assertIs(self.menu.current_item, self.menu.exit_item)
        self.menu.go_up()
        self.assertEqual(self.menu.current_option, 1)
        self.assertEqual(self.menu.current_item, self.item2)
        self.menu.go_up()
        self.assertEqual(self.menu.current_option, 0)
        self.assertIs(self.menu.current_item, self.item1)

    def test_go_to(self):
        self.menu.go_to(1)
        self.assertEqual(self.menu.current_option, 1)
        self.assertEqual(self.menu.current_item, self.item2)

    def test_select(self):
        self.menu.select()
        self.assertEqual(self.menu.selected_option, 0)
        self.assertIs(self.menu.selected_item, self.item1)
        self.menu.go_down()
        self.menu.select()
        self.assertEqual(self.menu.selected_option, 1)
        self.assertIs(self.menu.selected_item, self.item2)
        self.menu.go_down()
        self.menu.select()
        self.assertEqual(self.menu.selected_option, 2)
        self.assertIs(self.menu.selected_item, self.menu.exit_item)
        self.menu.join(timeout=10)
        self.assertFalse(self.menu.is_alive())

    def test_exit(self):
        self.assertTrue(self.menu.is_alive())
        self.menu.exit()
        self.menu.join(timeout=10)
        self.assertFalse(self.menu.is_alive())
Example #30
0
buildMenu_Fleet = ConsoleMenu('Fleet Menu')

# FUNCTIONS TO EACH MENU
buildMenuMining_FunctionMetal = FunctionItem('Metal Mine', bot.build, args='1')
buildMenuMining_FunctionCrystal = FunctionItem('Crystal Mine',
                                               bot.build,
                                               args='2')
buildMenuMining_FunctionDeuterium = FunctionItem('Deuterium Mine',
                                                 bot.build,
                                                 args='3')
buildMenuMining_FunctionEnergy = FunctionItem('Enery Plant',
                                              bot.build,
                                              args='4')

# ADD TO EACH MENU
buildMenu_Mining.append_item(buildMenuMining_FunctionMetal)
buildMenu_Mining.append_item(buildMenuMining_FunctionCrystal)
buildMenu_Mining.append_item(buildMenuMining_FunctionDeuterium)
buildMenu_Mining.append_item(buildMenuMining_FunctionEnergy)

# SUBMENUS BUILDING
subMenuMining = SubmenuItem('Mining Menu', buildMenu_Mining, buildMenu)
subMenuStructure = SubmenuItem('Structure Menu', buildMenu)
subMenuDefense = SubmenuItem('Defense Menu', buildMenu)
subMenuFleet = SubmenuItem('Fleet Menu', buildMenu)
buildSubMenu = SubmenuItem('Building Menu', buildMenu)

# SUBMENUS APPENDING TO MAIN MENU
buildMenu.append_item(subMenuMining)
buildMenu.append_item(subMenuStructure)
buildMenu.append_item(subMenuDefense)