mirror of
https://github.com/SoongNoonien/mpdevil.git
synced 2023-08-10 21:12:44 +03:00
merged OutputPopover into VolumeButton
This commit is contained in:
parent
1f2d9c8587
commit
0971bb7500
@ -3267,54 +3267,35 @@ class PlaybackOptions(Gtk.ButtonBox):
|
|||||||
def _on_reconnected(self, *args):
|
def _on_reconnected(self, *args):
|
||||||
self.set_sensitive(True)
|
self.set_sensitive(True)
|
||||||
|
|
||||||
class OutputPopover(Gtk.Popover):
|
|
||||||
def __init__(self, client, relative):
|
|
||||||
super().__init__()
|
|
||||||
self.set_relative_to(relative)
|
|
||||||
self._client=client
|
|
||||||
|
|
||||||
# widgets
|
|
||||||
box=Gtk.Box(orientation=Gtk.Orientation.VERTICAL, border_width=9)
|
|
||||||
for output in self._client.outputs():
|
|
||||||
button=Gtk.ModelButton(label=f"{output['outputname']} ({output['plugin']})", role=Gtk.ButtonRole.CHECK)
|
|
||||||
button.get_child().set_property("xalign", 0)
|
|
||||||
if output["outputenabled"] == "1":
|
|
||||||
button.set_property("active", True)
|
|
||||||
button.connect("clicked", self._on_button_clicked, output["outputid"])
|
|
||||||
box.pack_start(button, False, False, 0)
|
|
||||||
|
|
||||||
#connect
|
|
||||||
self.connect("closed", lambda *args: self.destroy())
|
|
||||||
|
|
||||||
# packing
|
|
||||||
self.add(box)
|
|
||||||
box.show_all()
|
|
||||||
|
|
||||||
def _on_button_clicked(self, button, out_id):
|
|
||||||
if button.get_property("active"):
|
|
||||||
self._client.disableoutput(out_id)
|
|
||||||
button.set_property("active", False)
|
|
||||||
else:
|
|
||||||
self._client.enableoutput(out_id)
|
|
||||||
button.set_property("active", True)
|
|
||||||
|
|
||||||
class VolumeButton(Gtk.VolumeButton):
|
class VolumeButton(Gtk.VolumeButton):
|
||||||
def __init__(self, client, settings):
|
def __init__(self, client, settings):
|
||||||
super().__init__(use_symbolic=True, can_focus=False)
|
super().__init__(orientation=Gtk.Orientation.HORIZONTAL, use_symbolic=True, can_focus=False)
|
||||||
self._client=client
|
self._client=client
|
||||||
self._popover=None
|
|
||||||
self._adj=self.get_adjustment()
|
self._adj=self.get_adjustment()
|
||||||
self._adj.set_step_increment(5)
|
self._adj.set_step_increment(5)
|
||||||
self._adj.set_page_increment(10)
|
self._adj.set_page_increment(10)
|
||||||
self._adj.set_upper(0) # do not allow volume change by user when MPD has not yet reported volume (no output enabled/avail)
|
self._adj.set_upper(0) # do not allow volume change by user when MPD has not yet reported volume (no output enabled/avail)
|
||||||
settings.bind("icon-size", self.get_child(), "pixel-size", Gio.SettingsBindFlags.GET)
|
settings.bind("icon-size", self.get_child(), "pixel-size", Gio.SettingsBindFlags.GET)
|
||||||
|
|
||||||
|
# output plugins
|
||||||
|
self._output_box=Gtk.Box(orientation=Gtk.Orientation.VERTICAL, margin_start=10, margin_end=10, margin_bottom=10)
|
||||||
|
|
||||||
|
# popover
|
||||||
|
popover=self.get_popup()
|
||||||
|
scale_box=popover.get_child()
|
||||||
|
popover.remove(scale_box)
|
||||||
|
box=Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||||
|
box.pack_start(scale_box, False, False, 0)
|
||||||
|
box.pack_start(self._output_box, False, False, 0)
|
||||||
|
popover.add(box)
|
||||||
|
box.show_all()
|
||||||
|
|
||||||
# connect
|
# connect
|
||||||
|
popover.connect("show", self._on_show)
|
||||||
self._changed=self.connect("value-changed", self._set_volume)
|
self._changed=self.connect("value-changed", self._set_volume)
|
||||||
self._client.emitter.connect("volume", self._refresh)
|
self._client.emitter.connect("volume", self._refresh)
|
||||||
self._client.emitter.connect("disconnected", self._on_disconnected)
|
self._client.emitter.connect("disconnected", self._on_disconnected)
|
||||||
self._client.emitter.connect("reconnected", self._on_reconnected)
|
self._client.emitter.connect("reconnected", self._on_reconnected)
|
||||||
self.connect("button-press-event", self._on_button_press_event)
|
|
||||||
|
|
||||||
def _set_volume(self, widget, value):
|
def _set_volume(self, widget, value):
|
||||||
self._client.setvol(str(int(value)))
|
self._client.setvol(str(int(value)))
|
||||||
@ -3329,10 +3310,24 @@ class VolumeButton(Gtk.VolumeButton):
|
|||||||
self.set_value(volume)
|
self.set_value(volume)
|
||||||
self.handler_unblock(self._changed)
|
self.handler_unblock(self._changed)
|
||||||
|
|
||||||
def _on_button_press_event(self, widget, event):
|
def _on_show(self, *args):
|
||||||
if event.button == 3 and event.type == Gdk.EventType.BUTTON_PRESS:
|
for button in self._output_box.get_children():
|
||||||
self._popover=OutputPopover(self._client, self)
|
self._output_box.remove(button)
|
||||||
self._popover.popup()
|
for output in self._client.outputs():
|
||||||
|
button=Gtk.ModelButton(label=f"{output['outputname']} ({output['plugin']})", role=Gtk.ButtonRole.CHECK, visible=True)
|
||||||
|
button.get_child().set_property("xalign", 0)
|
||||||
|
if output["outputenabled"] == "1":
|
||||||
|
button.set_property("active", True)
|
||||||
|
button.connect("clicked", self._on_button_clicked, output["outputid"])
|
||||||
|
self._output_box.pack_start(button, False, False, 0)
|
||||||
|
|
||||||
|
def _on_button_clicked(self, button, out_id):
|
||||||
|
if button.get_property("active"):
|
||||||
|
self._client.disableoutput(out_id)
|
||||||
|
button.set_property("active", False)
|
||||||
|
else:
|
||||||
|
self._client.enableoutput(out_id)
|
||||||
|
button.set_property("active", True)
|
||||||
|
|
||||||
def _on_reconnected(self, *args):
|
def _on_reconnected(self, *args):
|
||||||
self.set_sensitive(True)
|
self.set_sensitive(True)
|
||||||
@ -3340,9 +3335,6 @@ class VolumeButton(Gtk.VolumeButton):
|
|||||||
def _on_disconnected(self, *args):
|
def _on_disconnected(self, *args):
|
||||||
self.set_sensitive(False)
|
self.set_sensitive(False)
|
||||||
self._refresh(None, -1)
|
self._refresh(None, -1)
|
||||||
if self._popover is not None:
|
|
||||||
self._popover.popdown()
|
|
||||||
self._popover=None
|
|
||||||
|
|
||||||
###################
|
###################
|
||||||
# MPD gio actions #
|
# MPD gio actions #
|
||||||
|
Loading…
Reference in New Issue
Block a user