def command(self, size, command, args): def deep_fold(): walker = self.walker node = walker.focus_node() if node.expanded: # we should fold the current node node.fold() else: # let's visit the parent pos = walker.focus_pos() if len(pos) > 1: walker.set_focus(pos[:-1]) else: # TODO: tell the user? pass commands = { 'activate': self.walker.focus_node().toggle_exp, 'expand': self.walker.focus_node().expand, 'fold': deep_fold, 'add': self.walker.focus_node().add_to_playlist, 'yank': self.walker.focus_node().save_to_buffer, } if command in commands: if self.walker.focus_node(): commands[command]() return True else: return ScrollableList.command(self, size, command, args)
def mouse_event(self, size, event, button, col, row, focus): if event == "mouse press" and (button == 3 or button == 11): actions = { # left button 3: self.walker.toggle_select, # double click (right) 11: self.walker.goto, } # select item under the mouse offset, inset = self.get_focus_offset_inset(size) self.move_focus(size, row - offset) actions[button]() else: ScrollableList.mouse_event(self, size, event, button, col, row, focus)
def mouse_event(self, size, event, button, col, row, focus): if event == 'mouse press' and button == 3 or button == 11: actions = { # left button 3: lambda node: node.toggle_exp(), # double click (right) 11: lambda node: node.add_to_playlist(), } # select item under the mouse offset, inset = self.get_focus_offset_inset(size) self.move_focus(size, row - offset) node = self.walker.focus_node() if node: actions[button](node) else: ScrollableList.mouse_event(self, size, event, button, col, row, focus)
def command(self, size, command, args): def toggle_walk(): self.walker.toggle_select() self.move_focus(size, 1) commands = { "delete": self.walker.delete_entry, "mark": toggle_walk, "reset_mark": self.walker.clear_select, "activate": self.walker.goto, "move_up": self.walker.move_up, "move_down": self.walker.move_down, "paste": self.walker.insert_buffer, "yank": self.walker.yank_entry, } if command in commands: commands[command]() return True else: return ScrollableList.command(self, size, command, args)