Exemplo n.º 1
0
    def __key_press(self, songlist, event, librarian):
        rating_accels = [
            "<ctrl>%d" % i for i in range(min(10, config.RATINGS.number + 1))]

        if qltk.is_accel(event, *rating_accels):
            rating = int(chr(event.keyval)) * config.RATINGS.precision
            self.__set_rating(rating, self.get_selected_songs(), librarian)
            return True
        elif qltk.is_accel(event, "<ctrl>Return", "<ctrl>KP_Enter"):
            self.__enqueue(self.get_selected_songs())
            return True
        elif qltk.is_accel(event, "<control>F"):
            self.emit('start-interactive-search')
            return True
        elif qltk.is_accel(event, "<alt>Return"):
            songs = self.get_selected_songs()
            if songs:
                window = SongProperties(librarian, songs, parent=self)
                window.show()
            return True
        elif qltk.is_accel(event, "<control>I"):
            songs = self.get_selected_songs()
            if songs:
                window = Information(librarian, songs, self)
                window.show()
            return True
        return False
Exemplo n.º 2
0
 def __key_press(self, songlist, event, librarian):
     if qltk.is_accel(event, "<Primary>Return", "<Primary>KP_Enter"):
         self.__enqueue(self.get_selected_songs())
         return True
     elif qltk.is_accel(event, "<Primary>F"):
         self.emit('start-interactive-search')
         return True
     elif qltk.is_accel(event, "<Primary>Delete"):
         songs = self.get_selected_songs()
         if songs:
             trash_songs(self, songs, librarian)
         return True
     elif qltk.is_accel(event, "<alt>Return"):
         songs = self.get_selected_songs()
         if songs:
             window = SongProperties(librarian, songs, parent=self)
             window.show()
         return True
     elif qltk.is_accel(event, "<Primary>I"):
         songs = self.get_selected_songs()
         if songs:
             window = Information(librarian, songs, self)
             window.show()
         return True
     return False
Exemplo n.º 3
0
 def __sb_key_pressed(self, entry, event):
     if (is_accel(event, "<Primary>Return") or
             is_accel(event, "<Primary>KP_Enter")):
         songs = app.window.songlist.get_songs()
         app.window.playlist.enqueue(songs)
         return True
     return False
Exemplo n.º 4
0
    def __key_pressed(self, widget, event):
        if qltk.is_accel(event, "Delete"):
            model, iter = self.__selected_playlists()
            if not iter:
                return False

            playlist = model[iter][0]
            dialog = ConfirmRemovePlaylistDialog(self, playlist)
            if dialog.run() == Gtk.ResponseType.YES:
                playlist.delete()
                model.get_model().remove(
                    model.convert_iter_to_child_iter(iter))
            return True
        elif qltk.is_accel(event, "F2"):
            model, iter = self.__selected_playlists()
            if iter:
                self._start_rename(model.get_path(iter))
            return True
        elif qltk.is_accel(event, "<Primary>I"):
            songs = self._get_playlist_songs()
            if songs:
                window = Information(self.library.librarian, songs, self)
                window.show()
            return True
        elif qltk.is_accel(event, "<Primary>Return", "<Primary>KP_Enter"):
            qltk.enqueue(self._get_playlist_songs())
            return True
        elif qltk.is_accel(event, "<alt>Return"):
            songs = self._get_playlist_songs()
            if songs:
                window = SongProperties(self.library.librarian, songs, self)
                window.show()
            return True
        return False
Exemplo n.º 5
0
    def test_is_accel(self):
        e = gtk.gdk.Event(gtk.gdk.KEY_RELEASE)
        self.failIf(qltk.is_accel(e, "a"))

        e = gtk.gdk.Event(gtk.gdk.KEY_PRESS)
        e.keyval = 65293
        e.state =  gtk.gdk.CONTROL_MASK
        self.failUnless(qltk.is_accel(e, "<ctrl>Return"))
Exemplo n.º 6
0
 def __key_press(self, entry, event):
     if is_accel(event, "<Primary>z"):
         self.undo()
         return True
     elif is_accel(event, "<Primary><shift>z"):
         self.redo()
         return True
     return False
Exemplo n.º 7
0
 def __view_key_press_event(self, view, event):
     if qltk.is_accel(event, "Delete"):
         self.__remove_tag(view, view)
         return Gdk.EVENT_STOP
     elif qltk.is_accel(event, "<Primary>s"):
         # Issue 697: allow Ctrl-s to save.
         self._save.emit('clicked')
         return Gdk.EVENT_STOP
     return Gdk.EVENT_PROPAGATE
Exemplo n.º 8
0
 def __key_press(self, songlist, event, librarian):
     if event.string in ['0', '1', '2', '3', '4']:
         rating = min(1.0, int(event.string) * util.RATING_PRECISION)
         self.__set_rating(rating, self.get_selected_songs(), librarian)
         return True
     elif qltk.is_accel(event, "<ctrl>Return") or \
         qltk.is_accel(event, "<ctrl>KP_Enter"):
         self.__enqueue(self.get_selected_songs())
         return True
     elif qltk.is_accel(event, "<control>F"):
         self.emit('start-interactive-search')
         return True
     return False
Exemplo n.º 9
0
 def __key_pressed(self, widget, event, librarian):
     if qltk.is_accel(event, "<Primary>I"):
         songs = self.__get_selected_songs()
         if songs:
             window = Information(librarian, songs, self)
             window.show()
         return True
     elif qltk.is_accel(event, "<alt>Return"):
         songs = self.__get_selected_songs()
         if songs:
             window = SongProperties(librarian, songs, self)
             window.show()
         return True
     return False
Exemplo n.º 10
0
    def test_is_accel(self):
        e = Gdk.Event.new(Gdk.EventType.KEY_RELEASE)
        self.failIf(qltk.is_accel(e, "a"))

        e = Gdk.Event.new(Gdk.EventType.KEY_PRESS)
        e.keyval = Gdk.KEY_Return
        e.state = Gdk.ModifierType.CONTROL_MASK
        self.failUnless(qltk.is_accel(e, "<ctrl>Return"))

        e = Gdk.Event.new(Gdk.EventType.KEY_PRESS)
        e.keyval = Gdk.KEY_Return
        e.state = Gdk.ModifierType.CONTROL_MASK
        self.failUnless(qltk.is_accel(e, "a", "<ctrl>Return"))
        self.failUnless(qltk.is_accel(e, "<ctrl>Return", "b"))
        self.failIf(qltk.is_accel(e, "a", "b"))
Exemplo n.º 11
0
 def __key_pressed(self, widget, event):
     # alt+X switches to page X
     for i in xrange(self.get_n_pages()):
         if is_accel(event, "<alt>%d" % (i + 1)):
             self.set_current_page(i)
             return True
     return False
Exemplo n.º 12
0
    def __key_pressed(self, player, event):
        if not player.song:
            return

        def seek_relative(seconds):
            current = player.get_position()
            current += seconds * 1000
            current = min(player.song("~#length") * 1000 -1, current)
            current = max(0, current)
            player.seek(current)

        if qltk.is_accel(event, "<alt>Right"):
            seek_relative(10)
            return True
        elif qltk.is_accel(event, "<alt>Left"):
            seek_relative(-10)
            return True
Exemplo n.º 13
0
    def __key_pressed(self, widget, event, player):
        if not player.song:
            return

        def seek_relative(seconds):
            current = player.get_position()
            current += seconds * 1000
            current = min(player.song("~#length") * 1000 - 1, current)
            current = max(0, current)
            player.seek(current)

        if qltk.is_accel(event, "<alt>Right"):
            seek_relative(10)
            return True
        elif qltk.is_accel(event, "<alt>Left"):
            seek_relative(-10)
            return True
Exemplo n.º 14
0
    def test_is_accel(self):
        RETURN = 65293

        e = Gdk.Event.new(Gdk.EventType.KEY_RELEASE)
        self.failIf(qltk.is_accel(e, "a"))

        e = Gdk.Event.new(Gdk.EventType.KEY_PRESS)
        e.keyval = RETURN
        e.state = Gdk.ModifierType.CONTROL_MASK
        self.failUnless(qltk.is_accel(e, "<ctrl>Return"))

        e = Gdk.Event.new(Gdk.EventType.KEY_PRESS)
        e.keyval = RETURN
        e.state = Gdk.ModifierType.CONTROL_MASK
        self.failUnless(qltk.is_accel(e, "a", "<ctrl>Return"))
        self.failUnless(qltk.is_accel(e, "<ctrl>Return", "b"))
        self.failIf(qltk.is_accel(e, "a", "b"))
Exemplo n.º 15
0
 def __key_pressed(self, widget, event, librarian):
     if qltk.is_accel(event, "<Primary>I"):
         songs = self.__get_selected_songs()
         if songs:
             window = Information(librarian, songs, self)
             window.show()
         return True
     elif qltk.is_accel(event, "<Primary>Return", "<Primary>KP_Enter"):
         qltk.enqueue(self.__get_selected_songs(sort=True))
         return True
     elif qltk.is_accel(event, "<alt>Return"):
         songs = self.__get_selected_songs()
         if songs:
             window = SongProperties(librarian, songs, self)
             window.show()
         return True
     return False
Exemplo n.º 16
0
    def _on_key_press(self, widget, event):
        is_dialog = self.get_type_hint() == Gdk.WindowTypeHint.DIALOG

        if (is_dialog and is_accel(event, "Escape")) or (not is_dialog and is_accel(event, "<Primary>w")):
            # Do not close the window if we edit a Gtk.CellRendererText.
            # Focus the treeview instead.
            if isinstance(self.get_focus(), Gtk.Entry) and isinstance(self.get_focus().get_parent(), Gtk.TreeView):
                self.get_focus().get_parent().grab_focus()
                return Gdk.EVENT_PROPAGATE
            self.close()
            return Gdk.EVENT_STOP

        if not is_dialog and is_accel(event, "F11"):
            self.toggle_fullscreen()
            return Gdk.EVENT_STOP

        return Gdk.EVENT_PROPAGATE
Exemplo n.º 17
0
    def _on_key_press(self, widget, event):
        is_dialog = (self.get_type_hint() == Gdk.WindowTypeHint.DIALOG)

        if (is_dialog and is_accel(event, "Escape")) or (
                not is_dialog and is_accel(event, "<Primary>w")):
            # Do not close the window if we edit a Gtk.CellRendererText.
            # Focus the treeview instead.
            if isinstance(self.get_focus(), Gtk.Entry) and \
                isinstance(self.get_focus().get_parent(), Gtk.TreeView):
                self.get_focus().get_parent().grab_focus()
                return Gdk.EVENT_PROPAGATE
            self.close()
            return Gdk.EVENT_STOP

        if not is_dialog and is_accel(event, "F11"):
            self.toggle_fullscreen()
            return Gdk.EVENT_STOP

        return Gdk.EVENT_PROPAGATE
Exemplo n.º 18
0
    def __key_pressed(self, widget, event):
        if qltk.is_accel(event, "Delete"):
            model, iter = self.__view.get_selection().get_selected()
            if not iter:
                return False

            playlist = model[iter][0]
            dialog = ConfirmRemovePlaylistDialog(self, playlist)
            if dialog.run() == Gtk.ResponseType.YES:
                playlist.delete()
                model.get_model().remove(
                    model.convert_iter_to_child_iter(iter))
            return True
        elif qltk.is_accel(event, "F2"):
            model, iter = self.__view.get_selection().get_selected()
            if iter:
                self._start_rename(model.get_path(iter))
            return True
        return False
Exemplo n.º 19
0
    def __key_pressed(self, widget, event):
        if qltk.is_accel(event, "Delete"):
            model, iter = self.__selected_playlists()
            if not iter:
                return False

            playlist = model[iter][0]
            dialog = ConfirmRemovePlaylistDialog(self, playlist)
            if dialog.run() == Gtk.ResponseType.YES:
                playlist.delete()
                model.get_model().remove(
                    model.convert_iter_to_child_iter(iter))
            return True
        elif qltk.is_accel(event, "F2"):
            model, iter = self.__selected_playlists()
            if iter:
                self._start_rename(model.get_path(iter))
            return True
        return False
Exemplo n.º 20
0
 def do_key_press_event(self, event):
     if is_accel(event, "space", "KP_Space"):
         selection = self.get_selection()
         fmodel, fiter = selection.get_selected()
         plugin = fmodel.get_value(fiter)
         if plugin.can_enable:
             self._emit_toggled(fmodel.get_path(fiter),
                                not plugin_enabled(plugin))
         self.get_model().iter_changed(fiter)
     else:
         Gtk.TreeView.do_key_press_event(self, event)
Exemplo n.º 21
0
 def do_key_press_event(self, event):
     if is_accel(event, "space", "KP_Space"):
         selection = self.get_selection()
         fmodel, fiter = selection.get_selected()
         plugin = fmodel.get_value(fiter)
         if plugin.can_enable:
             self._emit_toggled(fmodel.get_path(fiter),
                                not plugin_enabled(plugin))
         self.get_model().iter_changed(fiter)
     else:
         Gtk.TreeView.do_key_press_event(self, event)
Exemplo n.º 22
0
 def __key_pressed(self, view, event, librarian):
     # if ctrl+a is pressed, intercept and select the All entry instead
     if is_accel(event, "<Primary>a"):
         self.set_selected([])
         return True
     elif is_accel(event, "<Primary>Return", "<Primary>KP_Enter"):
         self.__enqueue(self.__get_selected_songs(sort=True))
         return True
     elif is_accel(event, "<alt>Return"):
         songs = self.__get_selected_songs(sort=True)
         if songs:
             window = SongProperties(librarian, songs, parent=self)
             window.show()
         return True
     elif is_accel(event, "<Primary>I"):
         songs = self.__get_selected_songs(sort=True)
         if songs:
             window = Information(librarian, songs, self)
             window.show()
         return True
     return False
Exemplo n.º 23
0
 def __key_pressed(self, view, event, librarian):
     # if ctrl+a is pressed, intercept and select the All entry instead
     if is_accel(event, "<Primary>a"):
         self.set_selected([])
         return True
     elif is_accel(event, "<Primary>Return", "<Primary>KP_Enter"):
         qltk.enqueue(self.__get_selected_songs(sort=True))
         return True
     elif is_accel(event, "<alt>Return"):
         songs = self.__get_selected_songs(sort=True)
         if songs:
             window = SongProperties(librarian, songs, parent=self)
             window.show()
         return True
     elif is_accel(event, "<Primary>I"):
         songs = self.__get_selected_songs(sort=True)
         if songs:
             window = Information(librarian, songs, self)
             window.show()
         return True
     return False
Exemplo n.º 24
0
 def __key_press(self, songlist, event, librarian, player):
     if qltk.is_accel(event, "<Primary>Return", "<Primary>KP_Enter"):
         self.__enqueue(self.get_selected_songs())
         return True
     elif qltk.is_accel(event, "<Primary>F"):
         self.emit('start-interactive-search')
         return True
     elif qltk.is_accel(event, "<Primary>Delete"):
         songs = self.get_selected_songs()
         if songs:
             trash_songs(self, songs, librarian)
         return True
     elif qltk.is_accel(event, "<alt>Return"):
         songs = self.get_selected_songs()
         if songs:
             window = SongProperties(librarian, songs, parent=self)
             window.show()
         return True
     elif qltk.is_accel(event, "<Primary>I"):
         songs = self.get_selected_songs()
         if songs:
             window = Information(librarian, songs, self)
             window.show()
         return True
     elif qltk.is_accel(event, "space", "KP_Space") and player is not None:
         player.paused = not player.paused
         return True
     return False
Exemplo n.º 25
0
    def __key_pressed(self, widget, event):
        if qltk.is_accel(event, "Delete"):
            model, iter = self.__view.get_selection().get_selected()
            if not iter:
                return False

            playlist = model[iter][0]
            dialog = ConfirmRemovePlaylistDialog(self, playlist)
            if dialog.run() == Gtk.ResponseType.YES:
                playlist.delete()
                model.get_model().remove(
                    model.convert_iter_to_child_iter(iter))
            return True
        elif qltk.is_accel(event, "F2"):
            model, iter = self.__view.get_selection().get_selected()
            if iter:
                self.__render.set_property('editable', True)
                self.__view.set_cursor(model.get_path(iter),
                                       self.__view.get_columns()[0],
                                       start_editing=True)
            return True
        return False
Exemplo n.º 26
0
    def __key_pressed(self, view, event):
        def get_first_selected():
            selection = self.get_selection()
            model, paths = selection.get_selected_rows()
            return paths and paths[0] or None

        if is_accel(event, "Right") or is_accel(event, "<ctrl>Right"):
            first = get_first_selected()
            if first:
                self.expand_row(first, False)
        elif is_accel(event, "Left") or is_accel(event, "<ctrl>Left"):
            first = get_first_selected()
            if first:
                if self.row_expanded(first):
                    self.collapse_row(first)
                else:
                    # if we can't collapse, move the selection to the parent,
                    # so that a second attempt collapses the parent
                    model = self.get_model()
                    parent = model.iter_parent(model.get_iter(first))
                    if parent:
                        self.set_cursor(model.get_path(parent))
Exemplo n.º 27
0
    def __key_pressed(self, view, event):
        def get_first_selected():
            selection = self.get_selection()
            model, paths = selection.get_selected_rows()
            return paths and paths[0] or None

        if is_accel(event, "Right") or is_accel(event, "<Primary>Right"):
            first = get_first_selected()
            if first:
                self.expand_row(first, False)
        elif is_accel(event, "Left") or is_accel(event, "<Primary>Left"):
            first = get_first_selected()
            if first:
                if self.row_expanded(first):
                    self.collapse_row(first)
                else:
                    # if we can't collapse, move the selection to the parent,
                    # so that a second attempt collapses the parent
                    model = self.get_model()
                    parent = model.iter_parent(model.get_iter(first))
                    if parent:
                        self.set_cursor(model.get_path(parent))
Exemplo n.º 28
0
    def __key_pressed(self, widget, event):
        if qltk.is_accel(event, "Delete"):
            model, iter = self.__view.get_selection().get_selected()
            if not iter:
                return False

            playlist = model[iter][0]
            dialog = ConfirmRemovePlaylistDialog(self, playlist)
            if dialog.run() == Gtk.ResponseType.YES:
                playlist.delete()
                model.get_model().remove(
                    model.convert_iter_to_child_iter(iter))
            return True
        elif qltk.is_accel(event, "F2"):
            model, iter = self.__view.get_selection().get_selected()
            if iter:
                self.__render.set_property('editable', True)
                self.__view.set_cursor(model.get_path(iter),
                                       self.__view.get_columns()[0],
                                       start_editing=True)
            return True
        return False
Exemplo n.º 29
0
    def __key_pressed(self, widget, event):
        if qltk.is_accel(event, "Delete"):
            model, iter = self.__view.get_selection().get_selected()
            if not iter:
                return False

            playlist = model[iter][0]
            dialog = ConfirmRemovePlaylistDialog(self, playlist)
            if dialog.run() == gtk.RESPONSE_YES:
                playlist.delete()
                model.get_model().remove(
                    model.convert_iter_to_child_iter(None, iter))

        return False
Exemplo n.º 30
0
    def __key_pressed(self, widget, event):
        if qltk.is_accel(event, "Delete"):
            model, iter = self.__selected_playlists()
            if not iter:
                return False

            playlist = model[iter][0]
            response = confirm_remove_playlist_dialog_invoke(
                self, playlist, self.Confirmer)
            if response:
                playlist.delete()
                model.get_model().remove(
                    model.convert_iter_to_child_iter(iter))
            else:
                print_d("Playlist removal cancelled through prompt")
            return True
        elif qltk.is_accel(event, "F2"):
            model, iter = self.__selected_playlists()
            if iter:
                self._start_rename(model.get_path(iter))
            return True
        elif qltk.is_accel(event, "<Primary>I"):
            songs = self._get_playlist_songs()
            if songs:
                window = Information(self.library.librarian, songs, self)
                window.show()
            return True
        elif qltk.is_accel(event, "<Primary>Return", "<Primary>KP_Enter"):
            qltk.enqueue(self._get_playlist_songs())
            return True
        elif qltk.is_accel(event, "<alt>Return"):
            songs = self._get_playlist_songs()
            if songs:
                window = SongProperties(self.library.librarian, songs, self)
                window.show()
            return True
        return False
Exemplo n.º 31
0
    def __key_pressed(self, _widget: Gtk.Widget, event: Gdk.Event):
        # alt+X switches to page X
        for i in range(self.get_n_pages()):
            if is_accel(event, "<alt>%d" % (i + 1)):
                self.set_current_page(i)
                return Gdk.EVENT_STOP

        state = event.state & self._KEY_MODS
        # Use hardware, as Gtk+ seems to special-case tab for itself
        if event.hardware_keycode == 23:
            total = self.get_n_pages()
            current = self.get_current_page()
            if state == (MT.SHIFT_MASK | MT.CONTROL_MASK | MT.MOD2_MASK):
                self.set_current_page((current + total - 1) % total)
                return Gdk.EVENT_STOP
            elif state == (MT.CONTROL_MASK | MT.MOD2_MASK):
                self.set_current_page((current + 1) % total)
                return Gdk.EVENT_STOP
            else:
                print_d(f"Unhandled tab key combo: {event.state}")
        return Gdk.EVENT_PROPAGATE
Exemplo n.º 32
0
 def __view_key_press(self, view, event):
     if qltk.is_accel(event, "Delete"):
         self.__remove(view)
Exemplo n.º 33
0
 def key_pressed(self, event):
     if qltk.is_accel(event, "Delete"):
         self.__handle_songlist_delete()
         return True
     return False
Exemplo n.º 34
0
 def __key_pressed(self, entry, event):
     if (is_accel(event, '<Primary>Return')
             or is_accel(event, '<Primary>KP_Enter')):
         # Save query on Primary+Return accel, even though the focus is kept
         self.__save_search(entry)
     return False
Exemplo n.º 35
0
 def do_key_press_event(self, event):
     if is_accel(event, "space", "KP_Space"):
         return False
     return Gtk.TreeView.do_key_press_event(self, event)
Exemplo n.º 36
0
 def __delete_key_pressed(self, widget, event):
     if qltk.is_accel(event, "Delete"):
         self.__remove()
         return True
     return False
Exemplo n.º 37
0
 def __view_key_press(self, view, event):
     if qltk.is_accel(event, "Delete"):
         self.__remove(view)
Exemplo n.º 38
0
 def test_is_accel_primary(self):
     e = Gdk.Event.new(Gdk.EventType.KEY_PRESS)
     e.keyval = Gdk.KEY_Return
     e.state = Gdk.ModifierType.CONTROL_MASK
     if not util.is_osx():
         self.assertTrue(qltk.is_accel(e, "<Primary>Return"))
Exemplo n.º 39
0
 def __key_pressed(self, view, event):
     # if ctrl+a is pressed, intercept and select the All entry instead
     if is_accel(event, "<Primary>a"):
         self.set_selected([])
         return True
     return False
Exemplo n.º 40
0
 def __delete_key_pressed(self, widget, event):
     if qltk.is_accel(event, "Delete"):
         self.__remove()
         return True
     return False
Exemplo n.º 41
0
 def key_pressed(self, event):
     if qltk.is_accel(event, "Delete"):
         self.__handle_songlist_delete()
         return True
     return False
Exemplo n.º 42
0
 def test_is_accel_primary(self):
     e = Gdk.Event.new(Gdk.EventType.KEY_PRESS)
     e.keyval = Gdk.KEY_Return
     e.state = Gdk.ModifierType.CONTROL_MASK
     if not util.is_osx():
         self.assertTrue(qltk.is_accel(e, "<Primary>Return"))
Exemplo n.º 43
0
 def test_is_accel_invalid(self):
     e = Gdk.Event.new(Gdk.EventType.KEY_PRESS)
     with self.assertRaises(ValueError):
         qltk.is_accel(e, "NOPE")
Exemplo n.º 44
0
 def __key_pressed(self, view, event):
     # if ctrl+a is pressed, intercept and select the All entry instead
     if is_accel(event, "<ctrl>a"):
         self.set_selected([])
         return True
     return False
Exemplo n.º 45
0
 def _on_key_press_event(self, widget, event, player: BasePlayer):
     if qltk.is_accel(event, "space"):
         player.playpause()
Exemplo n.º 46
0
 def test_is_accel_invalid(self):
     e = Gdk.Event.new(Gdk.EventType.KEY_PRESS)
     with self.assertRaises(ValueError):
         qltk.is_accel(e, "NOPE")
Exemplo n.º 47
0
 def __key_pressed(self, entry, event):
     if (is_accel(event, '<Primary>Return') or
             is_accel(event, '<Primary>KP_Enter')):
         # Save query on Primary+Return accel, even though the focus is kept
         self.__save_search(entry)
     return False