def __repr__(self, **k):
     # type: (Any) -> str
     output = "%s" % get_callable_repr(self.func)
     if self.awaited_listener:
         output += " (waiting for listener call %s)" % get_callable_repr(
             self.awaited_listener)
     return output
Exemple #2
0
 def __repr__(self):
     # type: () -> str
     if self._wrapped:
         return str(self._wrapped)
     else:
         return "%s_%d_%s" % (get_callable_repr(
             self._func), id(self), self.__class__.__name__)
 def __init__(self, callback, tick_count, *a, **k):
     # type: (Callable, int, Any, Any) -> None
     super(SchedulerEvent, self).__init__(*a, **k)
     self._executed = False
     self._cancelled = False
     self._callback = callback
     self._tick_count = tick_count
     self._ticks_left = tick_count
     self.name = get_callable_repr(self._callback)
Exemple #4
0
    def execute(self, encoder_name, *a, **k):
        # type: (str, Any, Any) -> Optional[Sequence]
        """
        NB : Here lambda is just a way to act on the right objects at runtime
            like this we can display the function name
        """
        if self._is_executing:
            self._is_executing = False
            if self.cancel_action:
                self.cancel_action.execute(encoder_name, *a, **k)
                return None
            raise DoubleEncoderActionExecution(self)

        if self.song:
            self.song.begin_undo_step()
        if is_lambda(self.func):
            func = self.func(
            )  # allows delaying property lookup until execution time
        else:
            func = self.func
        if func is None:
            return None  # the action is sync and is already processed
        assert callable(
            func), "%s : action func should be callable, got %s" % (
                encoder_name,
                get_callable_repr(func),
            )
        if self.move_type != EncoderMoveEnum.SCROLL:
            self.parent.log_notice("%s : executing %s" %
                                   (encoder_name, get_callable_repr(func)))
        else:
            self.parent.log_notice("%s : scrolling %s" %
                                   (encoder_name, get_callable_repr(func)))

        self._is_executing = True
        seq = Sequence()
        with self.parent.component_guard():
            seq.add(partial(func, *a, **k))
            if self.song:
                seq.add(self.song.end_undo_step)
            seq.on_end(partial(setattr, self, "_is_executing", False))
        return seq.done()
Exemple #5
0
    def __repr__(self, **k):
        # type: (Any) -> str
        output = self.name
        if self.wait_for_system:
            output += " (and wait for system)"
        elif self._complete_on:
            output += " (and wait for listener call : %s)" % get_callable_repr(
                self._complete_on)
        elif self._wait:
            output += " (and wait %s)" % self._wait
        elif self._wait_beats:
            output += " (and wait_beats %.2f)" % self._wait_beats

        return "[%s]" % output
Exemple #6
0
 def __init__(self, func, move_type, name, *a, **k):
     # type: (Callable, EncoderMoveEnum, Optional[str], Any, Any) -> None
     """
     base moves are listed in the enum. press is the default choice
     """
     super(EncoderAction, self).__init__(*a, **k)
     assert callable(
         func
     ), "func action should be callable: %s" % get_callable_repr(func)
     self.func = func
     self.move_type = move_type
     self.name = name
     self._is_executing = False
     self.cancel_action = None  # type: Optional[EncoderAction]
Exemple #7
0
    def __init__(
            self,
            func,  # type: Callable
            sequence,  # type: Sequence
            name,  # type: str
            wait,  # type: int
            wait_beats,  # type: float
            wait_for_system,  # type: bool
            no_cancel,  # type: bool
            complete_on,  # type: Optional[Union[Callable, CallableWithCallbacks]]
            check_timeout,  # type: int
            *a,  # type: Any
            **k  # type: Any
    ):
        """ the tick is 100 ms """
        super(SequenceStep, self).__init__(*a, **k)
        if not name and func == nop:
            name = "wait %s" % wait if wait else "pass"
        self.name = "step %s" % (name or get_callable_repr(func))
        self._sequence_name = sequence.name
        self._callable = func
        self._wait = wait
        self._wait_beats = wait_beats or 0
        self.wait_for_system = wait_for_system
        self.no_cancel = no_cancel
        self._complete_on = complete_on
        self._check_timeout = check_timeout
        self._callback_timeout = None  # type: Optional[Callable]
        self.res = None  # type: Optional[Any]

        if self.wait_for_system:
            assert self._wait == 0 and self._wait_beats == 0 and self._complete_on is None, "waiting for system excludes other waiting options"
        if self._complete_on:
            assert self._wait == 0 and self._wait_beats == 0, "complete_on excludes wait and wait_beats"
        if self._wait:
            assert self._wait_beats == 0, "wait excludes wait_beats"
        if self.no_cancel:
            assert self.wait_for_system, "no cancel used without wait_for_system"
        assert callable(
            self._callable), "You passed a non callable (%s) to %s" % (
                self._callable, self)
        from protocol0.sequence.Sequence import Sequence

        if Config.SEQUENCE_SLOW_MO:
            self._wait = min(100, self._wait * 5)
            self._check_timeout += 5
Exemple #8
0
 def __repr__(self, **k):
     # type: (Any) -> str
     return "%s : %s" % (self.name, get_callable_repr(self.func))
Exemple #9
0
 def __repr__(self):
     # type: () -> str
     return "cwc %s" % get_callable_repr(self._function)
Exemple #10
0
 def execute(self):
     # type: () -> None
     from protocol0 import Protocol0
     Protocol0.SELF.log_debug("Api call, executing %s" % get_callable_repr(self.method))
     self.method(**self.args)