From 2739fa28f0d61764e5134b70bef660925a354ceb Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Mon, 26 May 2025 20:54:22 +0100 Subject: [PATCH] add projector subtyper --- obsws_cli/app.py | 2 ++ obsws_cli/projector.py | 58 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 obsws_cli/projector.py diff --git a/obsws_cli/app.py b/obsws_cli/app.py index 78583b4..e6b9483 100644 --- a/obsws_cli/app.py +++ b/obsws_cli/app.py @@ -12,6 +12,7 @@ from . import ( hotkey, input, profile, + projector, record, replaybuffer, scene, @@ -30,6 +31,7 @@ for module in ( group, hotkey, input, + projector, profile, record, replaybuffer, diff --git a/obsws_cli/projector.py b/obsws_cli/projector.py new file mode 100644 index 0000000..ac69f11 --- /dev/null +++ b/obsws_cli/projector.py @@ -0,0 +1,58 @@ +"""module containing commands for manipulating projectors in OBS.""" + +from typing import Annotated + +import typer +from rich.console import Console +from rich.table import Table + +from .alias import AliasGroup + +app = typer.Typer(cls=AliasGroup) +out_console = Console() +err_console = Console(stderr=True) + + +@app.callback() +def main(): + """Control projectors in OBS.""" + + +@app.command('list-monitors | ls-m') +def list_monitors(ctx: typer.Context): + """List available monitors.""" + resp = ctx.obj.get_monitor_list() + + if not resp.monitors: + out_console.print('No monitors found.') + return + + monitors = sorted( + ((m['monitorIndex'], m['monitorName']) for m in resp.monitors), + key=lambda m: m[0], + ) + + table = Table(title='Available Monitors', padding=(0, 2)) + table.add_column('Index', justify='right', style='cyan') + table.add_column('Name', style='cyan') + + for index, monitor in monitors: + table.add_row(str(index), monitor) + + out_console.print(table) + + +@app.command('open | o') +def open( + ctx: typer.Context, + source_name: str, + monitor_index: Annotated[ + int, + typer.Option(help='Index of the monitor to open the projector on.'), + ] = 0, +): + """Open a fullscreen projector for a source on a specific monitor.""" + ctx.obj.open_source_projector( + source_name=source_name, + monitor_index=monitor_index, + )