def __listbox_event_cb(self, listbox, event):
        def move(direction):
            focused = listbox.get_toplevel().get_focus()
            if focused.get_parent() == listbox:
                s = focused
            else:
                s = listbox.get_selected_row() or self._first_row
            row = listbox.get_row_at_index(s.get_index() + direction)
            if row is not None:
                row.grab_focus()
            else:
                # We went too far!
                s.error_bell()
                s.get_style_context().remove_class('angry')
                s.get_style_context().add_class('angry')
                GLib.timeout_add(
                    500,
                    s.get_style_context().remove_class,
                    'angry')

        shortcuts = {
            'k': (move, [-1]),
            'j': (move, [+1]),
            'Up': (move, [-1]),
            'Down': (move, [+1]),
            '0': (listbox.select_row, [self._first_row])
        }
        return process_shortcuts(shortcuts, event)
Example #2
0
    def do_event(self, event):
        def toggle(button):
            button.props.active = not button.props.active

        def activate(button):
            button.props.active = True

        shortcuts = {
            'u': (self._sbb.vote, [+1]),
            'd': (self._sbb.vote, [-1]),
            'n': (self._sbb.vote, [0]),
            'f': (toggle, [self._favorite]),
            't': (activate, [self._time_button]),
            'a': (self.get_toplevel().goto_sublist,
                  ['/u/{}'.format(self.data['author'])]),
            's': (self.get_toplevel().goto_sublist,
                  ['/r/{}'.format(self.data['subreddit'])]),
            'r': (self.show_reply, []),
            'space': (toggle, [self.expand]),
            # The ListBoxRow usually eats these shortcuts, but we want
            # the ListBox to handle them, so we need to pass it up
            'Up': (self._toplevel_cv.do_event, [event]),
            'Down': (self._toplevel_cv.do_event, [event]),
        }
        return process_shortcuts(shortcuts, event)
    def __listbox_event_cb(self, listbox, event):
        def move(direction):
            focused = listbox.get_toplevel().get_focus()
            if focused.get_parent() == listbox:
                s = focused
            else:
                s = listbox.get_selected_row() or self._first_row
            row = listbox.get_row_at_index(s.get_index() + direction)
            if row is not None:
                row.grab_focus()
            else:
                # We went too far!
                s.error_bell()
                s.get_style_context().remove_class('angry')
                s.get_style_context().add_class('angry')
                GLib.timeout_add(500,
                                 s.get_style_context().remove_class, 'angry')

        shortcuts = {
            'k': (move, [-1]),
            'j': (move, [+1]),
            'Up': (move, [-1]),
            'Down': (move, [+1]),
            '0': (listbox.select_row, [self._first_row])
        }
        return process_shortcuts(shortcuts, event)
    def do_event(self, event):
        def toggle(button):
            button.props.active = not button.props.active

        def activate(button):
            button.props.active = True

        shortcuts = {
            'u': (self._sbb.vote, [+1]),
            'd': (self._sbb.vote, [-1]),
            'n': (self._sbb.vote, [0]),
            'f': (toggle, [self._favorite]),
            't': (activate, [self._time_button]),
            'a': (self.get_toplevel().goto_sublist,
                  ['/u/{}'.format(self.data['author'])]),
            's': (self.get_toplevel().goto_sublist,
                  ['/r/{}'.format(self.data['subreddit'])]),
            'r': (self.show_reply, []),
            'space': (toggle, [self.expand]),
            # The ListBoxRow usually eats these shortcuts, but we want
            # the ListBox to handle them, so we need to pass it up
            'Up': (self._toplevel_cv.do_event, [event]),
            'Down': (self._toplevel_cv.do_event, [event]),
        }
        return process_shortcuts(shortcuts, event)
 def do_event(self, event):
     shortcuts = {
         'a': (self.get_toplevel().goto_sublist,
               ['/u/{}'.format(self.data['author'])]),
         's': (self.get_toplevel().goto_sublist,
               ['/r/{}'.format(self.data['subreddit'])]),
     }
     return process_shortcuts(shortcuts, event)
 def do_event(self, event):
     shortcuts = {
         'a': (self.get_toplevel().goto_sublist,
               ['/u/{}'.format(self.data['author'])]),
         's': (self.get_toplevel().goto_sublist,
               ['/r/{}'.format(self.data['subreddit'])]),
     }
     return process_shortcuts(shortcuts, event)
    def do_event(self, event):
        def move(direction, jump):
            if jump:
                row = self._selected
                while isinstance(row, CommentRow) and row.depth > 0:
                    # FIXME:  This must be bad
                    # Me > List > Box > Revealer > Box > Next Row!!
                    row = row.get_parent().get_parent().get_parent() \
                             .get_parent().get_parent()
                kids = [self._top] + self._comments.get_children()
                i = kids.index(row)
                if 0 <= i + direction < len(kids):
                    row = kids[i + direction]
            else:
                i = self._all_comments.index(self._selected)
                row = None
                while 0 <= i + direction < len(self._all_comments):
                    row = self._all_comments[i + direction]
                    if row.get_mapped():
                        break
                    else:
                        i += direction
                        row = None

            if row is not None:
                row.grab_focus()
                self._selected = row
            else:
                # We went too far!
                self.error_bell()
                self._selected.get_style_context().remove_class('angry')
                self._selected.get_style_context().add_class('angry')
                GLib.timeout_add(
                    500,
                    self._selected.get_style_context().remove_class,
                    'angry')

        def load_full():
            if self._load_full is not None:
                self.__load_full_cb(None)

        shortcuts = {
            'k': (move, [-1, False]),
            'j': (move, [+1, False]),
            'Up': (move, [-1, False]),
            'Down': (move, [+1, False]),
            'h': (move, [-1, True]),
            'l': (move, [+1, True]),
            'Left': (move, [-1, True]),
            'Right': (move, [+1, True]),
            '<ctrl>f': (load_full, []),
            '<ctrl>r': (self.refresh, []),
        }
        return process_shortcuts(shortcuts, event)
 def do_event(self, event):
     shortcuts = {
         'u': (self._sbb.vote, [+1]),
         'd': (self._sbb.vote, [-1]),
         'n': (self._sbb.vote, [0]),
         'c': (self.goto_comments.emit, []),
         'a': (self.get_toplevel().goto_sublist,
               ['/u/{}'.format(self.data['author'])]),
         's': (self.get_toplevel().goto_sublist,
               ['/r/{}'.format(self.data['subreddit'])]),
     }
     return process_shortcuts(shortcuts, event)
 def do_event(self, event):
     shortcuts = {
         'u': (self._sbb.vote, [+1]),
         'd': (self._sbb.vote, [-1]),
         'n': (self._sbb.vote, [0]),
         'c': (self.goto_comments.emit, []),
         'a': (self.get_toplevel().goto_sublist,
               ['/u/{}'.format(self.data['author'])]),
         's': (self.get_toplevel().goto_sublist,
               ['/r/{}'.format(self.data['subreddit'])]),
     }
     return process_shortcuts(shortcuts, event)
Example #10
0
    def do_event(self, event):
        def move(direction, jump):
            if jump:
                row = self._selected
                while isinstance(row, CommentRow) and row.depth > 0:
                    # FIXME:  This must be bad
                    # Me > List > Box > Revealer > Box > Next Row!!
                    row = row.get_parent().get_parent().get_parent() \
                             .get_parent().get_parent()
                kids = [self._top] + self._comments.get_children()
                i = kids.index(row)
                if 0 <= i + direction < len(kids):
                    row = kids[i + direction]
            else:
                f = self._get_next_row if direction > 0 else self._get_prev_row
                while True:
                    row = f(self._selected)
                    if row is None or row.get_mapped():
                        break

            if row is not None:
                row.grab_focus()
                self._selected = row
            else:
                # We went too far!
                self.error_bell()
                self._selected.get_style_context().remove_class('angry')
                self._selected.get_style_context().add_class('angry')
                GLib.timeout_add(
                    500,
                    self._selected.get_style_context().remove_class, 'angry')

        def load_full():
            if self._load_full is not None:
                self.__load_full_cb(None)

        shortcuts = {
            'k': (move, [-1, False]),
            'j': (move, [+1, False]),
            'Up': (move, [-1, False]),
            'Down': (move, [+1, False]),
            'h': (move, [-1, True]),
            'l': (move, [+1, True]),
            'Left': (move, [-1, True]),
            'Right': (move, [+1, True]),
            '<ctrl>f': (load_full, []),
            '<ctrl>r': (self.refresh, []),
        }
        return process_shortcuts(shortcuts, event)
Example #11
0
 def __event_cb(self, textview, event):
     shortcuts = {'<Ctrl>Return': (self.__done_clicked_cb, [None])}
     return process_shortcuts(shortcuts, event)
 def __event_cb(self, textview, event):
     shortcuts = {
         '<Ctrl>Return': (self.__done_clicked_cb, [None])
     }
     return process_shortcuts(shortcuts, event)