diff options
| author | Franziska Kunsmann <hi@kunsmann.eu> | 2023-01-11 15:00:46 +0100 |
|---|---|---|
| committer | Franziska Kunsmann <hi@kunsmann.eu> | 2023-01-11 15:00:46 +0100 |
| commit | da8f6e83627d8068d3f9a0e1bd68eb57e3571e2f (patch) | |
| tree | 6adb65ef1b183709826151ec3d608ad5d79d4f01 | |
| parent | 2d4dfc58844c7b16e51492ccbb5fbf0bff425f4c (diff) | |
get it working
| -rw-r--r-- | gui.py | 76 | ||||
| -rw-r--r-- | switcher.py | 13 |
2 files changed, 68 insertions, 21 deletions
@@ -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() diff --git a/switcher.py b/switcher.py index e4a7e1c..e14dbad 100644 --- a/switcher.py +++ b/switcher.py @@ -19,6 +19,7 @@ class PyATEMSwitcher: self._connect_subscribers = [] self._connect_attempt_subscribers = [] self._disconnect_subscribers = [] + self._receive_subscribers = [] self._validate_config() @@ -34,6 +35,10 @@ class PyATEMSwitcher: self.atem.atem.events.disconnect, self._on_disconnect, ) + self.atem.registerEvent( + self.atem.atem.events.receive, + self._on_receive, + ) def _on_connect(self, params): self.log.debug(f'_on_connect({repr(params)})') @@ -51,6 +56,11 @@ class PyATEMSwitcher: for callback in self._disconnect_subscribers: callback(params['switcher']) + def _on_receive(self, params): + self.log.debug(f'_on_receive({repr(params)})') + for callback in self._receive_subscribers: + callback(params) + def _push_config(self): conf = self.config.get('settings', {}) @@ -95,6 +105,9 @@ class PyATEMSwitcher: def on_disconnect(self, callback): self._disconnect_subscribers.append(callback) + def on_receive(self, callback): + self._receive_subscribers.append(callback) + def trans(self, input): self.log.debug(f'hehehehe trans({repr(input)})') self.atem.setProgramInputVideoSource( |
