Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added static option to HTML component #776

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions nengo_gui/components/htmlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@
class HTMLView(Component):
"""Arbitrary HTML display taking input from a Node

See nengo_gui/examples/basics/html.py for example usage"""
See nengo_gui/examples/basics/html.py for example usage.

The HTML is given by a string, stored in the attribute ``_nengo_html_``
on the output function of the nengo Node. To make the HTML static
(served once instead of every timestep), add the attribute
``_nengo_static_`` to the node's output function.
"""

def __init__(self, obj):
super(HTMLView, self).__init__()
self.obj = obj
self.obj_output = obj.output
self.data = collections.deque()
self.is_static = hasattr(self.obj_output, '_nengo_static_')
if self.is_static:
self.data.append('%g %s' % (0, self.obj_output._nengo_html_))

def attach(self, page, config, uid):
super(HTMLView, self).attach(page, config, uid)
Expand All @@ -27,8 +36,9 @@ def remove_nengo_objects(self, page):

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 not self.is_static:
data = '%g %s' % (t, self.obj_output._nengo_html_)
self.data.append(data)
return value

def update_client(self, client):
Expand Down