Esempio n. 1
0
    def on_signal(self, args, block):
        name = args[0]
        rest = args[1:]
        signal = create_signal(name, rest, None)

        ctx = SequentialActionContext()
        ctx.apply_block(block)

        self.signals.append((signal, ctx, [None]))
Esempio n. 2
0
    def on_while(self, args, block):
        self.op = args[1]
        if op not in {"==", "!=", "in", "not in"}:
            raise ValueError(f"while: unknown operand {op}")
        self.lhs = args[0]
        self.rhs = args[2]

        ctx = SequentialActionContext()
        ctx.apply_block(block)

        self.actions.append(ctx)
Esempio n. 3
0
class StateDefinition(SignalContext, BaseButtonDefinition):
    def __init__(self, name: str, default: bool):
        super().__init__()
        self.name = name
        self.default = default
        self.entered = None
        self.leaving = None

    @validated(min_args=0, max_args=0, with_block=True)
    def on_entered(self, args, block):
        self.entered = SequentialActionContext()
        self.entered.apply_block(block)

    @validated(min_args=0, max_args=0, with_block=True)
    def on_leaving(self, args, block):
        self.leaving = SequentialActionContext()
        self.leaving.apply_block(block)

    async def when_entered(self, app, target):
        if self.entered is not None:
            await self.entered.apply_actions(app, target)

        for signal, sig_ctx, cb_holder in self.signals:
            if cb_holder[0] is not None:
                continue

            cb = (lambda ctx:
                  (lambda: ctx.apply_actions(app, target)))(sig_ctx)
            cb_holder[0] = cb
            signal.register(cb)

    async def when_leaving(self, app, target):
        if self.leaving is not None:
            await self.leaving.apply_actions(app, target)

        for signal, sig_ctx, cb_holder in self.signals:
            signal.unregister(cb_holder[0])
            cb_holder[0] = None
Esempio n. 4
0
    def on_button(self, args, block):
        from streamdeckd.display import Display

        x = int(args[0])
        y = int(args[1])

        ctx = SequentialActionContext()
        ctx.apply_block(block)

        @self.actions.append
        @ActionableContext.simple
        async def _op(app, target):
            while isinstance(target, State):
                if isinstance(target, Display):
                    break

                target = target.parent

            if not isinstance(target, Display):
                return

            target = target.buttons[(x, y)]
            await ctx.apply_actions(app, target)
Esempio n. 5
0
 def on_entered(self, args, block):
     self.entered = SequentialActionContext()
     self.entered.apply_block(block)
Esempio n. 6
0
 def on_connected(self, args, block):
     ctx = SequentialActionContext()
     ctx.apply_block(block)
     self.connected = ctx
Esempio n. 7
0
 def on_released(self, args, block):
     ctx = SequentialActionContext()
     ctx.apply_block(block)
     self.state["released"] = ctx
Esempio n. 8
0
 def on_opened(self, args, block):
     ctx = SequentialActionContext()
     ctx.apply_block(block)
     self.opened = ctx
Esempio n. 9
0
 def on_leaving(self, args, block):
     self.leaving = SequentialActionContext()
     self.leaving.apply_block(block)