summaryrefslogtreecommitdiff
path: root/gui.py
diff options
context:
space:
mode:
authorFranziska Kunsmann <hi@kunsmann.eu>2023-01-11 15:00:46 +0100
committerFranziska Kunsmann <hi@kunsmann.eu>2023-01-11 15:00:46 +0100
commitda8f6e83627d8068d3f9a0e1bd68eb57e3571e2f (patch)
tree6adb65ef1b183709826151ec3d608ad5d79d4f01 /gui.py
parent2d4dfc58844c7b16e51492ccbb5fbf0bff425f4c (diff)
get it working
Diffstat (limited to 'gui.py')
-rw-r--r--gui.py76
1 files changed, 55 insertions, 21 deletions
diff --git a/gui.py b/gui.py
index bb4d25e..eb73bc3 100644
--- a/gui.py
+++ b/gui.py
@@ -30,6 +30,7 @@ class PyATEMSwitcherGui():
self.switcher.on_connect(self._switcher_connected)
self.switcher.on_connect_attempt(self._switcher_connect_attempt)
self.switcher.on_disconnect(self._switcher_disconnected)
+ self.switcher.on_receive(self._switcher_state_changed)
self.window.set_border_width(BUTTON_SPACING)
@@ -45,38 +46,66 @@ class PyATEMSwitcherGui():
Gtk.main_quit(*args, **kwargs)
def _button_clicked(self, button, name):
- # TODO actually do something
self.log.info(f'Button {name} was pressed')
for btn in self.buttons:
- ctx = self.buttons[btn].get_style_context()
+ ctx = self.buttons[btn][0].get_style_context()
if btn == name:
self.log.debug(f'{btn}.add_class("selected")')
ctx.add_class('selected')
+ self.switcher.trans(self.buttons[btn][1])
else:
self.log.debug(f'{btn}.remove_class("selected")')
ctx.remove_class('selected')
def _switcher_connected(self, params):
- self.box = Gtk.FlowBox()
- self.box.set_column_spacing(BUTTON_SPACING)
- self.box.set_max_children_per_line(2)
- self.box.set_row_spacing(BUTTON_SPACING)
- self.box.set_selection_mode(Gtk.SelectionMode.NONE)
- self.box.set_valign(Gtk.Align.START)
-
- # TODO get input list from switcher
- for i in range(1, 7):
- self.buttons[f'input{i}'] = Gtk.Button.new_with_label(
- f'input{i}'
+ log = logging.getLogger('GUI connected')
+
+ log.debug(f'_switcher_connected({params})')
+ log.info(f'Connected to "{params.atemModel}" @ {params.ip}')
+ self.header.props.title = f'{params.atemModel} @ {params.ip}'
+
+ inputs = {}
+ for idx,i in enumerate(params.inputProperties):
+ if not i.shortName:
+ break
+ log.debug(f'Creating Button for {i.shortName} of type {i.externalPortType}: {i.longName}')
+ btn = Gtk.Button.new_with_label(
+ i.longName
)
- self.buttons[f'input{i}'].connect(
+ btn.connect(
'clicked',
self._button_clicked,
- f'input{i}',
+ f'in_{i.shortName}',
)
- self.box.add(self.buttons[f'input{i}'])
+ log.debug(f'Adding {i.shortName} to FlowBox')
+ self.buttons[f'in_{i.shortName}'] = (btn, idx)
+ inputs.setdefault(str(i.externalPortType), []).append(btn)
+ log.debug(repr(inputs))
+
+ log.debug('Creating vertically stacked box as container')
+ self.box = Gtk.VBox(spacing=BUTTON_SPACING)
+
+ for input_type in ('hdmi', 'sdi', 'internal'):
+ if input_type not in inputs:
+ continue
+
+# log.debug(f'Creating FlowBox for {input_type} buttons')
+# flowbox = Gtk.VBox()
+# flowbox.set_column_spacing(BUTTON_SPACING)
+# flowbox.set_max_children_per_line(2)
+# flowbox.set_row_spacing(BUTTON_SPACING)
+# flowbox.set_selection_mode(Gtk.SelectionMode.NONE)
+# flowbox.set_valign(Gtk.Align.START)
+
+ for btn in inputs[input_type]:
+ self.box.pack_start(btn, True, True, 0)
+ #self.box.pack_start(flowbox, True, True, 0)
+
+ log.debug('All FlowBoxes added, adding box to window')
self.window.add(self.box)
+ self.window.show_all()
+ self.log.debug('done')
def _switcher_connect_attempt(self, params):
self.header.props.title = 'PyATEMSwitcherGui: Connecting ...'
@@ -88,13 +117,18 @@ class PyATEMSwitcherGui():
self.buttons = {}
self.header.props.title = 'PyATEMSwitcherGui: Not connected'
- def _switcher_ping(self):
- # TODO actually do something here
- self.log.debug('_switcher_ping()')
- return True
+ def _switcher_state_changed(self, params):
+ source = params['switcher'].programInput[0].videoSource
+ sn = params['switcher'].inputProperties[source].shortName
+ for btn in self.buttons:
+ ctx = self.buttons[btn][0].get_style_context()
+ if btn == f'in_{sn}':
+ ctx.add_class('program')
+ else:
+ ctx.remove_class('program')
+ ctx.remove_class('selected')
def main_loop(self):
self.switcher.connect()
self.window.show_all()
- GObject.timeout_add(500, self._switcher_ping)
Gtk.main()