How to use the pscript.stubs.window.flexx 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
#and command[1] == 'JS' or command[1] == 'DEFINE-JS-EVAL '):
            kind, name, code = command[1:]
            window.flexx.spin()
            address = window.location.protocol + '//' + self.ws_url.split('/')[2]
            code += '\n//# sourceURL=%s/flexx/assets/shared/%s\n' % (address, name)
            if kind == 'JS-EVAL':
                eval(code)
            elif kind == 'JS':
                # With this method, sourceURL does not work on Firefox,
                # but eval might not work for assets that don't "use strict"
                # (e.g. Bokeh). Note, btw, that creating links to assets does
                # not work because these won't be loaded on time.
                el = window.document.createElement("script")
                el.id = name
                el.innerHTML = code
                window.flexx.asset_node.appendChild(el)
            elif kind == 'CSS':
                el = window.document.createElement("style")
                el.type = "text/css"
                el.id = name
                el.innerHTML = code
                window.flexx.asset_node.appendChild(el)
            else:
                window.console.error('Dont know how to DEFINE ' +
                                     name + ' with "' + kind + '".')
        elif cmd == 'OPEN':
            window.win1 = window.open(command[1], 'new', 'chrome')
        else:
            window.console.error('Invalid command: "' + cmd + '"')
        return command
github flexxui / flexx / flexx / app / _clientcore.py View on Github external
def __init__(self):

        if window.flexx.init:
            raise RuntimeError('Should not create global Flexx object more than once.')

        # Init (overloadable) variables. These can be set by creating
        # a window.flexx object *before* instantiating this class, or by
        # setting them on this object before the init() is called.
        self.is_notebook = False
        self.is_exported = False

        # Copy attributes from temporary object (e.g. is_notebook, require, ...)
        for key in window.flexx.keys():
            self[key] = window.flexx[key]

        # We need a global main widget (shared between sessions)
        self.need_main_widget = True  # Used/set in ui/_widget.py

        # Keep track of sessions
github flexxui / flexx / flexx / app / _clientcore.py View on Github external
ob[name](*args)
        elif cmd == 'INSTANTIATE':
            self.instantiate_component(*command[1:])  # module, cname, id, args, kwargs
        elif cmd == 'DISPOSE':
            id = command[1]
            c = self.instances.get(id, None)
            if c is not None and c._disposed is False:  # else: no need to warn
                c._dispose()
            self.send_command('DISPOSE_ACK', command[1])
            self.instances.pop(id, None)  # Drop local reference now
        elif cmd == 'DISPOSE_ACK':
            self.instances.pop(command[1], None)  # Drop reference
        elif cmd == 'DEFINE':
            #and command[1] == 'JS' or command[1] == 'DEFINE-JS-EVAL '):
            kind, name, code = command[1:]
            window.flexx.spin()
            address = window.location.protocol + '//' + self.ws_url.split('/')[2]
            code += '\n//# sourceURL=%s/flexx/assets/shared/%s\n' % (address, name)
            if kind == 'JS-EVAL':
                eval(code)
            elif kind == 'JS':
                # With this method, sourceURL does not work on Firefox,
                # but eval might not work for assets that don't "use strict"
                # (e.g. Bokeh). Note, btw, that creating links to assets does
                # not work because these won't be loaded on time.
                el = window.document.createElement("script")
                el.id = name
                el.innerHTML = code
                window.flexx.asset_node.appendChild(el)
            elif kind == 'CSS':
                el = window.document.createElement("style")
                el.type = "text/css"
github flexxui / flexx / flexx / app / _clientcore.py View on Github external
def __init__(self):

        if window.flexx.init:
            raise RuntimeError('Should not create global Flexx object more than once.')

        # Init (overloadable) variables. These can be set by creating
        # a window.flexx object *before* instantiating this class, or by
        # setting them on this object before the init() is called.
        self.is_notebook = False
        self.is_exported = False

        # Copy attributes from temporary object (e.g. is_notebook, require, ...)
        for key in window.flexx.keys():
            self[key] = window.flexx[key]

        # We need a global main widget (shared between sessions)
        self.need_main_widget = True  # Used/set in ui/_widget.py

        # Keep track of sessions
        self._session_count = 0
        self.sessions = {}

        # Note: flexx.init() is not auto-called when Flexx is embedded
        window.addEventListener('load', self.init, False)
        window.addEventListener('unload', self.exit, False)  # not beforeunload
github flexxui / flexx / flexx / app / _clientcore.py View on Github external
def on_ws_close(evt):
            self._ws = None
            self.status = 0
            msg = 'Lost connection with server'
            if evt and evt.reason:
                msg += ': %s (%i)' % (evt.reason, evt.code)
            if not window.flexx.is_notebook:
                # todo: show modal or cooky-like dialog instead of killing whole page
                window.document.body.textContent = msg
            else:
                window.console.info(msg)
        def on_ws_error(self, evt):
github flexxui / flexx / flexx / app / _clientcore.py View on Github external
else:
            self.instances_to_check_size.pop(ob.id, None)

    def _check_size_of_objects(self):
        for ob in self.instances_to_check_size.values():
            if ob._disposed is False:
                ob.check_real_size()


# In Python, we need some extras for the serializer to work
if this_is_js():
    # Include bsdf.js
    window.flexx = Flexx()
    bsdf = RawJS("flexx.require('bsdf')")
    serializer = bsdf.BsdfSerializer()
    window.flexx.serializer = serializer
else:
    # Import vendored bsdf lite module
    from . import bsdf_lite as bsdf
    serializer = bsdf.BsdfLiteSerializer()
    serializer.__module__ = __name__
github flexxui / flexx / flexx / app / _clientcore.py View on Github external
self.id = config.flexx_session_id
                    self.app_name = config.flexx_app_name
                except Exception as err:
                    print(err)

        # Init internal variables
        self._init_time = time()
        self._pending_commands = []  # to pend raw commands during init
        self._asset_count = 0
        self._ws = None
        self.last_msg = None
        # self.classes = {}
        self.instances = {}
        self.instances_to_check_size = {}

        if not window.flexx.is_exported:
            self.init_socket()

        # Initiate service to track resize
        # Note that only toplevel widgets are tracked, and only once per sec
        window.addEventListener('resize', self._check_size_of_objects, False)
        window.setInterval(self._check_size_of_objects, 1000)
github flexxui / flexx / flexx / app / _clientcore.py View on Github external
# in any case, at least once each second.
        if check:
            self.instances_to_check_size[ob.id] = ob
        else:
            self.instances_to_check_size.pop(ob.id, None)

    def _check_size_of_objects(self):
        for ob in self.instances_to_check_size.values():
            if ob._disposed is False:
                ob.check_real_size()


# In Python, we need some extras for the serializer to work
if this_is_js():
    # Include bsdf.js
    window.flexx = Flexx()
    bsdf = RawJS("flexx.require('bsdf')")
    serializer = bsdf.BsdfSerializer()
    window.flexx.serializer = serializer
else:
    # Import vendored bsdf lite module
    from . import bsdf_lite as bsdf
    serializer = bsdf.BsdfLiteSerializer()
    serializer.__module__ = __name__