Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #755 from luzip665/Quickbuttons_Plugin
Quick Buttons
- Loading branch information
Showing
4 changed files
with
388 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Version='0.4' | ||
Authors=[''] | ||
Name=_("Quick Settings Buttons") | ||
Description=_("Provides buttons on bottom of the playlist to quickly change some settings") | ||
Category=_('Utility') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,246 @@ | ||
from gi.repository import Gtk, GObject | ||
from xl import event, settings, providers | ||
from xl.nls import gettext as _ | ||
|
||
from . import qb_prefs | ||
|
||
|
||
class QuickButtons: | ||
""" | ||
Plugin adds some buttons on the bottom line of the playlists grid to | ||
change some settings quickly | ||
""" | ||
|
||
_self_triggered = False | ||
""" | ||
Don't repeat yourself. | ||
Is set to True to prevent resetting from settings.set_option | ||
""" | ||
|
||
_toolbar = None | ||
_equalizer_win = None | ||
|
||
_options = { | ||
"playlist/enqueue_by_default": { | ||
"show_button": "quickbuttons/btn_enqueue_by_default", | ||
"value": None, | ||
"default": False, | ||
"widget": None, | ||
"type": "toggle", | ||
"label": _("Enqueue"), | ||
"tooltip": _("Queue tracks by default instead of playing them"), | ||
}, | ||
"queue/disable_new_track_when_playing": { | ||
"show_button": "quickbuttons/btn_disable_new_track_when_playing", | ||
"value": None, | ||
"default": False, | ||
"widget": None, | ||
"type": "toggle", | ||
"label": "Keep playing", | ||
"tooltip": _("Disallow playing new tracks when another track is playing"), | ||
}, | ||
"queue/remove_item_when_played": { | ||
"show_button": "quickbuttons/btn_remove_item_when_played", | ||
"value": None, | ||
"default": True, | ||
"widget": None, | ||
"type": "toggle", | ||
"label": _("Auto-Remove"), | ||
"tooltip": _("Remove track from queue upon playback"), | ||
}, | ||
"player/auto_advance": { | ||
"show_button": "quickbuttons/btn_auto_advance", | ||
"value": None, | ||
"default": True, | ||
"widget": None, | ||
"type": "toggle", | ||
"label": _("Auto-Advance"), | ||
"tooltip": _("Automatically advance to the next track"), | ||
}, | ||
"player/auto_advance_delay": { | ||
"show_button": "quickbuttons/btn_auto_advance_delay", | ||
"value": None, | ||
"default": 0, | ||
"widget": None, | ||
"type": "spin", | ||
"label": _("Delay"), | ||
"tooltip": _("Delay between tracks (in seconds):"), | ||
}, | ||
"equalizer": { | ||
"show_button": "quickbuttons/btn_equalizer", | ||
"value": None, | ||
"default": None, | ||
"widget": None, | ||
"type": "equalizer", | ||
"label": _("EQ"), | ||
"tooltip": _("Equalizer"), | ||
}, | ||
} | ||
""" | ||
Usable options | ||
""" | ||
|
||
def enable(self, exaile): | ||
""" | ||
Called on startup of exaile | ||
""" | ||
self._exaile = exaile | ||
|
||
event.add_callback(self._on_option_set, "playlist_option_set") | ||
event.add_callback(self._on_option_set, "queue_option_set") | ||
event.add_callback(self._on_option_set, "player_option_set") | ||
event.add_callback(self._on_button_activate, "quickbuttons_option_set") | ||
|
||
def disable(self, exaile): | ||
self._toolbar.hide() | ||
event.remove_callback(self._on_option_set, "playlist_option_set") | ||
event.remove_callback(self._on_option_set, "queue_option_set") | ||
event.remove_callback(self._on_option_set, "player_option_set") | ||
|
||
def _on_button_activate(self, event_name, event_source, option: str) -> None: | ||
for k in self._options: | ||
show_btn_option = self._options[k]["show_button"] | ||
if option == show_btn_option: | ||
if not self._options[k]["widget"]: | ||
return | ||
if settings.get_option(show_btn_option, True): | ||
self._options[k]["widget"].show_all() | ||
else: | ||
self._options[k]["widget"].hide() | ||
break | ||
|
||
def _on_option_set(self, event_name, event_source, option: str) -> None: | ||
if option not in self._options: | ||
return | ||
|
||
if self._self_triggered: | ||
self._self_triggered = False | ||
return | ||
|
||
self._options[option]["value"] = settings.get_option(option) | ||
if self._options[option]["type"] == "toggle": | ||
self._options[option]["widget"].set_active(self._options[option]["value"]) | ||
elif self._options[option]["type"] == "spin": | ||
self._options[option]["widget"].get_children()[0].set_value( | ||
self._options[option]["value"] | ||
) | ||
|
||
def _on_toggle(self, widget, setting: str): | ||
""" | ||
Called when toggling a button | ||
""" | ||
self._self_triggered = True | ||
settings.set_option(setting, widget.get_active()) | ||
|
||
def _on_spin(self, widget, setting: str): | ||
""" | ||
Called when changing the value from spinbutton | ||
""" | ||
self._self_triggered = True | ||
self._set_delay_value(widget.get_value_as_int()) | ||
|
||
def _get_delay_value(self) -> int: | ||
""" | ||
Get the current delay value in seconds as int | ||
""" | ||
value = settings.get_option("player/auto_advance_delay") | ||
if value == None: | ||
value = 0 | ||
value = value / 1000 | ||
return int(value) | ||
|
||
def _set_delay_value(self, value: int) -> None: | ||
""" | ||
Set the delay value in ms | ||
""" | ||
value = value * 1000 | ||
settings.set_option("player/auto_advance_delay", value) | ||
|
||
def _add_button(self, setting: str) -> None: | ||
|
||
if self._options[setting]["type"] == "toggle": | ||
active = self._options[setting]["value"] | ||
if active != True: | ||
active = False | ||
tbs = Gtk.ToggleButton() | ||
tbs.set_label(self._options[setting]["label"]) | ||
tbs.set_active(active) | ||
tbs.connect("toggled", self._on_toggle, setting) | ||
|
||
elif self._options[setting]["type"] == "spin": | ||
tbs = Gtk.SpinButton() | ||
tbs.set_adjustment(Gtk.Adjustment(self._get_delay_value(), 0, 60, 1, 0, 0)) | ||
tbs.connect("value-changed", self._on_spin, setting) | ||
|
||
elif self._options[setting]["type"] == "equalizer": | ||
if "equalizer" not in self._exaile.plugins.enabled_plugins: | ||
return None | ||
tbs = Gtk.Button() | ||
tbs.set_label(_("EQ")) | ||
tbs.connect("clicked", self.__on_equalizer_press) | ||
|
||
return self._add_button_to_toolbar(tbs, setting) | ||
|
||
def _add_button_to_toolbar(self, tbs, setting) -> None: | ||
tbs.set_tooltip_text(self._options[setting]["tooltip"]) | ||
tb = Gtk.ToolItem() | ||
tb.add(tbs) | ||
|
||
show_btn_option = self._options[setting]["show_button"] | ||
show_btn = settings.get_option(show_btn_option, True) | ||
if show_btn: | ||
tb.show_all() | ||
|
||
self._options[setting]["widget"] = tb | ||
self._toolbar.insert(tb, -1) | ||
|
||
def __on_equalizer_press(self, widget) -> None: | ||
|
||
if "equalizer" not in self._exaile.plugins.enabled_plugins: | ||
return None | ||
|
||
eq_plugin_win = self._exaile.plugins.enabled_plugins["equalizer"].window | ||
if not eq_plugin_win: | ||
eq_win = GObject.new("EqualizerWindow") | ||
eq_win.set_transient_for(self._exaile.gui.main.window) | ||
self._exaile.plugins.enabled_plugins["equalizer"].window = eq_win | ||
self._equalizer_win = eq_win | ||
|
||
def _destroy(w): | ||
self._equalizer_win = None | ||
self._exaile.plugins.enabled_plugins["equalizer"].window = None | ||
|
||
eq_win.connect("destroy", _destroy) | ||
eq_win.show_all() | ||
|
||
def on_gui_loaded(self): | ||
""" | ||
Called when the gui is loaded | ||
Before that there is no status bar | ||
""" | ||
|
||
if self._toolbar != None: | ||
self._toolbar.show_all() | ||
return | ||
|
||
self._status_bar = self._exaile.gui.builder.get_object("status_bar") | ||
self._toolbar = Gtk.Toolbar() | ||
|
||
for k in self._options: | ||
self._options[k]["value"] = settings.get_option( | ||
k, self._options[k]["default"] | ||
) | ||
self._add_button(k) | ||
|
||
self._toolbar.show() | ||
self._status_bar.pack_start(self._toolbar, False, True, 0) | ||
self._status_bar.reorder_child(self._toolbar, 0) | ||
|
||
def on_exaile_loaded(self): | ||
pass | ||
|
||
def get_preferences_pane(self): | ||
return qb_prefs | ||
|
||
|
||
plugin_class = QuickButtons |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
from xlgui.preferences import widgets | ||
from xl.nls import gettext as _ | ||
|
||
name = _("Quickbuttons") | ||
basedir = os.path.dirname(os.path.realpath(__file__)) | ||
ui = os.path.join(basedir, "qb_prefs.ui") | ||
|
||
|
||
class EnqueueByDefault(widgets.CheckPreference): | ||
default = True | ||
name = "quickbuttons/btn_enqueue_by_default" | ||
|
||
|
||
class DisableNewTrack(widgets.CheckPreference): | ||
default = True | ||
name = "quickbuttons/btn_disable_new_track_when_playing" | ||
|
||
|
||
class RemoveItem(widgets.CheckPreference): | ||
default = True | ||
name = "quickbuttons/btn_remove_item_when_played" | ||
|
||
|
||
class AutoAdvance(widgets.CheckPreference): | ||
default = True | ||
name = "quickbuttons/btn_auto_advance" | ||
|
||
|
||
class AutoAdvanceDelay(widgets.CheckPreference): | ||
default = True | ||
name = "quickbuttons/btn_auto_advance_delay" | ||
|
||
|
||
class Equalizer(widgets.CheckPreference): | ||
default = True | ||
name = "quickbuttons/btn_equalizer" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- Generated with glade 3.18.3 --> | ||
<interface> | ||
<requires lib="gtk+" version="3.10"/> | ||
<object class="GtkGrid" id="preferences_pane"> | ||
<property name="visible">True</property> | ||
<property name="can_focus">False</property> | ||
<property name="row_spacing">4</property> | ||
<property name="column_spacing">2</property> | ||
<child> | ||
<object class="GtkCheckButton" id="quickbuttons/btn_enqueue_by_default"> | ||
<property name="label" translatable="yes">Enqueue by default</property> | ||
<property name="visible">True</property> | ||
<property name="can_focus">True</property> | ||
<property name="receives_default">False</property> | ||
<property name="tooltip_text" translatable="yes">Level 1 - Genre, Level 2 - Artist, Ordered by track date</property> | ||
<property name="draw_indicator">True</property> | ||
</object> | ||
<packing> | ||
<property name="left_attach">0</property> | ||
<property name="top_attach">0</property> | ||
<property name="width">3</property> | ||
</packing> | ||
</child> | ||
<child> | ||
<object class="GtkCheckButton" id="quickbuttons/btn_disable_new_track_when_playing"> | ||
<property name="label" translatable="yes">Disable new track when playing</property> | ||
<property name="visible">True</property> | ||
<property name="can_focus">True</property> | ||
<property name="receives_default">False</property> | ||
<property name="tooltip_text" translatable="yes">Level 1 - Genre, Level 2 - Artist, Ordered by track date</property> | ||
<property name="draw_indicator">True</property> | ||
</object> | ||
<packing> | ||
<property name="left_attach">0</property> | ||
<property name="top_attach">1</property> | ||
<property name="width">3</property> | ||
</packing> | ||
</child> | ||
<child> | ||
<object class="GtkCheckButton" id="quickbuttons/btn_remove_item_when_played"> | ||
<property name="label" translatable="yes">remove item when played</property> | ||
<property name="visible">True</property> | ||
<property name="can_focus">True</property> | ||
<property name="receives_default">False</property> | ||
<property name="tooltip_text" translatable="yes">Level 1 - Genre, Level 2 - Artist, Ordered by track date</property> | ||
<property name="draw_indicator">True</property> | ||
</object> | ||
<packing> | ||
<property name="left_attach">0</property> | ||
<property name="top_attach">2</property> | ||
<property name="width">3</property> | ||
</packing> | ||
</child> | ||
<child> | ||
<object class="GtkCheckButton" id="quickbuttons/btn_auto_advance"> | ||
<property name="label" translatable="yes">Auto advance</property> | ||
<property name="visible">True</property> | ||
<property name="can_focus">True</property> | ||
<property name="receives_default">False</property> | ||
<property name="tooltip_text" translatable="yes">Level 1 - Genre, Level 2 - Artist, Ordered by track date</property> | ||
<property name="draw_indicator">True</property> | ||
</object> | ||
<packing> | ||
<property name="left_attach">0</property> | ||
<property name="top_attach">3</property> | ||
<property name="width">3</property> | ||
</packing> | ||
</child> | ||
<child> | ||
<object class="GtkCheckButton" id="quickbuttons/btn_auto_advance_delay"> | ||
<property name="label" translatable="yes">Auto advance delay (in seconds)</property> | ||
<property name="visible">True</property> | ||
<property name="can_focus">True</property> | ||
<property name="receives_default">False</property> | ||
<property name="tooltip_text" translatable="yes">Level 1 - Genre, Level 2 - Artist, Ordered by track date</property> | ||
<property name="draw_indicator">True</property> | ||
</object> | ||
<packing> | ||
<property name="left_attach">0</property> | ||
<property name="top_attach">4</property> | ||
<property name="width">3</property> | ||
</packing> | ||
</child> | ||
<child> | ||
<object class="GtkCheckButton" id="quickbuttons/btn_equalizer"> | ||
<property name="label" translatable="yes">Equalizer (depends on Equalizer Plugin)</property> | ||
<property name="visible">True</property> | ||
<property name="can_focus">True</property> | ||
<property name="receives_default">False</property> | ||
<property name="draw_indicator">True</property> | ||
</object> | ||
<packing> | ||
<property name="left_attach">0</property> | ||
<property name="top_attach">5</property> | ||
<property name="width">3</property> | ||
</packing> | ||
</child> | ||
</object> | ||
</interface> |