Compare commits

...

3 Commits

Author SHA1 Message Date
Martin Wagner
6198a821db fixed ctrl-c behavior 2022-04-16 22:02:18 +02:00
Martin Wagner
d07ca0697d set sensitivity of back_button 2022-04-16 21:21:50 +02:00
Martin Wagner
32893f7062 fixed MPRIS Previous method according to the specs
Using conditional previous in the MPRIS interface introduced some bugs.
It was not possible to go to the previous track via plasma's MPRIS client.
2022-04-16 20:47:59 +02:00

View File

@ -32,6 +32,7 @@ import datetime
import collections import collections
import os import os
import sys import sys
import signal
import re import re
import locale import locale
from gettext import gettext as _, ngettext, textdomain, bindtextdomain from gettext import gettext as _, ngettext, textdomain, bindtextdomain
@ -362,7 +363,7 @@ class MPRISInterface: # TODO emit Seeked if needed
self._client.next() self._client.next()
def Previous(self): def Previous(self):
self._client.conditional_previous() self._client.previous()
def Pause(self): def Pause(self):
self._client.pause(1) self._client.pause(1)
@ -2264,20 +2265,18 @@ class Browser(Gtk.Paned):
self.pack1(genre_window, False, False) self.pack1(genre_window, False, False)
self.pack2(self.paned1, True, False) self.pack2(self.paned1, True, False)
def back_to_current_album(self, force=False): def back_to_current_album(self):
if (song:=self._client.currentsong()): song=self._client.currentsong()
artist,genre=self._artist_list.get_artist_selected() artist,genre=self._artist_list.get_artist_selected()
# deactivate genre filter to show all artists (if needed) # deactivate genre filter to show all artists (if needed)
if song["genre"][0] != genre or force: if song["genre"][0] != genre:
self._genre_list.deactivate()
# select artist
if artist is None and not force: # all artists selected
self._artist_list.highlight_selected()
else: # one artist selected
self._artist_list.select(song["albumartist"][0])
self._album_list.scroll_to_current_album()
else:
self._genre_list.deactivate() self._genre_list.deactivate()
# select artist
if artist is None: # all artists selected
self._artist_list.highlight_selected()
else: # one artist selected
self._artist_list.select(song["albumartist"][0])
self._album_list.scroll_to_current_album()
def _on_genre_filter_changed(self, settings, key): def _on_genre_filter_changed(self, settings, key):
if self._client.connected(): if self._client.connected():
@ -3537,9 +3536,10 @@ class MainWindow(Gtk.ApplicationWindow):
self._search_button=Gtk.ToggleButton( self._search_button=Gtk.ToggleButton(
image=icon("system-search-symbolic"), tooltip_text=_("Search"), can_focus=False, no_show_all=True) image=icon("system-search-symbolic"), tooltip_text=_("Search"), can_focus=False, no_show_all=True)
self._settings.bind("mini-player", self._search_button, "visible", Gio.SettingsBindFlags.INVERT_BOOLEAN|Gio.SettingsBindFlags.GET) self._settings.bind("mini-player", self._search_button, "visible", Gio.SettingsBindFlags.INVERT_BOOLEAN|Gio.SettingsBindFlags.GET)
self._back_button=Gtk.Button( back_button=Gtk.Button(
image=icon("go-previous-symbolic"), tooltip_text=_("Back to current album"), can_focus=False, no_show_all=True) image=icon("go-previous-symbolic"), tooltip_text=_("Back to current album"),
self._settings.bind("mini-player", self._back_button, "visible", Gio.SettingsBindFlags.INVERT_BOOLEAN|Gio.SettingsBindFlags.GET) action_name="win.back-to-current-album", can_focus=False, no_show_all=True)
self._settings.bind("mini-player", back_button, "visible", Gio.SettingsBindFlags.INVERT_BOOLEAN|Gio.SettingsBindFlags.GET)
# stack # stack
self._stack=Gtk.Stack(transition_type=Gtk.StackTransitionType.CROSSFADE) self._stack=Gtk.Stack(transition_type=Gtk.StackTransitionType.CROSSFADE)
@ -3580,8 +3580,6 @@ class MainWindow(Gtk.ApplicationWindow):
# connect # connect
self._search_button.connect("toggled", self._on_search_button_toggled) self._search_button.connect("toggled", self._on_search_button_toggled)
self._back_button.connect("clicked", self._on_back_button_clicked)
self._back_button.connect("button-press-event", self._on_back_button_press_event)
self._settings.connect_after("changed::mini-player", self._mini_player) self._settings.connect_after("changed::mini-player", self._mini_player)
self._settings.connect_after("notify::cursor-watch", self._on_cursor_watch) self._settings.connect_after("notify::cursor-watch", self._on_cursor_watch)
self._settings.connect("changed::playlist-right", self._on_playlist_pos_changed) self._settings.connect("changed::playlist-right", self._on_playlist_pos_changed)
@ -3602,11 +3600,11 @@ class MainWindow(Gtk.ApplicationWindow):
if self._use_csd: if self._use_csd:
self._header_bar=Gtk.HeaderBar(show_close_button=True) self._header_bar=Gtk.HeaderBar(show_close_button=True)
self.set_titlebar(self._header_bar) self.set_titlebar(self._header_bar)
self._header_bar.pack_start(self._back_button) self._header_bar.pack_start(back_button)
self._header_bar.pack_end(self._menu_button) self._header_bar.pack_end(self._menu_button)
self._header_bar.pack_end(self._search_button) self._header_bar.pack_end(self._search_button)
else: else:
action_bar.pack_start(self._back_button) action_bar.pack_start(back_button)
action_bar.pack_end(self._menu_button) action_bar.pack_end(self._menu_button)
action_bar.pack_end(self._search_button) action_bar.pack_end(self._search_button)
action_bar.pack_start(playback_control) action_bar.pack_start(playback_control)
@ -3658,7 +3656,8 @@ class MainWindow(Gtk.ApplicationWindow):
self._cover_lyrics_window.lyrics_button.emit("clicked") self._cover_lyrics_window.lyrics_button.emit("clicked")
def _on_back_to_current_album(self, action, param): def _on_back_to_current_album(self, action, param):
self._back_button.emit("clicked") self._search_button.set_active(False)
self._browser.back_to_current_album()
def _on_toggle_search(self, action, param): def _on_toggle_search(self, action, param):
self._search_button.emit("clicked") self._search_button.emit("clicked")
@ -3708,16 +3707,9 @@ class MainWindow(Gtk.ApplicationWindow):
else: else:
self._stack.set_visible_child_name("browser") self._stack.set_visible_child_name("browser")
def _on_back_button_clicked(self, *args):
self._search_button.set_active(False)
self._browser.back_to_current_album()
def _on_back_button_press_event(self, widget, event):
if event.button == 1 and event.type == Gdk.EventType._2BUTTON_PRESS:
self._browser.back_to_current_album(force=True)
def _on_song_changed(self, *args): def _on_song_changed(self, *args):
if (song:=self._client.currentsong()): if (song:=self._client.currentsong()):
self.lookup_action("back-to-current-album").set_enabled(True)
album=song.get_album_with_date() album=song.get_album_with_date()
title="".join(filter(None, (song["title"][0], str(song["artist"])))) title="".join(filter(None, (song["title"][0], str(song["artist"]))))
if self._use_csd: if self._use_csd:
@ -3738,6 +3730,7 @@ class MainWindow(Gtk.ApplicationWindow):
else: else:
self.get_application().withdraw_notification("title-change") self.get_application().withdraw_notification("title-change")
else: else:
self.lookup_action("back-to-current-album").set_enabled(False)
self.set_title("mpdevil") self.set_title("mpdevil")
if self._use_csd: if self._use_csd:
self._header_bar.set_subtitle("") self._header_bar.set_subtitle("")
@ -3747,7 +3740,6 @@ class MainWindow(Gtk.ApplicationWindow):
for action in ("stats","toggle-lyrics","back-to-current-album","toggle-search"): for action in ("stats","toggle-lyrics","back-to-current-album","toggle-search"):
self.lookup_action(action).set_enabled(True) self.lookup_action(action).set_enabled(True)
self._search_button.set_sensitive(True) self._search_button.set_sensitive(True)
self._back_button.set_sensitive(True)
def _on_disconnected(self, *args): def _on_disconnected(self, *args):
self.set_title("mpdevil") self.set_title("mpdevil")
@ -3757,7 +3749,6 @@ class MainWindow(Gtk.ApplicationWindow):
self.lookup_action(action).set_enabled(False) self.lookup_action(action).set_enabled(False)
self._search_button.set_active(False) self._search_button.set_active(False)
self._search_button.set_sensitive(False) self._search_button.set_sensitive(False)
self._back_button.set_sensitive(False)
def _on_size_allocate(self, widget, rect): def _on_size_allocate(self, widget, rect):
if not self.is_maximized() and not self._settings.get_boolean("mini-player"): if not self.is_maximized() and not self._settings.get_boolean("mini-player"):
@ -3856,4 +3847,5 @@ class mpdevil(Gtk.Application):
if __name__ == "__main__": if __name__ == "__main__":
app=mpdevil() app=mpdevil()
signal.signal(signal.SIGINT, signal.SIG_DFL) # allow using ctrl-c to terminate
app.run(sys.argv) app.run(sys.argv)