mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2025-08-06 03:41:46 +00:00
convert projector commands
This commit is contained in:
parent
e658819719
commit
75fc18273e
@ -27,6 +27,7 @@ for sub_app in (
|
|||||||
'hotkey',
|
'hotkey',
|
||||||
'input',
|
'input',
|
||||||
'profile',
|
'profile',
|
||||||
|
'projector',
|
||||||
'filter',
|
'filter',
|
||||||
'scene',
|
'scene',
|
||||||
):
|
):
|
||||||
|
@ -2,25 +2,25 @@
|
|||||||
|
|
||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
|
|
||||||
import typer
|
from cyclopts import App, Argument, Parameter
|
||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
from rich.text import Text
|
from rich.text import Text
|
||||||
|
|
||||||
from . import console
|
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()
|
@app.command(name=['list-monitors', 'ls-m'])
|
||||||
def main():
|
def list_monitors(
|
||||||
"""Control projectors in OBS."""
|
*,
|
||||||
|
ctx: Annotated[Context, Parameter(parse=False)],
|
||||||
|
):
|
||||||
@app.command('list-monitors | ls-m')
|
|
||||||
def list_monitors(ctx: typer.Context):
|
|
||||||
"""List available monitors."""
|
"""List available monitors."""
|
||||||
resp = ctx.obj['obsws'].get_monitor_list()
|
resp = ctx.client.get_monitor_list()
|
||||||
|
|
||||||
if not resp.monitors:
|
if not resp.monitors:
|
||||||
console.out.print('No monitors found.')
|
console.out.print('No monitors found.')
|
||||||
@ -34,13 +34,13 @@ def list_monitors(ctx: typer.Context):
|
|||||||
table = Table(
|
table = Table(
|
||||||
title='Available Monitors',
|
title='Available Monitors',
|
||||||
padding=(0, 2),
|
padding=(0, 2),
|
||||||
border_style=ctx.obj['style'].border,
|
border_style=ctx.style.border,
|
||||||
)
|
)
|
||||||
table.add_column(
|
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(
|
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:
|
for index, monitor in monitors:
|
||||||
@ -49,29 +49,30 @@ def list_monitors(ctx: typer.Context):
|
|||||||
console.out.print(table)
|
console.out.print(table)
|
||||||
|
|
||||||
|
|
||||||
@app.command('open | o')
|
@app.command(name=['open', 'o'])
|
||||||
def open(
|
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[
|
source_name: Annotated[
|
||||||
str,
|
str,
|
||||||
typer.Argument(
|
Argument(
|
||||||
show_default='The current scene',
|
hint='Name of the source to project.',
|
||||||
help='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."""
|
"""Open a fullscreen projector for a source on a specific monitor."""
|
||||||
if not source_name:
|
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:
|
for monitor in monitors:
|
||||||
if monitor['monitorIndex'] == monitor_index:
|
if monitor['monitorIndex'] == monitor_index:
|
||||||
ctx.obj['obsws'].open_source_projector(
|
ctx.client.open_source_projector(
|
||||||
source_name=source_name,
|
source_name=source_name,
|
||||||
monitor_index=monitor_index,
|
monitor_index=monitor_index,
|
||||||
)
|
)
|
||||||
@ -82,8 +83,8 @@ def open(
|
|||||||
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
console.err.print(
|
raise OBSWSCLIError(
|
||||||
f'Monitor with index [yellow]{monitor_index}[/yellow] not found. '
|
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)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user