Issue #1425. Settings > Open A Theme File can look like it's not working. The Leo session that spawns the Leo-with-themefile locks and says "Not
Responding" in the title bar until the Leo-with-themefile session is
closed. Read the issue for more context. This is an ENB as I work towards resolution,
...
As currently written this menu command, defined in ../commands/commanderFileCommands.py-->Themes-->c_file.open_theme_file, will only work in Leo source code checkouts. That is, it's broken for anyone who installs from Pypi.org, from pip in a non-editable mode, or some other deployment mode that works similarly.
The problem part:
command = f'python launchLeo.py "{fn}"'
os.system(command)
launchLeo.py doesn't exist outside a source code repo. In a pip deployment Leo is launched with PYTHONHOME/Scripts/leo. Others use their own launch wrapper somewhere else.
A few different fixes suggest themselves:
leolaunchLeo.py as a python -c '...{py code}...' command line expression. (It's short enough that this is practical)I don't like 1 & 3 much. I do like 2 but don't know yet how much work it will be. Well, time to start learning!
Along the way, we might as well replace os.command with a current recommended method as "The subprocess module provides more powerful facilities for spawning
new processes and retrieving their results; using that module is preferable
to using this function. See the Replacing Older Functions with the subprocess Module section in
the subprocess documentation for some helpful recipes." (ref)
-matt
# name of the script we're running in
import inspect
g.es_print(inspect.getfile(inspect.currentframe()))
command = f'python launchLeo.py "{fn}"'
os.system(command)
#command = f'python launchLeo.py "{fn}"'
#os.system(command)
import sys
command = f'{sys.executable} {g.app.loadDir}/runLeo.py "{fn}"'
#g.es_print(command)
import subprocess
subprocess.Popen(command)
We could test if sys.argv[0] ends with .py and insert sys.executable if yes, otherwise use as is.
# fix idea 2:
if g.sys.argv[0].endswith('.py'):
command = f'{g.sys.executable} {g.sys.argv[0]} "{fn}"'
else:
command = f'{g.sys.argv[0]} "{fn}"'
g.es_print(command)
g.subprocess.Popen(command)
# fix idea 1:
command = f'{g.sys.executable} {g.app.loadDir}/runLeo.py "{fn}"'
g.es_print(command)
g.subprocess.Popen(command)
016867f.At the moment I much prefer the simple and direct version.
What I still need to learn: how to write and run Leo unit tests.