If one has a script that contains a block like this:
if __name__ == "__main__":
...
Trying to run this script from the etsdemo application by pressing the 'Run' button will not run that block, which is unexpected.
To reproduce, create a file like this:
if __name__ == "__main__":
print("Hello")
Then run this:
from etsdemo.main import main
main(
[
{
"version": 1,
"name": "Some name",
"root": ".", # or a path to a directory that contains the above test file.
},
]
)
That block is not run when one presses the 'Run' button.

But if one changes the "__main__" to "___main___" (three underscores), then it would run:

From the snapshot of an old version of the application, this ___main___ is not a typo: It looks deliberate.
https://github.com/enthought/traitsui/blob/96f45ff9c51ff55b5724cbed2361b933f468c183/enthought/traits/ui/extras/demo.py
Looks like the run_code method is serving two purposes:
(1) When the file is clicked, it loads the file to find this specially named variable 'demo'.
(2) When the Run button is clicked, it runs the file too.
For the first purpose, we don't want the block in if __name__ == "__main__" to run. For the second purpose, we do.
If one has a script that contains a block like this:
Trying to run this script from the
etsdemoapplication by pressing the 'Run' button will not run that block, which is unexpected.To reproduce, create a file like this:
Then run this:
That block is not run when one presses the 'Run' button.

But if one changes the

"__main__"to"___main___"(three underscores), then it would run:From the snapshot of an old version of the application, this
___main___is not a typo: It looks deliberate.https://github.com/enthought/traitsui/blob/96f45ff9c51ff55b5724cbed2361b933f468c183/enthought/traits/ui/extras/demo.py
Looks like the
run_codemethod is serving two purposes:(1) When the file is clicked, it loads the file to find this specially named variable 'demo'.
(2) When the Run button is clicked, it runs the file too.
For the first purpose, we don't want the block in
if __name__ == "__main__"to run. For the second purpose, we do.