示例#1
0
def switch_backdrop_to(backdrop):
    # TODO(Nicolas Despres): Add wait keyword argument to mimic the
    #   "switch to <backdrop> and wait" block?
    if not isinstance(backdrop, str):
        raise TypeError("backdrop must be str, not {}".format(
            type(backdrop).__name__))
    send_request(message.BackdropSwitchTo(name=backdrop))
示例#2
0
 def __setattr__(self, name, value):
     if name.startswith("_"):
         return super().__setattr__(name, value)
     # When executing code like "shared_variable.score += 1",
     # __setattr__ is called with name="score" and value="value returned by
     # __iadd__". In such case, the in-place operation have already been
     # committed, thus it is useless to create a new variable.
     if isinstance(value, SharedVariable):
         return
     send_request(message.SharedVariableNew(name=name, value=value))
示例#3
0
 def __getattr__(self, name):
     try:
         value = send_request(message.SharedVariableOp(name=name, op="get"))
     except KeyError:
         raise AttributeError(f"undefined shared variable '{name}'")
     else:
         return SharedVariable(name, value)
示例#4
0
def wait(delay):
    send_request(message.Wait(delay=delay))
示例#5
0
def stop_program(reason=""):
    script = get_context_script()
    get_script_logger().log(logging.INFO,
                            f"script {script.name} has stopped the program")
    send_request(message.StopProgram(reason=reason))
示例#6
0
def wait(delay):
    """Wait for _delay_ seconds (decimal value allowed)."""
    if not isinstance(delay, (int, float)):
        raise TypeError("delay must be int or float, not {}".format(
            type(delay).__name__))
    send_request(message.Wait(delay=delay))
示例#7
0
 def __delattr__(self, name):
     try:
         send_request(message.SharedVariableDel(name))
     except KeyError:
         raise AttributeError(f"undefined shared variable '{name}'")
示例#8
0
 def __iadd__(self, other):
     send_request(
         message.SharedVariableOp(name=self._name,
                                  op="__iadd__",
                                  args=(other, )))
     return self
示例#9
0
 def show(self):
     return send_request(
         message.SharedVariableOp(name=self._name, op="show"))
示例#10
0
 def hide(self):
     return send_request(
         message.SharedVariableOp(name=self._name, op="hide"))