Skip to content

Commit

Permalink
User can provide custom function for HTML display
Browse files Browse the repository at this point in the history
Also allows Processes to define custom HTML for viewing.
  • Loading branch information
hunse committed Jun 6, 2016
1 parent 9c0e2f4 commit 417ec75
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions nengo_gui/components/htmlview.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import collections

import nengo

from nengo_gui.components.component import Component


Expand All @@ -11,30 +13,31 @@ class HTMLView(Component):
def __init__(self, obj):
super(HTMLView, self).__init__()
self.obj = obj
self.obj_output = obj.output
self.data = collections.deque()
self.html_function = getattr(obj.output, '_nengo_html_function_')

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:
self.obj.output = self.gather_data
self.node = nengo.Node(self.gather_data, size_in=self.obj.size_out)
self.conn = nengo.Connection(self.obj, self.node, synapse=None)

def remove_nengo_objects(self, page):
self.obj.output = self.obj_output
page.model.connections.remove(self.conn)
page.model.nodes.remove(self.node)

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)
return value
def gather_data(self, t, x):
self.data.append((t, x))

def update_client(self, client):
while len(self.data) > 0:
item = self.data.popleft()
client.write(item)
t, x = self.data.popleft()
html = self.html_function(t, x)
out = '%g %s' % (t, html)
client.write(out)

def javascript(self):
info = dict(uid=id(self), label=self.label)
Expand Down
2 changes: 1 addition & 1 deletion nengo_gui/components/netgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_function_'):
info['html'] = True
info['dimensions'] = int(obj.size_out)
elif isinstance(obj, nengo.Ensemble):
Expand Down

0 comments on commit 417ec75

Please sign in to comment.