diff --git a/nengo_gui/components/htmlview.py b/nengo_gui/components/htmlview.py
index b7486c79..c609e68e 100644
--- a/nengo_gui/components/htmlview.py
+++ b/nengo_gui/components/htmlview.py
@@ -1,5 +1,7 @@
import collections
+import nengo
+
from nengo_gui.components.component import Component
@@ -10,31 +12,50 @@ class HTMLView(Component):
def __init__(self, obj):
super(HTMLView, self).__init__()
- self.obj = obj
- self.obj_output = obj.output
self.data = collections.deque()
+ self.obj = obj
+ self.obj_output = self.obj.output
+ self.callable_html = callable(obj.output._nengo_html_)
+ if self.callable_html:
+ assert self.obj.size_out > 0
+ else:
+ assert callable(self.obj_output)
+
def attach(self, page, config, uid):
super(HTMLView, self).attach(page, config, uid)
self.label = page.get_label(self.obj)
def add_nengo_objects(self, page):
- with page.model:
+ if self.callable_html:
+ with page.model:
+ self.node = nengo.Node(
+ self.gather_data, size_in=self.obj.size_out)
+ self.conn = nengo.Connection(self.obj, self.node, synapse=None)
+ else:
self.obj.output = self.gather_data
def remove_nengo_objects(self, page):
- self.obj.output = self.obj_output
+ if self.callable_html:
+ page.model.connections.remove(self.conn)
+ page.model.nodes.remove(self.node)
+ else:
+ self.obj.output = self.obj_output
def gather_data(self, t, *x):
- value = self.obj_output(t, *x)
- data = '%g %s' % (t, self.obj_output._nengo_html_)
- self.data.append(data)
+ if self.callable_html:
+ value = None
+ html = self.obj_output._nengo_html_(t, *x)
+ else:
+ value = self.obj_output(t, *x)
+ html = self.obj_output._nengo_html_
+
+ self.data.append('%g %s' % (t, html))
return value
def update_client(self, client):
while len(self.data) > 0:
- item = self.data.popleft()
- client.write_text(item)
+ client.write_text(self.data.popleft())
def javascript(self):
info = dict(uid=id(self), label=self.label)
diff --git a/nengo_gui/components/netgraph.py b/nengo_gui/components/netgraph.py
index efebcbf2..d486d50a 100644
--- a/nengo_gui/components/netgraph.py
+++ b/nengo_gui/components/netgraph.py
@@ -532,7 +532,7 @@ def get_extra_info(self, obj):
isinstance(obj.output, OverriddenOutput)
and obj.output.base_output is None):
info['passthrough'] = True
- if callable(obj.output) and hasattr(obj.output, '_nengo_html_'):
+ if hasattr(obj.output, '_nengo_html_'):
info['html'] = True
info['dimensions'] = int(obj.size_out)
elif isinstance(obj, nengo.Ensemble):