merged CoverLyricsOSD and CoverPlaylistWindow

This commit is contained in:
Martin Wagner 2020-09-26 12:50:05 +02:00
parent 375fe48fa0
commit 9d1a940cb9

View File

@ -2847,7 +2847,7 @@ class PlaylistWindow(Gtk.Box):
for icon in self._icons.values():
icon.set_pixel_size(pixel_size)
class CoverLyricsOSD(Gtk.Overlay):
class CoverPlaylistWindow(Gtk.Paned):
def __init__(self, client, settings, window):
super().__init__()
@ -2860,14 +2860,17 @@ class CoverLyricsOSD(Gtk.Overlay):
main_cover=MainCover(self._client, self._settings)
self._cover_event_box=CoverEventBox(self._client, self._settings, self._window)
# playlist
self._playlist_window=PlaylistWindow(self._client, self._settings)
# lyrics button
self._lyrics_button=Gtk.ToggleButton(
self.lyrics_button=Gtk.ToggleButton(
image=Gtk.Image.new_from_icon_name("media-view-subtitles-symbolic", Gtk.IconSize.BUTTON),
tooltip_text=_("Show lyrics")
)
self._lyrics_button.set_margin_top(6)
self._lyrics_button.set_margin_end(6)
style_context=self._lyrics_button.get_style_context()
self.lyrics_button.set_margin_top(6)
self.lyrics_button.set_margin_end(6)
style_context=self.lyrics_button.get_style_context()
style_context.add_class("circular")
# lyrics window
@ -2877,7 +2880,7 @@ class CoverLyricsOSD(Gtk.Overlay):
self._lyrics_button_revealer=Gtk.Revealer()
self._lyrics_button_revealer.set_halign(Gtk.Align.END)
self._lyrics_button_revealer.set_valign(Gtk.Align.START)
self._lyrics_button_revealer.add(self._lyrics_button)
self._lyrics_button_revealer.add(self.lyrics_button)
# stack
self._stack=Gtk.Stack(transition_type=Gtk.StackTransitionType.CROSSFADE)
@ -2885,28 +2888,33 @@ class CoverLyricsOSD(Gtk.Overlay):
self._stack.add_named(self._lyrics_window, "lyrics")
self._stack.set_visible_child(self._cover_event_box)
# packing
self.add(main_cover)
self.add_overlay(self._stack)
self.add_overlay(self._lyrics_button_revealer)
# connect
self._lyrics_button.connect("toggled", self._on_lyrics_toggled)
self.lyrics_button.connect("toggled", self._on_lyrics_toggled)
self._client.emitter.connect("disconnected", self._on_disconnected)
self._client.emitter.connect("reconnected", self._on_reconnected)
self._settings.connect("changed::show-lyrics-button", self._on_settings_changed)
# packing
overlay=Gtk.Overlay()
overlay.add(main_cover)
overlay.add_overlay(self._stack)
overlay.add_overlay(self._lyrics_button_revealer)
self.pack1(overlay, False, False)
self.pack2(self._playlist_window, True, False)
self.set_position(self._settings.get_int("paned0"))
self._on_settings_changed() # hide lyrics button
def toggle_lyrics(self, *args):
self._lyrics_button.set_active(not(self._lyrics_button.get_active()))
def save_settings(self):
self._settings.set_int("paned0", self.get_position())
self._playlist_window.save_settings()
def _on_reconnected(self, *args):
self._lyrics_button.set_sensitive(True)
self.lyrics_button.set_sensitive(True)
def _on_disconnected(self, *args):
self._lyrics_button.set_active(False)
self._lyrics_button.set_sensitive(False)
self.lyrics_button.set_active(False)
self.lyrics_button.set_sensitive(False)
def _on_lyrics_toggled(self, widget):
if widget.get_active():
@ -2922,31 +2930,6 @@ class CoverLyricsOSD(Gtk.Overlay):
else:
self._lyrics_button_revealer.set_reveal_child(False)
class CoverPlaylistWindow(Gtk.Paned):
def __init__(self, client, settings, window):
super().__init__() # paned0
# adding vars
self._client=client
self._settings=settings
# widgets
self._cover_lyrics_osd=CoverLyricsOSD(self._client, self._settings, window)
self._playlist_window=PlaylistWindow(self._client, self._settings)
# packing
self.pack1(self._cover_lyrics_osd, False, False)
self.pack2(self._playlist_window, True, False)
self.set_position(self._settings.get_int("paned0"))
def toggle_lyrics(self, *args):
self._cover_lyrics_osd.toggle_lyrics()
def save_settings(self):
self._settings.set_int("paned0", self.get_position())
self._playlist_window.save_settings()
###################
# control widgets #
###################
@ -3587,7 +3570,8 @@ class MainWindow(Gtk.ApplicationWindow):
self.lookup_action("toggle-play").set_enabled(True)
def _on_toggle_lyrics(self, action, param):
self._cover_playlist_window.toggle_lyrics()
self._cover_playlist_window.lyrics_button.grab_focus()
self._cover_playlist_window.lyrics_button.set_active(not(self._cover_playlist_window.lyrics_button.get_active()))
def _on_toggle_play(self, action, param):
self._playback_control.play_button.grab_focus()