nengo / nengo-gui

Nengo interactive visualizer
Other
95 stars 38 forks source link

Add on_event functions #828

Open tcstewar opened 7 years ago

tcstewar commented 7 years ago

There have been a few cases where I've wished I could add event handlers to the GUI. For example, when doing a lot of robotics work, I've wanted to only connect to the robot once, and not have that code re-execute every time I type something in the GUI. As another example, I've wanted to run code after a simulation has run, so I could do things like save the current weights from a learning connection, or even just print the decoder errors for a function.

I think this could be done by adding a few special magic functions that you can define in your code. The ones that come to mind are:

I could also maybe see on_build() or on_build(sim) but I'm not sure if it should be before or after the build has happened. And maybe on_play(sim). And maybe on_quit(sim). But I'm not sure what the use cases for those would be.

jgosmann commented 7 years ago

I haven't spend much thought on this yet, but I'm probably on board with the general idea. An alternative approach comes to my mind where you would register functions to certain events, e.g. register('init', my_init_method). Haven't thought about the pros and cons of the two approaches at all though.