@@ -623,6 +623,14 @@ def _instance(self):
623623
624624 self .client = clients [self .session ]
625625
626+ if not hasattr (self .client , 'page' ):
627+ head = gui .HEAD (self .server .title , self .client .js_head + '\n ' + self .client .js_body_end , self .client .css_head , self .client .html_head )
628+ body = gui .BODY ()
629+ body .disable_refresh ()
630+ self .client .page = gui .HTML ()
631+ self .client .page .add_child ('head' , head )
632+ self .client .page .add_child ('body' , body )
633+
626634 if not hasattr (clients [self .session ], 'websockets' ):
627635 clients [self .session ].websockets = []
628636
@@ -689,6 +697,7 @@ def websocket_handshake_done(self, ws_instance_to_update):
689697 ws_instance_to_update .send_message (msg )
690698
691699 def set_root_widget (self , widget ):
700+ self .page .children ['body' ].append (widget , 'root' )
692701 self .root = widget
693702 self .root .disable_refresh ()
694703 self .root .attributes ['data-parent-widget' ] = str (id (self ))
@@ -819,7 +828,7 @@ def do_GET(self):
819828 # build the page (call main()) in user code, if not built yet
820829 with self .update_lock :
821830 # build the root page once if necessary
822- if not hasattr ( self . client , 'root' ) or self .client .root is None :
831+ if not 'root' in self .client .page . children [ 'body' ]. children . keys () :
823832 self ._log .info ('built UI (path=%s)' % path )
824833 self .client .set_root_widget (self .main (* self .server .userdata ))
825834 self ._process_all (path )
@@ -846,14 +855,6 @@ def _process_all(self, func):
846855 self .send_header ('Content-type' , 'text/html' )
847856 self .end_headers ()
848857
849- #WARNING !!! MUTUAL/CIRCUAL import???
850- self .client .head = gui .HEAD (self .server .title , self .client .js_head + '\n ' + self .client .js_body_end , self .client .css_head , self .client .html_head )
851- self .client .body = gui .BODY ()
852- self .client .body .append (self .client .root )
853- self .client .page = gui .HTML ()
854- self .client .page .add_child ('head' , self .client .head )
855- self .client .page .add_child ('body' , self .client .body )
856-
857858 with self .update_lock :
858859 # render the HTML
859860 page_content = self .client .page .repr ()
0 commit comments