Exemplo n.º 1
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 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)
Exemplo n.º 3
0
 def __listbox_event_cb(self, listbox, event):
     shortcuts = {
         'k': (self._do_move, [-1]),
         'j': (self._do_move, [+1]),
         'Up': (self._do_move, [-1]),
         'Down': (self._do_move, [+1]),
         '0': (listbox.select_row, [self._first_row])
     }
     return process_shortcuts(shortcuts, event)
Exemplo n.º 4
0
 def do_event(self, event):
     shortcuts = {
         'a': (self.get_toplevel().goto_sublist,
               ['/u/{}'.format(self.data['author'])]),
     }
     if self.data.get('subreddit'):
         shortcuts['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'])]),
     }
     if self.data.get('subreddit'):
         shortcuts['s'] = (
             self.get_toplevel().goto_sublist,
             ['/r/{}'.format(self.data['subreddit'])],
         )
     return process_shortcuts(shortcuts, event)
Exemplo n.º 6
0
 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)
    def do_event(self, event):
        def move(direction, jump):
            if jump:
                row = self._selected
                while isinstance(row, CommentRow) and row.depth > 0:
                    # Walk up to next CommentRow
                    row = row.get_parent()
                    while not isinstance(row, CommentRow):
                        row = row.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:
                self.select_row(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)
Exemplo n.º 9
0
    def do_event(self, event):
        def move(direction, jump):
            if jump:
                row = self._selected
                while isinstance(row, CommentRow) and row.depth > 0:
                    # Walk up to next CommentRow
                    row = row.get_parent()
                    while not isinstance(row, CommentRow):
                        row = row.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:
                self.select_row(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)
Exemplo n.º 10
0
def test_process_shortcuts():
    up_cb = MagicMock()
    k_cb = MagicMock()

    shortcuts = {
        'Up': (up_cb, ['up']),
        '<Ctrl>k': (k_cb, ['k']),
    }

    gtkutil.process_shortcuts(shortcuts, fake_event('a', event_type=None))
    assert not up_cb.called
    assert not k_cb.called

    gtkutil.process_shortcuts(shortcuts, fake_event(65362))
    assert up_cb.called
    assert up_cb.call_args[0] == ('up',)

    gtkutil.process_shortcuts(shortcuts, fake_event('k'))
    assert not k_cb.called

    gtkutil.process_shortcuts(shortcuts, fake_event('k', ctrl=True))
    assert k_cb.called
    assert k_cb.call_args[0] == ('k',)
 def __event_cb(self, textview, event):
     shortcuts = {
         '<Ctrl>Return': (self.__done_clicked_cb, [None])
     }
     return process_shortcuts(shortcuts, event)
Exemplo n.º 12
0
 def __event_cb(self, textview, event):
     shortcuts = {'<Ctrl>Return': (self.__done_clicked_cb, [None])}
     return process_shortcuts(shortcuts, event)