This Engineering Notebook post discusses running Leo, *inside IPython*, on 
Windows. This project is part of #4105: 
<https://github.com/leo-editor/leo-editor/issues/4105> fix leoIPython.py.

This post is similar to a previous post 
<https://groups.google.com/g/leo-editor/c/l45hxNq_3ZI/m/RhiykT9NAAAJ>: 
Launching 
Leo when SageMath starts (Ubuntu). The code is similar, but there are 
twists. Note: I did all my work from within IPython.

*Running a custom startup script when IPython starts*

By default, IPython will run any Python scripts in the default profile's 
startup directory, found in *~/.ipython/profile_default/startup*.

I created *init.py* in that folder. This file contains:

# ~/.ipython/profile_default/startup/init.py
# IPython runs this code during startup.

import os
from subprocess import Popen

print('')
print('~/.ipython/profile_default/startup/init.py')

def load_leo():
print('loading leoPy.leo...')
command = 'ipython-init'
proc = Popen([command],
shell=True, stdin=None,
stdout=None, stderr=None, close_fds=True)

# Load leoPy.leo on startup?!?
# load_leo()

Because of strange problems relating to filenames, Popen doesn't execute 
Python code directly. Instead, it executes* ipython-init.cmd*:

@echo off
cd c:\Repos\leo-editor
python C:\Repos\leo-editor\launchLeo.py leo\core\leoPy.leo ^
--silent --no-splash --gui=qttabs

Now I run the ipython command from a console.

At any IPython prompt, entering load_leo() launches Leo *without blocking 
IPython.* As on Ubuntu, I must click the IPython console and hit return to 
see the IPython prompt.

*Summary*

It's easy to run any Python code while IPython starts.

Launching Leo from within IPython (on Windows) is similar to launching Leo 
from SageMath on Ubuntu.

An open question: how much of IPython can the "embedded" Leo access?

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/5ff711c6-3c7c-44b5-b3de-a19873bc2ae3n%40googlegroups.com.

Reply via email to