def call_function(self, name: str, *args): """Call scripting function defined in the global namespace.""" rv = sciter.Value() argc, argv, _ = sciter.Value.pack_args(*args) ok = _api.SciterCall(self.hwnd, name.encode('utf-8'), argc, argv, rv) sciter.Value.raise_from(rv, ok != False, name) return rv
def set_media_vars(self, media: dict): """Set media variables of this sciter instance.""" v = sciter.Value(media) ok = _api.SciterSetMediaVars(self.hwnd, v) if not ok: raise sciter.SciterError("Could not set media vars " + str(media)) return self
def pack_args(*args, **kwargs): """Pack arguments tuple as SCITER_VALUE array.""" argc = len(args) args_type = SCITER_VALUE * argc argv = args_type() for i, v in enumerate(args): sv = sciter.Value(v) sv.copy_to(argv[i]) this = value(kwargs.get('this')) return (argc, argv, this)
def eval_script(self, script: str, name=None): """Evaluate script in context of current document.""" rv = sciter.Value() ok = _api.SciterEval(self.hwnd, script, len(script), rv) sciter.Value.raise_from(rv, ok != False, name if name else 'Host.eval') return rv