Working on player settings

This commit is contained in:
Sumner Evans
2020-06-19 10:18:16 -06:00
parent f99284b6c6
commit 06f0968afb
3 changed files with 109 additions and 64 deletions

View File

@@ -202,15 +202,108 @@ class MainWindow(Gtk.ApplicationWindow):
# Main Settings
self.notification_switch.set_active(app_config.song_play_notification)
print(player_manager.get_configuration_options())
# TODO
# # MPV Settings
# self.replay_gain_options.set_active_id(app_config.replay_gain.as_string())
# Player settings
for c in self.player_settings_box.get_children():
self.player_settings_box.remove(c)
# # Chromecast Settings
# self.serve_over_lan_switch.set_active(app_config.serve_over_lan)
# self.port_number_entry.set_value(app_config.port_number)
# self.port_number_entry.set_sensitive(app_config.serve_over_lan)
def emit_player_settings_change(
player_name: str, option_name: str, value_extraction_fn: Callable, *args
):
if self._updating_settings:
return
self.emit(
"refresh-window",
{
"__player_setting__": (
player_name,
option_name,
value_extraction_fn(*args),
)
},
False,
)
for player_name, options in player_manager.get_configuration_options().items():
self.player_settings_box.add(Gtk.Separator())
self.player_settings_box.add(
self._create_label(
f"{player_name} Settings", name="menu-settings-separator"
)
)
for option_name, descriptor in options.items():
setting_box = Gtk.Box()
setting_box.add(option_name_label := Gtk.Label(label=option_name))
option_name_label.get_style_context().add_class("menu-label")
option_value = app_config.player_config.get(player_name, {}).get(
option_name
)
if type(descriptor) == tuple:
option_store = Gtk.ListStore(str)
for option in descriptor:
option_store.append([option])
combo = Gtk.ComboBox.new_with_model(option_store)
combo.set_id_column(0)
renderer_text = Gtk.CellRendererText()
combo.pack_start(renderer_text, True)
combo.add_attribute(renderer_text, "text", 0)
combo.set_active_id(option_value)
combo.connect(
"changed",
partial(
emit_player_settings_change,
player_name,
option_name,
lambda c: c.get_active_id(),
),
)
setting_box.pack_end(combo, False, False, 0)
elif descriptor == bool:
switch = Gtk.Switch(active=option_value)
switch.connect(
"notify::active",
partial(
emit_player_settings_change,
player_name,
option_name,
lambda s, _: s.get_active(),
),
)
setting_box.pack_end(switch, False, False, 0)
elif descriptor == int:
def restrict_to_ints(
entry: Gtk.Entry, text: str, length: int, position: int
) -> bool:
if self._updating_settings:
return False
if not text.isdigit():
entry.emit_stop_by_name("insert-text")
return True
return False
entry = Gtk.Entry(width_chars=8, text=option_value)
entry.connect(
"changed",
partial(
emit_player_settings_change,
player_name,
option_name,
lambda e: int(e.get_text()),
),
)
entry.connect("insert-text", restrict_to_ints)
setting_box.pack_end(entry, False, False, 0)
setting_box.get_style_context().add_class("menu-button")
self.player_settings_box.add(setting_box)
self.player_settings_box.show_all()
# Download Settings
allow_song_downloads = app_config.allow_song_downloads
@@ -682,49 +775,8 @@ class MainWindow(Gtk.ApplicationWindow):
# PLAYER SETTINGS
# ==============================================================================
vbox.add(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL))
vbox.add(
self._create_label(
"Local Playback Settings", name="menu-settings-separator"
)
)
# Replay Gain
replay_gain_box = Gtk.Box()
replay_gain_box.add(replay_gain_label := Gtk.Label(label="Replay Gain"))
replay_gain_label.get_style_context().add_class("menu-label")
replay_gain_option_store = Gtk.ListStore(str, str)
for id, option in (("no", "Disabled"), ("track", "Track"), ("album", "Album")):
replay_gain_option_store.append([id, option])
self.replay_gain_options = Gtk.ComboBox.new_with_model(replay_gain_option_store)
self.replay_gain_options.set_id_column(0)
renderer_text = Gtk.CellRendererText()
self.replay_gain_options.pack_start(renderer_text, True)
self.replay_gain_options.add_attribute(renderer_text, "text", 1)
self.replay_gain_options.connect("changed", self._on_replay_gain_change)
replay_gain_box.pack_end(self.replay_gain_options, False, False, 0)
replay_gain_box.get_style_context().add_class("menu-button")
vbox.add(replay_gain_box)
vbox.add(Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL))
vbox.add(
self._create_label("Chromecast Settings", name="menu-settings-separator")
)
# Serve Local Files to Chromecast
serve_over_lan, self.serve_over_lan_switch = self._create_toggle_menu_button(
"Serve Local Files to Chromecasts on the LAN", "serve_over_lan"
)
vbox.add(serve_over_lan)
# Server Port
server_port_box, self.port_number_entry = self._create_spin_button_menu_item(
"LAN Server Port Number", 8000, 9000, 1, "port_number"
)
vbox.add(server_port_box)
self.player_settings_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
vbox.add(self.player_settings_box)
# DOWNLOAD SETTINGS
# ==============================================================================
@@ -885,9 +937,6 @@ class MainWindow(Gtk.ApplicationWindow):
self.main_menu_popover.popup()
self.main_menu_popover.show_all()
def _on_replay_gain_change(self, combo: Gtk.ComboBox):
self._emit_settings_change({"replay_gain": combo.get_active_id()})
def _on_search_entry_focus(self, *args):
self._show_search()