Open tcstewar opened 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.
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:
def on_init():
(called when you first open a file in the GUI, and only called once. If you change the contents of the function, you'll need to reload the page to get it to re-execute)def on_pause(sim):
(called whenever you pause the simulation, and gets the sim object passed in)I could also maybe see
on_build()
oron_build(sim)
but I'm not sure if it should be before or after the build has happened. And maybeon_play(sim)
. And maybeon_quit(sim)
. But I'm not sure what the use cases for those would be.