Skip to content

Commit e3ce769

Browse files
committed
Allow tests to run without IPython. Closes aimacode#226.
1 parent 1d278f6 commit e3ce769

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

canvas.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from IPython.display import HTML, display
2-
31
_canvas = """
42
<script type="text/javascript" src="./js/canvas.js"></script>
53
<div>
@@ -25,7 +23,7 @@ def __init__(self, varname, id=None, width=800, height=600):
2523
self.height = height
2624
self.html = _canvas.format(self.id, self.width, self.height, self.name)
2725
self.exec_list = []
28-
display(HTML(self.html))
26+
display_html(self.html)
2927

3028
def mouse_click(self, x, y):
3129
"Override this method to handle mouse click at position (x, y)"
@@ -115,10 +113,14 @@ def text_n(self, txt, xn, yn, fill=True):
115113

116114
def alert(self, message):
117115
"Immediately display an alert"
118-
display(HTML('<script>alert("{0}")</script>'.format(message)))
116+
display_html('<script>alert("{0}")</script>'.format(message))
119117

120118
def update(self):
121119
"Execute the JS code to execute the commands queued by execute()"
122120
exec_code = "<script>\n" + '\n'.join(self.exec_list) + "\n</script>"
123121
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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy