Skip to content

Commit

Permalink
Added hooks: on_pause, on_continue, on_start, on_close
Browse files Browse the repository at this point in the history
  • Loading branch information
tcstewar committed Jun 9, 2019
1 parent 627d191 commit 8445961
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions nengo_gui/components/sim_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,18 @@ def javascript(self):
def message(self, msg):
if msg == 'pause':
self.paused = True
if 'on_pause' in self.page.locals:
self.page.locals['on_pause'](self.page.sim)
elif msg == 'config':
self.send_config_options = True
elif msg == 'continue':
if self.page.sim is None:
self.page.rebuild = True
if 'on_start' in self.page.locals:
self.page.locals['on_start'](self.page.sim)
else:
if 'on_continue' in self.page.locals:
self.page.locals['on_continue'](self.page.sim)
self.paused = False
elif msg == 'reset':
self.paused = True
Expand Down
1 change: 1 addition & 0 deletions nengo_gui/guibackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ def create_page(self, filename, reset_cfg=False):

def remove_page(self, page):
self._last_access = time.time()
page.close()
self.pages.remove(page)
if (not self._shutting_down and self.settings.auto_shutdown > 0 and
len(self.pages) <= 0):
Expand Down
10 changes: 9 additions & 1 deletion nengo_gui/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,16 @@ def runner(self):
self.error = dict(trace=traceback.format_exc(), line=line)
self.sim = None
while self.sims_to_close:
self.sims_to_close.pop().close()
s = self.sims_to_close.pop()
if 'on_close' in self.locals:
self.locals['on_close'](s)
s.close()

if self.rebuild:
self.build()
self.sim = None

def close(self):
if self.sim is not None:
if 'on_close' in self.locals:
self.locals['on_close'](self.sim)

0 comments on commit 8445961

Please sign in to comment.