Hi, is there any way “smart” way of checking if the current nengo .py
script is being run in the GUI or not?
I’ve looked through the GUI source code but don’t see an obvious way to do this.
I’m not sure if there’s a supported way of doing this, but an unsupported way would be to check:
__name__ == 'builtins'
I’m not sure how robust this is, but I tested it out on nengo-gui==0.4.6
and this is True
if the current script is being run in the GUI, and False
if being run as a python
script from the command line.
I’ve also used:
from nengo.simulator import Simulator as NengoSimulator
if nengo.Simulator is not NengoSimulator:
...
elif __name__ == "__main__":
...
Here’s yet another way:
if '__page__' in locals():
Here’s the part of the nengo_gui
code which initializes locals
when executing the code
We set the __file__
variable here, and we also create this other variable __page__
which refers to the nengo_gui.page.Page
object that’s running that page.
It’d still be nicer to have a better way to do that… something like a nengo_gui.is_running_in_ui
flag that could be checked… But we don’t have anything like that yet.