generated from itdominator/Python-With-Gtk-Template
Separation of containers
This commit is contained in:
parent
834d7ee94b
commit
572041a2a3
@ -7,17 +7,15 @@ from gi.repository import Gtk
|
|||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
|
from .sink_input_list import SinkInputList, AudioSink
|
||||||
from utils.pulsectl import pulsectl
|
from utils.pulsectl import pulsectl
|
||||||
from ..widgets.audio_sink import AudioSink
|
|
||||||
|
|
||||||
|
|
||||||
class BaseContainer(Gtk.Box):
|
class BaseContainer(Gtk.Box):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(BaseContainer, self).__init__()
|
super(BaseContainer, self).__init__()
|
||||||
|
|
||||||
self._scroll = None
|
|
||||||
self._box = None
|
|
||||||
|
|
||||||
self.pulse = None
|
self.pulse = None
|
||||||
self.pulse_events = None
|
self.pulse_events = None
|
||||||
self.sink_inputs = None
|
self.sink_inputs = None
|
||||||
@ -42,17 +40,20 @@ class BaseContainer(Gtk.Box):
|
|||||||
...
|
...
|
||||||
|
|
||||||
def _subscribe_to_events(self):
|
def _subscribe_to_events(self):
|
||||||
event_system.subscribe("handle_new_sync_input", self._handle_new_sync_input)
|
...
|
||||||
event_system.subscribe("handle_del_sync_input", self._handle_del_sync_input)
|
|
||||||
event_system.subscribe("handle_cng_sync_input", self._handle_cng_sync_input)
|
|
||||||
|
|
||||||
def _load_widgets(self):
|
def _load_widgets(self):
|
||||||
scroll = Gtk.ScrolledWindow()
|
self._load_pulse_data()
|
||||||
viewport = Gtk.Viewport()
|
|
||||||
box = Gtk.Box()
|
|
||||||
scroll.add(viewport)
|
|
||||||
viewport.add(box)
|
|
||||||
|
|
||||||
|
scroll = SinkInputList(self.pulse)
|
||||||
|
box = scroll.get_box()
|
||||||
|
for sink_input in self.sink_inputs:
|
||||||
|
box.add( AudioSink(self.pulse, sink_input) )
|
||||||
|
|
||||||
|
self.add(scroll)
|
||||||
|
self._set_pulse_event_listener()
|
||||||
|
|
||||||
|
def _load_pulse_data(self):
|
||||||
try:
|
try:
|
||||||
pulse = pulsectl.Pulse()
|
pulse = pulsectl.Pulse()
|
||||||
self.pulse_events = pulsectl.Pulse('event-printer')
|
self.pulse_events = pulsectl.Pulse('event-printer')
|
||||||
@ -64,48 +65,11 @@ class BaseContainer(Gtk.Box):
|
|||||||
|
|
||||||
self.pulse = pulse
|
self.pulse = pulse
|
||||||
self.sink_inputs = sink_inputs
|
self.sink_inputs = sink_inputs
|
||||||
for sink_input in sink_inputs:
|
|
||||||
box.add( AudioSink(pulse, sink_input) )
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"{e}")
|
logger.debug(f"{e}")
|
||||||
|
|
||||||
self._box = box
|
|
||||||
self._scroll = scroll.get_vadjustment()
|
|
||||||
|
|
||||||
self._scroll.connect("changed", self._scroll_to_bottom)
|
|
||||||
|
|
||||||
scroll.set_vexpand(True)
|
|
||||||
scroll.set_overlay_scrolling(False)
|
|
||||||
scroll.set_margin_top(20)
|
|
||||||
scroll.set_margin_bottom(10)
|
|
||||||
box.set_orientation(Gtk.Orientation.VERTICAL)
|
|
||||||
self.add(scroll)
|
|
||||||
|
|
||||||
self.set_pulse_event_listener()
|
|
||||||
|
|
||||||
def _handle_new_sync_input(self, index):
|
|
||||||
sink_input = self.pulse.sink_input_list()[-1]
|
|
||||||
self._box.add( AudioSink(self.pulse, sink_input) )
|
|
||||||
|
|
||||||
def _handle_del_sync_input(self, index):
|
|
||||||
for sink_input in self.sink_inputs:
|
|
||||||
if index == sink_input.index:
|
|
||||||
self.sink_inputs.remove(sink_input)
|
|
||||||
|
|
||||||
for child in self._box.get_children():
|
|
||||||
if index == child.sink.index:
|
|
||||||
child.destroy()
|
|
||||||
|
|
||||||
def _handle_cng_sync_input(self, index):
|
|
||||||
for child in self._box.get_children():
|
|
||||||
if index == child.sink.index:
|
|
||||||
child.do_update()
|
|
||||||
|
|
||||||
def _scroll_to_bottom(self, adjustment):
|
|
||||||
self._scroll.set_value( adjustment.get_upper() )
|
|
||||||
|
|
||||||
@daemon_threaded
|
@daemon_threaded
|
||||||
def set_pulse_event_listener(self):
|
def _set_pulse_event_listener(self):
|
||||||
try:
|
try:
|
||||||
self.pulse_events.event_mask_set('all')
|
self.pulse_events.event_mask_set('all')
|
||||||
self.pulse_events.event_callback_set(self._sub_threaded_event)
|
self.pulse_events.event_callback_set(self._sub_threaded_event)
|
||||||
|
77
src/core/containers/sink_input_list.py
Normal file
77
src/core/containers/sink_input_list.py
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
|
from gi.repository import Gtk
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
from ..widgets.audio_sink import AudioSink
|
||||||
|
|
||||||
|
|
||||||
|
class SinkInputList(Gtk.ScrolledWindow):
|
||||||
|
def __init__(self, pulse):
|
||||||
|
super(SinkInputList, self).__init__()
|
||||||
|
|
||||||
|
self.pulse = pulse
|
||||||
|
self._vadjust = None
|
||||||
|
self._box = None
|
||||||
|
|
||||||
|
self._setup_styling()
|
||||||
|
self._setup_signals()
|
||||||
|
self._subscribe_to_events()
|
||||||
|
self._load_widgets()
|
||||||
|
|
||||||
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
|
def _setup_styling(self):
|
||||||
|
self.set_vexpand(True)
|
||||||
|
self.set_overlay_scrolling(False)
|
||||||
|
self.set_margin_top(20)
|
||||||
|
self.set_margin_bottom(10)
|
||||||
|
|
||||||
|
def _setup_signals(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
def _subscribe_to_events(self):
|
||||||
|
event_system.subscribe("handle_new_sync_input", self._handle_new_sync_input)
|
||||||
|
event_system.subscribe("handle_del_sync_input", self._handle_del_sync_input)
|
||||||
|
event_system.subscribe("handle_cng_sync_input", self._handle_cng_sync_input)
|
||||||
|
|
||||||
|
def _load_widgets(self):
|
||||||
|
viewport = Gtk.Viewport()
|
||||||
|
box = Gtk.Box()
|
||||||
|
self._box = box
|
||||||
|
self._vadjust = self.get_vadjustment()
|
||||||
|
|
||||||
|
box.set_orientation(Gtk.Orientation.VERTICAL)
|
||||||
|
self._vadjust.connect("changed", self._scroll_to_bottom)
|
||||||
|
|
||||||
|
viewport.add(box)
|
||||||
|
self.add(viewport)
|
||||||
|
|
||||||
|
def _handle_cng_sync_input(self, index):
|
||||||
|
for child in self._box.get_children():
|
||||||
|
if index == child.sink.index:
|
||||||
|
child.do_update()
|
||||||
|
|
||||||
|
def _handle_new_sync_input(self, index):
|
||||||
|
sink_input = self.pulse.sink_input_list()[-1]
|
||||||
|
self._box.add( AudioSink(self.pulse, sink_input) )
|
||||||
|
|
||||||
|
def _handle_del_sync_input(self, index):
|
||||||
|
parent = self.get_parent()
|
||||||
|
for sink_input in parent.sink_inputs:
|
||||||
|
if index == sink_input.index:
|
||||||
|
parent.sink_inputs.remove(sink_input)
|
||||||
|
|
||||||
|
for child in self._box.get_children():
|
||||||
|
if index == child.sink.index:
|
||||||
|
child.destroy()
|
||||||
|
|
||||||
|
def _scroll_to_bottom(self, adjustment):
|
||||||
|
self._vadjust.set_value( adjustment.get_upper() )
|
||||||
|
|
||||||
|
def get_box(self):
|
||||||
|
return self._box
|
Loading…
Reference in New Issue
Block a user