Exemplo n.º 1
0
    def test_left_key_returns_none(self):
        pp = PathPicker('/tmp',
                        get_mock_input(),
                        get_mock_output(),
                        name=pp_name,
                        config={})
        pp.refresh = lambda *args, **kwargs: None

        # Checking at the start of the list
        def scenario():
            pp.deactivate()  # KEY_LEFT
            assert not pp.in_foreground

        with patch.object(pp, 'idle_loop', side_effect=scenario) as p:
            return_value = pp.activate()
        assert return_value is None

        # Checking after going a couple of elements down
        def scenario():
            for i in range(3):
                pp.move_down()  # KEY_DOWN x3
            pp.deactivate()  # KEY_LEFT
            assert not pp.in_foreground

        with patch.object(pp, 'idle_loop', side_effect=scenario) as p:
            return_value = pp.activate()
        assert return_value is None
Exemplo n.º 2
0
def call_by_path():
    path = PathPicker("/", i, o).activate()
    if path is None:
        return
    args = NumpadCharInput(i, o, message="Arguments:", name="Script argument input").activate()
    if args is not None:
        path = path+" "+args
    call_external(path, shell=True)
Exemplo n.º 3
0
 def test_constructor(self):
     """tests constructor"""
     pp = PathPicker("/tmp",
                     get_mock_input(),
                     get_mock_output(),
                     name=pp_name,
                     config={})
     self.assertIsNotNone(pp)
Exemplo n.º 4
0
def set_mtkdownload_path():
    key = "mtkdownload_path"
    default_path = config[key] if os.path.isabs(config[key]) else "/"
    path = PathPicker(default_path, i, o, name="Hardware setup app mtkdownload path picker").activate()
    if path:
        config[key] = path
        save_config(config)
        return True
    return False
Exemplo n.º 5
0
def set_sim_firmware_path():
    key = "gsm_fw_path"
    default_path = config.get(key, default_gsm_fw_path)
    path = PathPicker(default_path, i, o, dirs_only=True, name="Hardware setup app SIM firmware path picker").activate()
    if path:
        config[key] = path
        save_config(config)
        return True
    return False
Exemplo n.º 6
0
 def test_keymap(self):
     """tests keymap"""
     pp = PathPicker("/tmp",
                     get_mock_input(),
                     get_mock_output(),
                     name=pp_name,
                     config={})
     self.assertIsNotNone(pp.keymap)
     for key_name, callback in pp.keymap.iteritems():
         self.assertIsNotNone(callback)
Exemplo n.º 7
0
 def set_dir(self, attr_name, config_option_name):
     """
     A convenience wrapper for setting directories. For now, is only
     used for "read_dir".
     """
     original_dir = getattr(self, attr_name)
     dir = original_dir if original_dir else "/"
     dir = PathPicker(dir, self.i, self.o, dirs_only=True).activate()
     if dir:
         setattr(self, attr_name, dir)
         self.config[config_option_name] = dir
         self.save_config()
         return True
Exemplo n.º 8
0
def init_app(input, output):
    global callback, i, o
    i = input
    o = output
    lb_contents = [["Very long listbox option name", 1],
                   ["Even longer option name", 2]]
    lb = Listbox(lb_contents, i, o, "Scrolling test listbox")
    pp = PathPicker('/', i, o)
    main_menu_contents = [["Command with very long name", lb.activate],
                          ["Command with an even longer name", pp.activate],
                          ["Exit", 'exit']]
    main_menu = Menu(main_menu_contents, i, o, "Scrolling test menu")
    callback = main_menu.activate
Exemplo n.º 9
0
def call_by_path():
    path = PathPicker("/", i, o).activate()
    if path is None:
        return
    args = UniversalInput(i,
                          o,
                          message="Arguments:",
                          name="Script argument input").activate()
    if args is not None:
        path = path + " " + args
    call_external(path, shell=True)
    if path not in config["history"]:
        config["history"] = [path] + config["history"]
        save_config(config)
Exemplo n.º 10
0
def save_output(command, output):
    if not isinstance(command, basestring):
        command = " ".join(command)
    command = command.lstrip("/").replace("/", "_")
    now = datetime.now()
    filename = "log-{}-{}".format(command, now.strftime("%y%m%d-%H%M%S"))
    print(filename)
    old_dir = config["output_dir"]
    dir = PathPicker(old_dir, i, o, dirs_only=True).activate()
    if not dir:
        return
    # Saving the path into the config
    config["output_dir"] = dir
    save_config(config)
    path = os.path.join(dir, filename)
    print(path)
    with open(path, "w") as f:
        f.write(output)
Exemplo n.º 11
0
 def set_file(self, dir, attr_name, config_option_name):
     """
     A function for selecting files (specifically, a full path to an existing
     file. For now, is only used for "write_file".
     """
     original_file = getattr(self, attr_name)
     dir, filename = os.path.split(original_file)
     # The original dir might not exist anymore, we might need to go through directories
     # until we find a working one
     while dir and not (os.path.exists(dir) and os.path.isdir(dir)):
         dir = os.path.split(dir)[0]
     if not dir:
         dir = '/'
     file = PathPicker(dir, self.i, self.o, file=filename).activate()
     if file and os.path.isfile(file):
         setattr(self, attr_name, file)
         self.config[config_option_name] = file
         self.save_config()
         return True
Exemplo n.º 12
0
 def add_dir():
     default_path = PathPicker.default_path if not file_list else file_list[-1]
     path = PathPicker(default_path, i, o, dirs_only=True, name="Bugreport app custom file picker PathPicker", display_hidden = True).activate()
     if path:
         file_list.append(path)
Exemplo n.º 13
0
def change_file():
    global file_path
    file_path = PathPicker('/', i, o).activate()
Exemplo n.º 14
0
def browse():
    path_picker = PathPicker("/", i, o)
    path_picker.activate()  #Menu yet to be added
Exemplo n.º 15
0
Arquivo: main.py Projeto: joha2/pyLCI
def browse():
    #"File options" menu yet to be added
    path_picker = PathPicker("/", i, o, callback=print_path)
    path_picker.activate()