コード例 #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
ファイル: control.py プロジェクト: nicolasdespres/youpy
def wait(delay):
    send_request(message.Wait(delay=delay))
コード例 #5
0
ファイル: control.py プロジェクト: youpy-org/youpy
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
ファイル: control.py プロジェクト: youpy-org/youpy
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"))