convert projector commands

This commit is contained in:
onyx-and-iris 2025-07-24 02:20:17 +01:00
parent e658819719
commit 75fc18273e
2 changed files with 31 additions and 29 deletions

View File

@ -27,6 +27,7 @@ for sub_app in (
'hotkey',
'input',
'profile',
'projector',
'filter',
'scene',
):

View File

@ -2,25 +2,25 @@
from typing import Annotated
import typer
from cyclopts import App, Argument, Parameter
from rich.table import Table
from rich.text import Text
from . import console
from .alias import SubTyperAliasGroup
from .context import Context
from .enum import ExitCode
from .error import OBSWSCLIError
app = typer.Typer(cls=SubTyperAliasGroup)
app = App(name='projector', help='Commands for managing projectors in OBS')
@app.callback()
def main():
"""Control projectors in OBS."""
@app.command('list-monitors | ls-m')
def list_monitors(ctx: typer.Context):
@app.command(name=['list-monitors', 'ls-m'])
def list_monitors(
*,
ctx: Annotated[Context, Parameter(parse=False)],
):
"""List available monitors."""
resp = ctx.obj['obsws'].get_monitor_list()
resp = ctx.client.get_monitor_list()
if not resp.monitors:
console.out.print('No monitors found.')
@ -34,13 +34,13 @@ def list_monitors(ctx: typer.Context):
table = Table(
title='Available Monitors',
padding=(0, 2),
border_style=ctx.obj['style'].border,
border_style=ctx.style.border,
)
table.add_column(
Text('Index', justify='center'), justify='center', style=ctx.obj['style'].column
Text('Index', justify='center'), justify='center', style=ctx.style.column
)
table.add_column(
Text('Name', justify='center'), justify='left', style=ctx.obj['style'].column
Text('Name', justify='center'), justify='left', style=ctx.style.column
)
for index, monitor in monitors:
@ -49,29 +49,30 @@ def list_monitors(ctx: typer.Context):
console.out.print(table)
@app.command('open | o')
@app.command(name=['open', 'o'])
def open(
ctx: typer.Context,
monitor_index: Annotated[
int,
typer.Option(help='Index of the monitor to open the projector on.'),
] = 0,
source_name: Annotated[
str,
typer.Argument(
show_default='The current scene',
help='Name of the source to project.',
Argument(
hint='Name of the source to project.',
),
] = '',
/,
monitor_index: Annotated[
int,
Parameter(help='Index of the monitor to open the projector on.'),
] = 0,
*,
ctx: Annotated[Context, Parameter(parse=False)],
):
"""Open a fullscreen projector for a source on a specific monitor."""
if not source_name:
source_name = ctx.obj['obsws'].get_current_program_scene().scene_name
source_name = ctx.client.get_current_program_scene().scene_name
monitors = ctx.obj['obsws'].get_monitor_list().monitors
monitors = ctx.client.get_monitor_list().monitors
for monitor in monitors:
if monitor['monitorIndex'] == monitor_index:
ctx.obj['obsws'].open_source_projector(
ctx.client.open_source_projector(
source_name=source_name,
monitor_index=monitor_index,
)
@ -82,8 +83,8 @@ def open(
break
else:
console.err.print(
raise OBSWSCLIError(
f'Monitor with index [yellow]{monitor_index}[/yellow] not found. '
f'Use [yellow]obsws-cli projector ls-m[/yellow] to see available monitors.'
f'Use [yellow]obsws-cli projector ls-m[/yellow] to see available monitors.',
ExitCode.ERROR,
)
raise typer.Exit(code=1)