How to use the pscript.stubs.window.setTimeout function in pscript

To help you get started, we’ve selected a few pscript examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flexxui / flexx / flexx / app / _clientcore.py View on Github external
def _receive_command(self, command):
        """ Process a command send from the server.
        """
        cmd = command[0]
        if cmd == 'PING':
            # Used for roundtrip stuff, do at least one iter loop here ...
            window.setTimeout(self.send_command, 10, 'PONG', command[1])
        elif cmd == 'INIT_DONE':
            window.flexx.spin(None)
            while len(self._pending_commands):
                self._receive_raw_command(self._pending_commands.pop(0))
            self._pending_commands = None
            # print('init took', time() - self._init_time)
        elif cmd == 'PRINT':
            (window.console.ori_log or window.console.log)(command[1])
        elif cmd == 'EXEC':
            eval(command[1])
        elif cmd == 'EVAL':
            x = None
            if len(command) == 2:
                x = eval(command[1])
            elif len(command) == 3:
                x = eval('this.instances.' + command[1] + '.' + command[2])
github flexxui / flexx / flexxamples / demos / d3_collision.py View on Github external
def init(self):
        self.node.id = self.id
        window.setTimeout(self.load_viz, 500)
github flexxui / flexx / flexx / app / _clientcore.py View on Github external
def call_after_roundtrip(self, callback, *args):
        ping_to_schedule_at = self._ping_counter + 1
        if len(self._ping_calls) == 0 or self._ping_calls[-1][0] < ping_to_schedule_at:
            window.setTimeout(self._send_ping, 0)
        self._ping_calls.push((ping_to_schedule_at, callback, args))
github flexxui / flexx / flexx / app / _clientcore.py View on Github external
def _receive_pong(self, count):
        while len(self._ping_calls) > 0 and self._ping_calls[0][0] <= count:
            _, callback, args = self._ping_calls.pop(0)
            window.setTimeout(callback, 0, *args)
github flexxui / flexx / flexx / app / _clientcore.py View on Github external
def _process_commands(self):
        """ A less direct way to process commands, which gives the
        browser time to draw about every other JS asset. This is a
        tradeoff between a smooth spinner and fast load time.
        """
        while self._pending_commands is not None and len(self._pending_commands) > 0:
            msg = self._pending_commands.pop(0)
            try:
                command = self._receive_raw_command(msg)
            except Exception as err:
                window.setTimeout(self._process_commands, 0)
                raise err
            if command[0] == 'DEFINE':
                self._asset_count += 1
                if (self._asset_count % 3) == 0:
                    if len(self._pending_commands):
                        window.setTimeout(self._process_commands, 0)
                    break
github flexxui / flexx / flexx / app / _clientcore.py View on Github external
def on_ws_message(evt):
            msg = evt.data  # bsdf-encoded command
            if not msg:
                pass  # ? drop glitchy message :/
            elif self._pending_commands is None:
                # Direct mode
                self._receive_raw_command(msg)
            else:
                # Indirect mode, to give browser draw-time during loading
                if len(self._pending_commands) == 0:
                    window.setTimeout(self._process_commands, 0)
                self._pending_commands.push(msg)
        def on_ws_close(evt):