How to use the pscript.window 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 / ui / _widget.py View on Github external
vsubnode = vnode.children[i2]
                subnode = None
                if i1 < len(node.childNodes):
                    subnode = node.childNodes[i1]
                    if subnode.nodeName == "#text" and isinstance(vsubnode, str):
                        if subnode.data != vsubnode:
                            subnode.data = vsubnode
                        continue  # early exit for text nodes
                new_subnode = self.__render_resolve(vsubnode, subnode)
                if subnode is None:
                    node.appendChild(new_subnode)
                elif subnode is not new_subnode:
                    node.insertBefore(new_subnode, subnode)
                    node.removeChild(subnode)
        else:
            window.flexx_vnode = vnode
            raise TypeError('Widget._render_dom() '
                            'needs virtual node children to be None or list, not %s' %
                            vnode.children)

        return node
github flexxui / flexx / flexx / ui / widgets / _dropdown.py View on Github external
def _expand(self):
        rect = super()._expand()
        ul = self.outernode.children[len(self.outernode.children) - 1]
        ul.style.left = rect.left + 'px'
        ul.style.width = rect.width + 'px'
        ul.style.top = (rect.bottom - 1) + 'px'
        # Correct position (above, below) as needed
        space_below = window.innerHeight - rect.bottom
        if space_below < ul.clientHeight:
            space_above = rect.top
            if space_above > space_below:
                ul.style.top = (rect.top - 1 - ul.clientHeight) + 'px'
github flexxui / flexx / flexx / ui / widgets / _plotwidget.py View on Github external
if tick_unit * scale >= min_tick_dist:
                break
        else:
            return []
        # Calculate tick values
        first_tick = window.Math.ceil(t1 / tick_unit) * tick_unit
        last_tick = window.Math.floor(t2 / tick_unit) * tick_unit
        ticks = []
        t = first_tick
        while t <= last_tick:
            ticks.append(t)
            t += tick_unit
        for i in range(len(ticks)):
            t = ticks[i].toPrecision(4)
            if '.' in t:
                t = t.replace(window.RegExp("[0]+$"), "")
            if t[-1] == '.':
                t += '0'
            ticks[i] = t

        return ticks
github flexxui / flexx / flexx / ui / _widget.py View on Github external
id = self.container
        self.outernode.classList.remove('flx-main-widget')
        if self.parent:
            return

        # Let session keep us up to date about size changes
        # (or make it stop if we dont have a container anymore)
        self._session.keep_checking_size_of(self, bool(id))

        if id:
            if id == 'body':
                el = window.document.body
                self.outernode.classList.add('flx-main-widget')
                window.document.title = self.title or 'Flexx app'
            else:
                el = window.document.getElementById(id)
                if el is None:  # Try again later
                    window.setTimeout(self.__container_changed, 100)
                    return
            el.appendChild(self.outernode)
github flexxui / flexx / flexx / ui / _widget.py View on Github external
# Init this component (e.g. create properties and actions)
        super().__init__(*init_args, **kwargs)

        # Some further initialization ...
        # Note that the _comp_init_property_values() will get called first.

        # Attach this widget in the widget hierarchy, if we can
        if parent_given is True:
            self.set_parent(given_parent)
        elif parent is not None:
            self.set_parent(parent)
        elif self.container == '':
            # Determine whether this should be the main widget. If the browser
            # seems to need one, and this is the first "orphan" widget to be
            # instantiated, this widget will take on this role.
            if window.flexx.need_main_widget:
                window.flexx.need_main_widget = False
                self.set_container('body')

        # Apply widget-specific default minsize if minsize is not given
        if kwargs.get('minsize', None) is None:
            self.set_minsize(self.DEFAULT_MIN_SIZE)

        # Apply style if given (can override minsize)
        if style:
            self.apply_style(style)
github flexxui / flexx / flexx / ui / _widget.py View on Github external
def mup_outside(e):
            # emit mouse up event, and stop capturing
            if self._capture_flag == 2:
                e = window.event if window.event else e
                stopcapture()
                self.pointer_up(e)
github flexxui / flexx / flexx / ui / widgets / _plotwidget.py View on Github external
def update(self, *events):
        window.requestAnimationFrame(self._update)