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))
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))
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)
def wait(delay): send_request(message.Wait(delay=delay))
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))
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))
def __delattr__(self, name): try: send_request(message.SharedVariableDel(name)) except KeyError: raise AttributeError(f"undefined shared variable '{name}'")
def __iadd__(self, other): send_request( message.SharedVariableOp(name=self._name, op="__iadd__", args=(other, ))) return self
def show(self): return send_request( message.SharedVariableOp(name=self._name, op="show"))
def hide(self): return send_request( message.SharedVariableOp(name=self._name, op="hide"))