1
- from IPython .display import HTML , display
2
-
3
1
_canvas = """
4
2
<script type="text/javascript" src="./js/canvas.js"></script>
5
3
<div>
@@ -25,7 +23,7 @@ def __init__(self, varname, id=None, width=800, height=600):
25
23
self .height = height
26
24
self .html = _canvas .format (self .id , self .width , self .height , self .name )
27
25
self .exec_list = []
28
- display ( HTML ( self .html ) )
26
+ display_html ( self .html )
29
27
30
28
def mouse_click (self , x , y ):
31
29
"Override this method to handle mouse click at position (x, y)"
@@ -115,10 +113,14 @@ def text_n(self, txt, xn, yn, fill=True):
115
113
116
114
def alert (self , message ):
117
115
"Immediately display an alert"
118
- display ( HTML ( '<script>alert("{0}")</script>' .format (message ) ))
116
+ display_html ( '<script>alert("{0}")</script>' .format (message ))
119
117
120
118
def update (self ):
121
119
"Execute the JS code to execute the commands queued by execute()"
122
120
exec_code = "<script>\n " + '\n ' .join (self .exec_list ) + "\n </script>"
123
121
self .exec_list = []
124
- display (HTML (exec_code ))
122
+ display_html (exec_code )
123
+
124
+ def display_html (html_string ):
125
+ from IPython .display import HTML , display
126
+ display (HTML (html_string ))
0 commit comments