Open hunse opened 10 years ago
I was also thinking that it would also be good to include a section like:
if __name__ == '__main__':
sim = nengo.Simulator(model)
sim.run(1.0) # Run time, in seconds
assuming that __name__ != '__main__'
in nengo_gui
. The nengo_gui
stuff could be in else
of that maybe? With the auto generated comment.
+1 for being able to execute different code when the model is run as script or when it is run in the GUI.
That seems like a good idea. I don't like autogenerating the simulation section that people will later modify, though.
What would the __name__
be in nengo_gui? We should use that to determine whether to run the GUI code.
My plan had been that the nengo_gui just ignores everything past the first *.Simulator() call. Probably by monkey-patching in a version of nengo.Simulator (and nengo_ocl.Simulator and neurogrid.Simulator and so on) that raises an Exception. But not quite sure about that.
GUI code could be put in a special section thatnotes that it's auto generated. This code could also be hidden when opening the file in the GUI.