#NEWLINE# def visit_uiexample_html( self , node ) : #NEWLINE# #INDENT# global should_export_flexx_deps #NEWLINE# if ( not hasattr ( node , 'code' ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# code = ori_code = ( node . code . strip ( ) + '\n' ) #NEWLINE# ori_code = '\n' . join ( [ ( ( ' ' * 8 ) + x ) for x in ori_code . splitlines ( ) ] ) #NEWLINE# if ( 'import' not in code ) : #NEWLINE# #INDENT# code = ( SIMPLE_CODE_T + '\n        ' . join ( [ line for line in code . splitlines ( ) ] ) ) #NEWLINE# #UNINDENT# this_id = hashlib . md5 ( code . encode ( 'utf-8' ) ) . hexdigest ( ) #NEWLINE# fname = ( 'example%s.html' % this_id ) #NEWLINE# filename_html = os . path . join ( HTML_DIR , 'ui' , 'examples' , fname ) #NEWLINE# filename_py = os . path . join ( HTML_DIR , 'ui' , 'examples' , ( 'example%s.py' % this_id ) ) #NEWLINE# code += '\n\n' #NEWLINE# if ( 'class MyApp' in code ) : #NEWLINE# #INDENT# code += 'App = MyApp\n' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'class Example' in code ) : #NEWLINE# #INDENT# code += 'App = Example\n' #NEWLINE# #UNINDENT# #UNINDENT# if ( not ( 'app' in code ) ) : #NEWLINE# #INDENT# code += 'from flexx import app\n' #NEWLINE# #UNINDENT# code += ( 'app.export(App, %r, False)\n' % filename_html ) #NEWLINE# open ( filename_py , 'wt' , encoding = 'utf-8' ) . write ( code ) #NEWLINE# try : #NEWLINE# #INDENT# __import__ ( ( 'example%s' % this_id ) ) #NEWLINE# #UNINDENT# except ImportError as err : #NEWLINE# #INDENT# err_text = str ( err ) #NEWLINE# msg = ( 'Example not generated. <pre>%s</pre>' % err_text ) #NEWLINE# if os . environ . get ( 'READTHEDOCS' , False ) : #NEWLINE# #INDENT# node . height = 60 #NEWLINE# msg = ( 'This example is not build on read-the-docs. <pre>%s</pre>' % err_text ) #NEWLINE# #UNINDENT# open ( filename_html , 'wt' , encoding = 'utf-8' ) . write ( msg ) #NEWLINE# warnings . warn ( ( 'Ui example dependency not met: %s' % err_text ) ) #NEWLINE# #UNINDENT# except Exception as err : #NEWLINE# #INDENT# err_text = str ( err ) #NEWLINE# msg = ( 'Example not generated. <pre>%s</pre>' % err_text ) #NEWLINE# open ( filename_html , 'wt' , encoding = 'utf-8' ) . write ( msg . replace ( '\\n' , '<br />' ) ) #NEWLINE# raise RuntimeError ( ( 'Could not create ui example: %s\n%s' % ( err_text , ori_code ) ) ) #NEWLINE# #UNINDENT# rel_path = ( '../ui/examples/' + fname ) #NEWLINE# astyle = 'font-size:small; float:right;' #NEWLINE# dstyle = 'width: 500px; height: %ipx; align: center; resize:both; overflow: hidden; box-shadow: 5px 5px 5px #777;' #NEWLINE# istyle = 'width: 100%; height: 100%; border: 2px solid #094;' #NEWLINE# self . body . append ( ( "<a target='new' href='%s' style='%s'>open in new tab</a>" % ( rel_path , astyle ) ) ) #NEWLINE# self . body . append ( ( ( "<div style='%s'>" % fname ) % node . height ) ) #NEWLINE# self . body . append ( ( "<iframe src='%s' style='%s'>iframe not supported</iframe>" % ( rel_path , istyle ) ) ) #NEWLINE# self . body . append ( '</div>' ) #NEWLINE# self . body . append ( '<br />' )