def __init__(self, app_name, id, ws_url=None): self.app = None # the root component (can be a PyComponent) self.app_name = app_name self.id = id self.status = 1 self.ws_url = ws_url self._component_counter = 0 self._disposed_ob = {'_disposed': True} # Maybe this is JLab if not self.id: jconfig = window.document.getElementById('jupyter-config-data') if jconfig: try: config = JSON.parse(jconfig.innerText) 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)
func=func, next_time=now_secs + interval) def _check_long_timers(): now_secs = window.Date().getTime() / 1000 for name, ob in _long_timers.items(): if ob.next_time < now_secs: try: ob.func() except Exception as err: console.warn(err) ob.next_time = now_secs + ob.interval window.setInterval(_check_long_timers, 10 * 1000) # 10 s document.addEventListener("visibilitychange", _check_long_timers, False) # %% Connecting with server def build_api_url(suffix): if "/app/" in location.pathname: rootpath = location.pathname.split("/app/")[0] else: rootpath = location.pathname.rpartition("/")[0] url = location.protocol + "//" + location.hostname + ":" + location.port url = url.rstrip(":") + rootpath + "/api/v2/" return url + suffix