Working on pause play
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import os
|
||||
|
||||
import mpv
|
||||
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gio, Gtk, GLib, Gdk
|
||||
@@ -28,6 +30,9 @@ class LibremsonicApp(Gtk.Application):
|
||||
'Specify a configuration file. Defaults to ~/.config/libremsonic/config.json',
|
||||
None)
|
||||
|
||||
self.player = mpv.MPV()
|
||||
self.is_playing = False
|
||||
|
||||
# Handle command line option parsing.
|
||||
def do_command_line(self, command_line):
|
||||
options = command_line.get_options_dict()
|
||||
@@ -40,8 +45,7 @@ class LibremsonicApp(Gtk.Application):
|
||||
else:
|
||||
# Default to ~/.config/libremsonic.
|
||||
config_folder = (os.environ.get('XDG_CONFIG_HOME')
|
||||
or os.environ.get('APPDATA') or os.path.join(
|
||||
os.environ.get('HOME'), '.config'))
|
||||
or os.path.expanduser('~/.config'))
|
||||
config_folder = os.path.join(config_folder, 'libremsonic')
|
||||
self.config_file = os.path.join(config_folder, 'config.yaml')
|
||||
|
||||
@@ -58,6 +62,11 @@ class LibremsonicApp(Gtk.Application):
|
||||
action.connect('activate', self.on_configure_servers)
|
||||
self.add_action(action)
|
||||
|
||||
# Add action for configuring servers
|
||||
action = Gio.SimpleAction.new('play_pause', None)
|
||||
action.connect('activate', self.on_play_pause)
|
||||
self.add_action(action)
|
||||
|
||||
def do_activate(self):
|
||||
# We only allow a single window and raise any existing ones
|
||||
if not self.window:
|
||||
@@ -79,27 +88,40 @@ class LibremsonicApp(Gtk.Application):
|
||||
# Load the configuration and update the UI with the curent server, if
|
||||
# it exists. If there is no current server, show the dialog to select a
|
||||
# server.
|
||||
self.load_settings()
|
||||
self.load_config()
|
||||
|
||||
if self.config.current_server is None:
|
||||
self.show_configure_servers_dialog()
|
||||
else:
|
||||
self.on_connected_server_changed(None, self.config.current_server)
|
||||
|
||||
# ########## ACTION HANDLERS ########## #
|
||||
def on_configure_servers(self, action, param):
|
||||
self.show_configure_servers_dialog()
|
||||
|
||||
def on_play_pause(self, action, param):
|
||||
if self.is_playing:
|
||||
self.player.command('cycle', 'pause')
|
||||
else:
|
||||
self.player.loadfile(
|
||||
'/home/sumner/Music/Sapphyre/All You See Is Christ (live).mp3')
|
||||
|
||||
self.is_playing = not self.is_playing
|
||||
|
||||
self.update_window()
|
||||
|
||||
def on_server_list_changed(self, action, servers):
|
||||
self.config.servers = servers
|
||||
self.save_settings()
|
||||
self.save_config()
|
||||
|
||||
def on_connected_server_changed(self, action, current_server):
|
||||
self.config.current_server = current_server
|
||||
self.save_settings()
|
||||
self.save_config()
|
||||
|
||||
# Update the window according to the new server configuration.
|
||||
self.window.update(self.config.servers[self.config.current_server])
|
||||
self.update_window()
|
||||
|
||||
# ########## HELPER METHODS ########## #
|
||||
def show_configure_servers_dialog(self):
|
||||
"""Show the Connect to Server dialog."""
|
||||
dialog = ConfigureServersDialog(self.window, self.config)
|
||||
@@ -109,8 +131,15 @@ class LibremsonicApp(Gtk.Application):
|
||||
dialog.run()
|
||||
dialog.destroy()
|
||||
|
||||
def load_settings(self):
|
||||
def load_config(self):
|
||||
self.config = get_config(self.config_file)
|
||||
|
||||
def save_settings(self):
|
||||
def save_config(self):
|
||||
save_config(self.config, self.config_file)
|
||||
|
||||
def update_window(self):
|
||||
self.window.update(
|
||||
server=self.config.servers[self.config.current_server],
|
||||
current_song=None,
|
||||
is_playing=self.is_playing,
|
||||
)
|
||||
|
@@ -37,7 +37,8 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
flowbox.pack_start(self.player_controls, False, True, 0)
|
||||
self.add(flowbox)
|
||||
|
||||
def update(self, server: Optional[Server]):
|
||||
# TODO the song should eventually be an API object...
|
||||
def update(self, server: Optional[Server], current_song, is_playing):
|
||||
# Update the Connected to label on the popup menu.
|
||||
if server:
|
||||
self.connected_to_label.set_markup(f'Connected to {server.name}')
|
||||
@@ -45,8 +46,7 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
self.connected_to_label.set_markup(
|
||||
f'<span style="italic">Not Connected to a Server</span>')
|
||||
|
||||
print(self.panels)
|
||||
print(self.player_controls)
|
||||
self.player_controls.update(current_song, is_playing)
|
||||
|
||||
def create_stack(self, **kwargs):
|
||||
stack = Gtk.Stack()
|
||||
|
@@ -21,6 +21,11 @@ class PlayerControls(Gtk.ActionBar):
|
||||
self.set_center_widget(self.playback_controls)
|
||||
self.pack_end(self.up_next_volume)
|
||||
|
||||
def update(self, current_song, playing):
|
||||
self.play_button.get_child().set_from_icon_name(
|
||||
f"media-playback-{'start' if not playing else 'pause'}-symbolic",
|
||||
Gtk.IconSize.LARGE_TOOLBAR)
|
||||
|
||||
def create_song_display(self):
|
||||
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
|
||||
|
||||
@@ -79,12 +84,13 @@ class PlayerControls(Gtk.ActionBar):
|
||||
buttons.pack_start(previous_button, False, False, 5)
|
||||
|
||||
# Play button
|
||||
play_button = self.button_with_icon(
|
||||
self.play_button = self.button_with_icon(
|
||||
'media-playback-start-symbolic',
|
||||
relief=True,
|
||||
icon_size=Gtk.IconSize.LARGE_TOOLBAR)
|
||||
play_button.set_name('play-button')
|
||||
buttons.pack_start(play_button, False, False, 0)
|
||||
self.play_button.set_name('play-button')
|
||||
self.play_button.set_action_name('app.play_pause')
|
||||
buttons.pack_start(self.play_button, False, False, 0)
|
||||
|
||||
# Next button
|
||||
next_button = self.button_with_icon(
|
||||
|
Reference in New Issue
Block a user