From: sbkelley Date: Tue, 2 Dec 2025 18:03:04 +0000 (-0500) Subject: mov OBSApp to its own file X-Git-Url: https://skyeroc.xyz/gitweb/?a=commitdiff_plain;h=14f4a0be223fd240258bd01c1680fbb20e2c2947;p=obs-ctl mov OBSApp to its own file --- diff --git a/src/obs_ctl/__init__.py b/src/obs_ctl/__init__.py index 205d6ca..5aa6397 100644 --- a/src/obs_ctl/__init__.py +++ b/src/obs_ctl/__init__.py @@ -1,107 +1,5 @@ -import importlib.resources +from .app import OBSCtlApp -from textual import on -from textual.app import App -from textual.containers import Vertical, Horizontal, ScrollableContainer -from textual.widgets import Footer, Header, Placeholder, TabbedContent, TabPane - -from . import log, data -from .interface import RecordControls, StatsDisplay, OBSSettingsPane, obs - -logger = log.getLogger(__name__) - - -class OBSCtlApp(App): - CSS_PATH = importlib.resources.files(data).joinpath("layout.tcss") - - def compose(self): - yield Header() - yield Footer() - yield obs.API(1, id="api") - logger.debug("Composing OBSCtlApp") - with ScrollableContainer(id="content_container"): - with Vertical(id="blocks_v_container", classes="blocks_containers"): - with Horizontal(id="blocks_h_container1", classes="blocks_h_containers"): - yield RecordControls(id="record_controls") - with TabbedContent(id="settings_container", classes="blocks"): - with TabPane("OBS Settings", id="settings-tab"): - yield OBSSettingsPane(id="settings-content") - with TabPane("OBS Connection", id="connection-tab"): - yield Placeholder("CONNECTION BLOCK", id="conection-plc") - with TabPane("obs-ctl Settings", id="clients-tab"): - yield Placeholder("CLIENT SETTINGS BLOCK", id="client-plc") - yield StatsDisplay(id="stats_display") - - - @on(obs.API.Report, "#api") - def on_api_report(self, message: obs.API.Report): - self.update_monitors(message.data) - - - @on(RecordControls.RecordStarted, "#record_controls") - def on_record_started(self, message: RecordControls.RecordStarted): - self._query_api("start_record") - - - @on(RecordControls.RecordStopped, "#record_controls") - def on_record_stopped(self, message: RecordControls.RecordStopped): - self._query_api("stop_record") - - - @on(RecordControls.StreamStarted, "#record_controls") - def on_stream_started(self, message: RecordControls.StreamStarted): - self._query_api("start_stream") - - - @on(RecordControls.StreamStopped, "#record_controls") - def on_stream_stopped(self, message: RecordControls.StreamStopped): - self._query_api("stop_stream") - - - @on(RecordControls.RecordPaused, "#record_controls") - def on_record_paused(self, message: RecordControls.RecordPaused): - self._query_api("start_pause") - - - @on(RecordControls.RecordUnpaused, "#record_controls") - def on_record_unpaused(self, message: RecordControls.RecordUnpaused): - self._query_api("stop_pause") - - - @on(RecordControls.OBSWSConnected, "#record_controls") - def on_obs_ws_connected(self, message: RecordControls.OBSWSConnected): - self._query_api("connect") - - - @on(RecordControls.OBSWSDisconnected, "#record_controls") - def on_obs_ws_connected(self, message: RecordControls.OBSWSDisconnected): - self._query_api("disconnect") - - - def _query_api(self, query: str, *args, **kwargs): - api: obs.API = self.query_exactly_one("#api") - getattr(api, query)(*args, **kwargs) - - - @on(OBSSettingsPane.RecordPathChanged, "#settings-content") - def on_settings_record_path_changed(self, message: OBSSettingsPane.RecordPathChanged): - api: obs.API = self.query_exactly_one("#api") - api.set_record_path(message.record_path) - - - def update_monitors(self, obs_stats: obs.OBSStats): - record_controls: RecordControls = self.query_exactly_one("#record_controls") - obs_settings: OBSSettingsPane = self.query_exactly_one("#settings-content") - stats_display: StatsDisplay = self.query_exactly_one("#stats_display") - - record_controls.obsws_connected = obs_stats.obsws_connection_active - record_controls.streaming = obs_stats.stream_output_active - record_controls.recording = obs_stats.record_output_active - record_controls.paused = obs_stats.record_output_paused - obs_settings.record_path = obs_stats.record_directory - stats_display.update_text_readouts(obs_stats) - - -def main(): +def run(): app = OBSCtlApp() app.run() \ No newline at end of file diff --git a/src/obs_ctl/__main__.py b/src/obs_ctl/__main__.py index 878197e..cd2562e 100644 --- a/src/obs_ctl/__main__.py +++ b/src/obs_ctl/__main__.py @@ -1,4 +1,4 @@ -from . import main +from . import run if __name__ == "__main__": - main() \ No newline at end of file + run() \ No newline at end of file diff --git a/src/obs_ctl/app.py b/src/obs_ctl/app.py new file mode 100644 index 0000000..5432ef7 --- /dev/null +++ b/src/obs_ctl/app.py @@ -0,0 +1,102 @@ +import importlib.resources + +from textual import on +from textual.app import App +from textual.containers import Vertical, Horizontal, ScrollableContainer +from textual.widgets import Footer, Header, Placeholder, TabbedContent, TabPane + +from . import log, data +from .interface import RecordControls, StatsDisplay, OBSSettingsPane, obs + +logger = log.getLogger(__name__) + + +class OBSCtlApp(App): + CSS_PATH = importlib.resources.files(data).joinpath("layout.tcss") + + def compose(self): + yield Header() + yield Footer() + yield obs.API(1, id="api") + logger.debug("Composing OBSCtlApp") + with ScrollableContainer(id="content_container"): + with Vertical(id="blocks_v_container", classes="blocks_containers"): + with Horizontal(id="blocks_h_container1", classes="blocks_h_containers"): + yield RecordControls(id="record_controls") + with TabbedContent(id="settings_container", classes="blocks"): + with TabPane("OBS Settings", id="settings-tab"): + yield OBSSettingsPane(id="settings-content") + with TabPane("OBS Connection", id="connection-tab"): + yield Placeholder("CONNECTION BLOCK", id="conection-plc") + with TabPane("obs-ctl Settings", id="clients-tab"): + yield Placeholder("CLIENT SETTINGS BLOCK", id="client-plc") + yield StatsDisplay(id="stats_display") + + + @on(obs.API.Report, "#api") + def on_api_report(self, message: obs.API.Report): + self.update_monitors(message.data) + + + @on(RecordControls.RecordStarted, "#record_controls") + def on_record_started(self, message: RecordControls.RecordStarted): + self._query_api("start_record") + + + @on(RecordControls.RecordStopped, "#record_controls") + def on_record_stopped(self, message: RecordControls.RecordStopped): + self._query_api("stop_record") + + + @on(RecordControls.StreamStarted, "#record_controls") + def on_stream_started(self, message: RecordControls.StreamStarted): + self._query_api("start_stream") + + + @on(RecordControls.StreamStopped, "#record_controls") + def on_stream_stopped(self, message: RecordControls.StreamStopped): + self._query_api("stop_stream") + + + @on(RecordControls.RecordPaused, "#record_controls") + def on_record_paused(self, message: RecordControls.RecordPaused): + self._query_api("start_pause") + + + @on(RecordControls.RecordUnpaused, "#record_controls") + def on_record_unpaused(self, message: RecordControls.RecordUnpaused): + self._query_api("stop_pause") + + + @on(RecordControls.OBSWSConnected, "#record_controls") + def on_obs_ws_connected(self, message: RecordControls.OBSWSConnected): + self._query_api("connect") + + + @on(RecordControls.OBSWSDisconnected, "#record_controls") + def on_obs_ws_connected(self, message: RecordControls.OBSWSDisconnected): + self._query_api("disconnect") + + + def _query_api(self, query: str, *args, **kwargs): + api: obs.API = self.query_exactly_one("#api") + getattr(api, query)(*args, **kwargs) + + + @on(OBSSettingsPane.RecordPathChanged, "#settings-content") + def on_settings_record_path_changed(self, message: OBSSettingsPane.RecordPathChanged): + api: obs.API = self.query_exactly_one("#api") + api.set_record_path(message.record_path) + + + def update_monitors(self, obs_stats: obs.OBSStats): + record_controls: RecordControls = self.query_exactly_one("#record_controls") + obs_settings: OBSSettingsPane = self.query_exactly_one("#settings-content") + stats_display: StatsDisplay = self.query_exactly_one("#stats_display") + + record_controls.obsws_connected = obs_stats.obsws_connection_active + record_controls.streaming = obs_stats.stream_output_active + record_controls.recording = obs_stats.record_output_active + record_controls.paused = obs_stats.record_output_paused + obs_settings.record_path = obs_stats.record_directory + stats_display.update_text_readouts(obs_stats) \ No newline at end of file diff --git a/src/obs_ctl/data/__init__.py b/src/obs_ctl/data/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/obs_ctl/interface/__init__.py b/src/obs_ctl/interface/__init__.py index fc2366a..0f114e1 100644 --- a/src/obs_ctl/interface/__init__.py +++ b/src/obs_ctl/interface/__init__.py @@ -1,2 +1,3 @@ """Provides RecordControls, OBSSettingsPane, and StatsDisplay to obs-ctl""" -from .molecule import RecordControls, OBSSettingsPane, StatsDisplay \ No newline at end of file +from .molecule import RecordControls, OBSSettingsPane, StatsDisplay +from . import obs \ No newline at end of file diff --git a/src/vscode_run_entrypoint.py b/src/vscode_run_entrypoint.py index e87038c..cbf11ba 100644 --- a/src/vscode_run_entrypoint.py +++ b/src/vscode_run_entrypoint.py @@ -1,3 +1,3 @@ import obs_ctl -obs_ctl.main() \ No newline at end of file +obs_ctl.run() \ No newline at end of file