​​On Mon, Aug 5, 2019 at 1:27 PM Edward K. Ream <[email protected]> wrote:

> There is no need for the "let's pretend it's easy principle", because 
everything is easy :-) 

*Leo's pyzo_file_browser plugin now puts pyzo's standard file browser​ in a 
Leo dock!* This is a big milestone.

You can show/hide this dock by alt-clicking in the title area of any dock.

*Warning*

​At present the dock widget will crash if try to open any file, because the 
plugin only inits the required parts of pyzo. If you try to open a file you 
will be executing pyzo's open-file logic, which, naturally enough, assumes 
a full nit.  I have disabled pyzo's exception handling, so Leo crashes and 
burns.  Don't play with this plugin unless you can live with this.

*Adapting the file browser to Leo*

The plugin need only override pyzoFileBrowser.PyzoFileBrowser.  I expect 
considerable work, but localized and fairly straightforward.

*Summary*

1. Leo can use almost all of pyzo's code from leo/external/pyzo *unchanged*.  
This is the holy grail.  See the post script for details.

2. When enabled, the plugin creates pyzo's standard file browser in a Leo 
dock, without starting pyzo. This is, by far, the hardest part of the 
project.

3. It should be straightforward to integrate the file browser fully into 
Leo.  Until, *don't enable the plugin unless you are prepared to have Leo 
quit unexpectedly.*

Edward

P.S. Here are the code level details:

*A code breakthrough*

In pyzo's original code, these lines appear in pyzo/__main__.py

thisDir = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.split(thisDir)[0])

This ensures that all of pyzo's relative imports will work correctly.  The 
following lines do the same for the plugin:

pyzo_dir = g.os_path_finalize_join(g.app.loadDir, '..', 'external')
sys.path.insert(0, pyzo_dir)

This ensures that all the relative imports in leo/external/plugins work as 
expected.  This is a *huge* breakthrough, because it means that Leo can use 
99.9% of the code in leo/external/pyzo without changes!

*Imports*

Even after this breakthrough, several hours of work were needed to init* 
only the necessary parts* of pyzo.  Here are the imports in the 
pyzo_file_browser plugin:

# 0. Crucial.
pyzo_dir = g.os_path_finalize_join(g.app.loadDir, '..', 'external')
assert g.os_path_exists(pyzo_dir), repr(pyzo_dir)
sys.path.insert(0, pyzo_dir)
# 1. Must be first.
import pyzo
assert pyzo
# 2. Must be next.
import pyzo.core.main as main
main.loadIcons()
main.loadFonts()
from pyzo.core import menu
assert menu
# 3. All other imports:
from pyzo.tools.pyzoFileBrowser import PyzoFileBrowser
assert PyzoFileBrowser
# 4. Instantiate tool manager
from pyzo.tools import ToolManager
    # tools/__init__.py defines ToolManager.
pyzo.toolManager = ToolManager()
    # From mainWindow._populate.​

These imports roughly correspond to the several months work I originally 
spent on pyzo.

There are some strange aspects of the code.  Various imports are required 
(in the correct order) even though they aren't immediately used.  This is 
due to side effect of the imports.  The big advance in the present code is 
that I don't plan to change pyzo's code in any way!

Finally, here is the code that actually creates the browser:

def onCreate(tag, keys):
    """Create a pyzo file browser in c's outline."""
    c = keys.get('c')
    dw = c and c.frame and c.frame.top
    if not dw:
        return
    # Use Leo's main window, not pyzo's main window.
    pyzo.main = dw
    # Load the file browser.
    pyzo.toolManager.loadTool('pyzofilebrowser')

That's *all.*

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/bf4ddc3f-50fa-4542-96e1-23c6d2a58a8e%40googlegroups.com.

Reply via email to