Exemple #1
0
    def keypress(self, size, key):
        """allow subclasses to intercept keystrokes"""
        key = self.__super.keypress(size, key)

        this_node = self.get_node().get_value()
        parent_node = this_node if (self.get_node().get_parent() is None or this_node.nodetype == "folder") \
            else self.get_node().get_parent().get_value()

        if key == "enter":
            if isinstance(self.get_node(), UITreeNode):
                close_ui_and_run(this_node.hostinfo.get_ssh_command())

        if key in ("-", "left") and not self.is_leaf:
            self.expanded = False
            self.update_expanded_icon()

        elif key == "f5" and self.is_leaf:
            if package_available(package_name="mc"):
                close_ui_and_run(this_node.hostinfo.get_mc_command())
            else:
                MessageDialog(
                    State, "Error",
                    "Please install mc (Midnight Commander) package"
                    " to use this feature", reset_layout).show()

        elif key == "f6":
            AddFolderDialog(State, parent_node, Node("", "folder"),
                            reload_data).show()

        elif key == "f7":
            AddHostDialog(State, parent_node, Node("", "session",
                                                   HostInfo("")),
                          reload_data).show()

        elif key == "f8":
            if this_node.nodetype == "folder":
                # TODO implement removing folder
                MessageDialog(State, "Error", "Folders can not be removed",
                              reload_data).show()
            else:
                RemoveHostDialog(State, parent_node, this_node,
                                 reload_data).show()
        elif key == "f9" and self.is_leaf:
            AddHostDialog(State, parent_node, this_node, reload_data).show()
        elif key in ('q', 'Q'):
            close_ui_and_exit()
        return key
Exemple #2
0
    def on_key_press(self, key: str, w: UITreeWidget):
        this_node = w.get_node().get_value()
        folder_node = this_node if (w.get_node().get_parent() is None or this_node.nodetype == "folder") \
            else w.get_node().get_parent().get_value()

        parent_node = None if w.get_node().get_parent(
        ) is None else w.get_node().get_parent().get_value()

        if key in ['q', 'Q', 'ctrl d']:
            self.command = EXIT_REDIAL
            raise urwid.ExitMainLoop()

        elif key == "enter":
            if isinstance(w.get_node(), UITreeNode):
                self.command = w.get_node().get_value(
                ).hostinfo.get_ssh_command()
                raise urwid.ExitMainLoop()

        elif key == "f3" and w.is_leaf:
            if (len(get_public_ssh_keys())) == 0:
                MessageDialog(
                    "Error",
                    "There is no public SSH Key (.pub) in ~/.ssh folder. You can use ssh-keygen to "
                    "generate SSH key pairs",
                    self.close_dialog).show(self.loop)
            else:
                self.log = "SSH key is copied successfully"
                CopySSHKeyDialog(this_node, self.close_dialog_and_run,
                                 self.change_log).show(self.loop)

        elif key == "f5" and w.is_leaf:
            if package_available(package_name="mc"):
                self.command = this_node.hostinfo.get_mc_command()
                raise urwid.ExitMainLoop()
            else:
                MessageDialog(
                    "Error", "Please install mc (Midnight Commander) package"
                    " to use this feature", self.close_dialog).show(self.loop)

        elif key == "f6":
            AddFolderDialog(folder_node, Node("", "folder"),
                            self.save_and_focus).show(self.loop)

        elif key == "f7":
            AddHostDialog(folder_node, Node("", "session", HostInfo("")),
                          self.save_and_focus).show(self.loop)

        elif key == "f8":
            if this_node.nodetype == "folder":
                # TODO implement removing folder
                MessageDialog("Error", "Folders can not be removed",
                              self.close_dialog).show(self.loop)
            else:
                RemoveHostDialog(parent_node, this_node,
                                 self.save_and_focus).show(self.loop)

        elif key == "f9" and w.is_leaf:
            AddHostDialog(parent_node, this_node,
                          self.save_and_focus).show(self.loop)

        elif key in ["meta down", "ctrl down"]:
            if parent_node is None: return
            i = parent_node.children.index(this_node)
            if i == len(parent_node.children) - 1: return  # at bottom
            parent_node.children[i], parent_node.children[
                i + 1] = parent_node.children[i + 1], parent_node.children[i]

            self.save_and_focus(this_node)

        elif key in ["meta up", "ctrl up"]:
            if parent_node is None: return
            i = parent_node.children.index(this_node)
            if i == 0: return  # at top
            parent_node.children[i], parent_node.children[
                i - 1] = parent_node.children[i - 1], parent_node.children[i]

            self.save_and_focus(this_node)
        else:
            return key
Exemple #3
0
    def on_key_press(self, key: str, w: UITreeWidget):
        this_node = w.get_node().get_value()
        folder_node = this_node if (w.get_node().get_parent() is None or this_node.nodetype == "folder") \
            else w.get_node().get_parent().get_value()

        parent_node = None if w.get_node().get_parent(
        ) is None else w.get_node().get_parent().get_value()

        if key in 'qQ':
            self.command = EXIT_REDIAL
            raise urwid.ExitMainLoop()

        elif key == "enter":
            if isinstance(w.get_node(), UITreeNode):
                self.command = w.get_node().get_value(
                ).hostinfo.get_ssh_command()
                raise urwid.ExitMainLoop()

        elif key == "f5" and w.is_leaf:
            if package_available(package_name="mc"):
                self.command = this_node.hostinfo.get_mc_command()
                raise urwid.ExitMainLoop()
            else:
                MessageDialog(
                    "Error", "Please install mc (Midnight Commander) package"
                    " to use this feature", self.close_dialog).show(self.loop)

        elif key == "f6":
            AddFolderDialog(folder_node, Node("", "folder"),
                            self.save_and_focus).show(self.loop)

        elif key == "f7":
            AddHostDialog(folder_node, Node("", "session", HostInfo("")),
                          self.save_and_focus).show(self.loop)

        elif key == "f8":
            if this_node.nodetype == "folder":
                # TODO implement removing folder
                MessageDialog("Error", "Folders can not be removed",
                              self.close_dialog).show(self.loop)
            else:
                RemoveHostDialog(parent_node, this_node,
                                 self.save_and_focus).show(self.loop)

        elif key == "f9" and w.is_leaf:
            AddHostDialog(parent_node, this_node,
                          self.save_and_focus).show(self.loop)

        elif key in ["meta down", "ctrl down"]:
            if parent_node is None: return
            i = parent_node.children.index(this_node)
            if i == len(parent_node.children) - 1: return  # at bottom
            parent_node.children[i], parent_node.children[
                i + 1] = parent_node.children[i + 1], parent_node.children[i]

            Config.save_to_file(self.sessions)
            self.walker.set_focus(
                UIParentNode(self.sessions, key_handler=self.on_key_press))
            self.listbox.set_focus_to_node(this_node)

        elif key in ["meta up", "ctrl up"]:
            if parent_node is None: return
            i = parent_node.children.index(this_node)
            if i == 0: return  # at top
            parent_node.children[i], parent_node.children[
                i - 1] = parent_node.children[i - 1], parent_node.children[i]

            Config.save_to_file(self.sessions)
            self.walker.set_focus(
                UIParentNode(self.sessions, key_handler=self.on_key_press))
            self.listbox.set_focus_to_node(this_node)
        else:
            return key
Exemple #4
0
 def run(self):
     if self.command_return_key == 0 and self.log is not None:
         MessageDialog("Info", self.log, self.close_dialog).show(self.loop)
         self.log = None
     self.loop.run()