An Outline To Demonstrate The Script-based Layout System

113 views
Skip to first unread message

Thomas Passin

unread,
Sep 3, 2024, 1:46:40 PM9/3/24
to leo-editor
In  Engineering Notebook: A Script-based Approach To Leo's Layouts I proposed a system to apply layouts (different arrangements of Leo's panes). Attached to this post is a Leo outline that contains commands and a menu that let you try out the system for yourself.

The outline contains an @settings tree that creates the menu, and the commands that it calls.  They include some but not all of the layout commands I use myself.  One of the commands establishes a layout that Edward has names "big-tree".  These layout commands can be used as guidance for creating your own if you like.

There two menu items that create a new widget in a "Tabbed Body". You need to create a tabbed body first using the "Make Body Tabbed" menu item first.  Otherwise these widgets will open in another location, not in the tabbed body.

All layouts may be undone and the default layout re-applied Using the "Restore Default Layout" menu item.

The command to create specific layouts in the demo create the layouts with specific programs.  But the default layout is applied by a command that sets up the default layout by using descriptor data structures.  These include which splitters contain which widgets in which order, what orientations to apply to which splitters, etc.  These descriptors are stored a persistent object, a QWidget that lives in the main splitter.

The outline also contains an About This Outline node.

It would be very feasible to adapt the restoration code to run it on a set of descriptors from another source, such as a layout creation script.  Then it would produce some other layout instead.  This would be easier than writing bespoke creation code for each new layout. A layout script would look something like this in pseudo-code:

Initialize system if not already initialized.
Create any special objects and splitters needed for the layout.
Read descriptors from layout descriptor file.
Run generic layout code using the special objects and descriptors.

Give the outline a try.  If you find any bugs or unexpected behavior, please let me know.  This version has a bug that once you restore the default layout, then the VR/VR3 F11 Help display doesn't appear.  I'll track down what's happening and correct it. And if you like it, you can move the commands and menus over to your myLeoSettings.leo outline and have them available to all outlines.

layout_script_commands.zip

Thomas Passin

unread,
Sep 3, 2024, 1:59:42 PM9/3/24
to leo-editor
On Tuesday, September 3, 2024 at 1:46:40 PM UTC-4 Thomas Passin wrote:
In  Engineering Notebook: A Script-based Approach To Leo's Layouts I proposed a system to apply layouts (different arrangements of Leo's panes). Attached to this post is a Leo outline that contains commands and a menu that let you try out the system for yourself.
[...]
This version has a bug that once you restore the default layout, then the VR/VR3 F11 Help display doesn't appear.  I'll track down what's happening and correct it. And if you like it, you can move the commands and menus over to your myLeoSettings.leo outline and have them available to all outlines.

The temporary fix is to use one of the layouts that show VR3.  Then the help messages will display.  I will add a new menu item for displaying VR, for those who use it but not VR3. 

Viktor Ransmayr

unread,
Sep 4, 2024, 6:01:07 AM9/4/24
to leo-editor
Hello Thomas,

tbp1...@gmail.com schrieb am Dienstag, 3. September 2024 um 19:46:40 UTC+2:
In  Engineering Notebook: A Script-based Approach To Leo's Layouts I proposed a system to apply layouts (different arrangements of Leo's panes). Attached to this post is a Leo outline that contains commands and a menu that let you try out the system for yourself.

...

Give the outline a try.  If you find any bugs or unexpected behavior, please let me know.  ...

I gave it a try with Leo 6.8.1 from PyPI in a Fedora 40 VM. - Everything looks good, with one small hiccup. - Here's my log:
 
Download outline to '~/Documents/' as 'TBP-Layout-Script-Commands.leo'.

* Read info 'About this Outline' ...
* Try command 'layout-open-rpcalc-in-tabbed-body' ? - Works.
* Try command 'layout-big-tree' ? - Not OK - See "Log-001".
* Try command 'layout-restore-default' ? - Works.
* Try command 'vr3-toggle-in-main-split' ? - Works.
* Try command 'layout-make-tabbed-body-pane' ? - Works.
* Try command 'layout-vr3-to-tabbed-body' ? - Works.
* Try command 'layout-swap-nav-panel' ? - Works.
* Try command 'layout-restore-default' ? - Works.

With kind regards,

Viktor

### Log-001 ###

    Leo Log Window
    Leo 6.8.1, master branch
    Python 3.12.5, PyQt version 6.6.2
    linux
    reading settings in /home/user/Documents/TBP-Layout-Script-Commands.leo
    read outline in 0.00 seconds
    exception executing script
    Traceback (most recent call last):
      File "/home/user/PyVE/PyPI/Leo/lib64/python3.12/site-packages/leo/core/leoCommands.py", line 1214, in executeScript
        c.executeScriptHelper(args, define_g, define_name, namespace, script)
      File "/home/user/PyVE/PyPI/Leo/lib64/python3.12/site-packages/leo/core/leoCommands.py", line 1259, in executeScriptHelper
        exec(compile(script, scriptFile, 'exec'), d)
      File "/home/user/.leo/scriptFile.py", line 31, in <module>
        NAMES = 'viewrendered_pane viewrendered3_pane rpcalc'.split()
             ^^^^^^^
    AttributeError: module 'leo.plugins.viewrendered' has no attribute 'getVr'
    --------------------
      line 30: if not c.user_dict.get(EXTRAS):
    * line 31:     NAMES = 'viewrendered_pane viewrendered3_pane rpcalc'.split()
      line 32:     c.user_dict[EXTRAS] = set(NAMES)
      line 33:

Thomas Passin

unread,
Sep 4, 2024, 7:33:11 AM9/4/24
to leo-editor
Thanks for testing, and thanks for the report.  The big-tree layout was a late addition and it works for me. I haven't tried the outline on Linux, yet. I'm puzzled by the error report, though.  It's reporting the wrong place in the file: the AttributeError reported can't happen  there since it's just a string split.

Could you try the outline using a current version of the devel branch?  IIRC the missing getVr() method is something that Edward added recently, probably after 6.8.1 was released.  If you can't update for now I could send you a version that does work with 6.8.1 too.

Thomas Passin

unread,
Sep 4, 2024, 8:23:31 AM9/4/24
to leo-editor
Edward introduced the function getVr() on July 27, at rev f520b66d. Any version earlier than that won't have it.

Viktor Ransmayr

unread,
Sep 4, 2024, 8:41:13 AM9/4/24
to leo-e...@googlegroups.com
Hello Thomas,

Am Mi., 4. Sept. 2024 um 13:33 Uhr schrieb Thomas Passin <tbp1...@gmail.com>:
Thanks for testing, and thanks for the report.  The big-tree layout was a late addition and it works for me. I haven't tried the outline on Linux, yet. I'm puzzled by the error report, though.  It's reporting the wrong place in the file: the AttributeError reported can't happen  there since it's just a string split.

Could you try the outline using a current version of the devel branch?  IIRC the missing getVr() method is something that Edward added recently, probably after 6.8.1 was released.  If you can't update for now I could send you a version that does work with 6.8.1 too.

The picture changes - but - the ~ hiccup ~ persists - Here's my log again:

* Try command 'layout-open-rpcalc-in-tabbed-body' ? - Works as before ...
* Try command 'layout-big-tree' ? - GUI changes but tracebacks - See log ...
* Try command 'layout-restore-default' ? - GUI no longer changes but still tracebacks - See log ...

With kind regards,

Viktor

###

    Leo Log Window
    Leo 6.8.2-devel, devel branch, build 12f06b69ea
    2024-08-28 10:58:09 -0500
    Python 3.12.5, PyQt version 6.7.1
    linux
    setting leoID from os.getenv('USER'): 'user'
          home: /home/user
    leo-editor: /home/user/PyVE/GitHub/Leo/leo-editor
          load: /home/user/PyVE/GitHub/Leo/leo-editor/leo/core
        config: /home/user/PyVE/GitHub/Leo/leo-editor/leo/config
    reading settings in /home/user/PyVE/GitHub/Leo/leo-editor/leo/config/leoSettings.leo
    reading settings in /home/user/.leo/myLeoSettings.leo
    reading settings in /home/user/PyVE/GitHub/Leo/leo-editor/leo/themes/tbp_dark_solarized.leo
    VR3 -- no asciidoc processor
    VR3 -- no asciidoc3 processor
    Can't find /home/user/.leo/vr3/vr3_config.ini so VR3 cannot execute non-Python code
    reading settings in /home/user/Documents/SL2024.leo
    read outline in 0.29 seconds
 
    ### No output for 'layout-open-rpcalc-in-tabbed-body':

    ### Output for 'layout-big-tree':

    getVr "c" or "event" kwarg required atCommandCallback,executeScript,executeScriptHelper,<module>

    exception executing script
    Traceback (most recent call last):

      File "/home/user/PyVE/GitHub/Leo/leo-editor/leo/core/leoCommands.py", line 1214, in executeScript

        c.executeScriptHelper(args, define_g, define_name, namespace, script)

      File "/home/user/PyVE/GitHub/Leo/leo-editor/leo/core/leoCommands.py", line 1259, in executeScriptHelper

        exec(compile(script, scriptFile, 'exec'), d)

      File "/home/user/.leo/scriptFile.py", line 41, in <module>

    AttributeError: 'NoneType' object has no attribute 'setParent'

    --------------------


    ### Output for 'layout-restore-default':

    getVr "c" or "event" kwarg required atCommandCallback,executeScript,executeScriptHelper,<module>

    exception executing script
    Traceback (most recent call last):

      File "/home/user/PyVE/GitHub/Leo/leo-editor/leo/core/leoCommands.py", line 1214, in executeScript

        c.executeScriptHelper(args, define_g, define_name, namespace, script)

      File "/home/user/PyVE/GitHub/Leo/leo-editor/leo/core/leoCommands.py", line 1259, in executeScriptHelper

        exec(compile(script, scriptFile, 'exec'), d)

      File "/home/user/.leo/scriptFile.py", line 41, in <module>

    AttributeError: 'NoneType' object has no attribute 'setParent'

    --------------------

lewis

unread,
Sep 4, 2024, 9:16:14 AM9/4/24
to leo-editor
Using the Menu buttons I tested all commands on WSL Ubuntu-22.04 and all the commands worked. After each command I restored default layout.

# Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
Leo 6.8.2-devel, devel branch, build 7ba85dfcb8
Python 3.10.12, PyQt version 6.7.2


* Only 'vr3-toggle-in-main-split' gave any error.
Command 'vr3-toggle-in-main-split' gives error at first use:

Path override failed for key base::DIR_APP_DICTIONARIES and path '/usr/bin/qtwebengine_dictionaries'
Path override failed for key base::DIR_APP_DICTIONARIES and path '/home/lewisneal/.local/lib/python3.10/site-packages/PyQt6/Qt6/libexec/qtwebengine_dictionaries'
Path override failed for key base::DIR_APP_DICTIONARIES and path '/home/lewisneal/.local/lib/python3.10/site-packages/PyQt6/Qt6/libexec/qtwebengine_dictionaries'

If command 'vr3-toggle-in-main-split' is repeated a second time, a single error is given:
Path override failed for key base::DIR_APP_DICTIONARIES and path '/home/lewisneal/.local/lib/python3.10/site-packages/PyQt6/Qt6/libexec/qtwebengine_dictionaries'

If command 'vr3-toggle-in-main-split' is repeated again there are no further errors.

Thomas Passin

unread,
Sep 4, 2024, 9:48:29 AM9/4/24
to leo-editor
I can't help with the missing dictionaries.  That's one of those behind-the-scenes missing libraries and I haven't seen this one before.  I haven't gotten it on my own Ubuntu VM so far.  I will test the Layout Demo on some of my Linux VMs soon.

I do have an update to the big-tree script that will create a VR instance using either the new or old methods (tested on Windows so far).  It's attached.

updated-big-tree-command.zip

Thomas Passin

unread,
Sep 4, 2024, 10:14:37 AM9/4/24
to leo-editor
I've tried out the Layout Demo in my Ubuntu and Mint VMs and it works as intended without those error messages.  I don't have WSL set up so I can't work on your errors.  Funny how they went away after several tries.

Viktor Ransmayr

unread,
Sep 4, 2024, 12:31:37 PM9/4/24
to leo-editor
Hello Thomas,

tbp1...@gmail.com schrieb am Mittwoch, 4. September 2024 um 15:48:29 UTC+2:
I can't help with the missing dictionaries.  That's one of those behind-the-scenes missing libraries and I haven't seen this one before.  I haven't gotten it on my own Ubuntu VM so far.  I will test the Layout Demo on some of my Linux VMs soon.

I do have an update to the big-tree script that will create a VR instance using either the new or old methods (tested on Windows so far).  It's attached.

I have re-checked that I am FULLY up-to-date with Leo's devel branch. - I am ;-)

I tried your updated outline again in the Fedora 40 VM - and - still see a traceback - See attached log:

With kind regards,

Viktor

###

    no command function for 'layout-restore-default'
    doCommandByName new_cmd_wrapper,executeScript,executeScriptHelper,<module>
    getVr "c" or "event" kwarg required new_cmd_wrapper,executeScript,executeScriptHelper,<module>

    exception executing script
    Traceback (most recent call last):

      File "/home/user/PyVE/GitHub/Leo/leo-editor/leo/core/leoCommands.py", line 1214, in executeScript
        c.executeScriptHelper(args, define_g, define_name, namespace, script)

      File "/home/user/PyVE/GitHub/Leo/leo-editor/leo/core/leoCommands.py", line 1259, in executeScriptHelper
        exec(compile(script, scriptFile, 'exec'), d)

      File "/home/user/.leo/scriptFile.py", line 47, in <module>
        widget.setParent(None)
        ^^^^^^^^^^^^^^^^

Thomas Passin

unread,
Sep 4, 2024, 5:00:49 PM9/4/24
to leo-editor
The error that counts here is 

no command function for 'layout-restore-default'

I wasn't clear enough, I think.  The script I sent can't work on its own. I meant the one new node in the new outline  to replace the node of the same name in the @settings tree of the Layouts Demo outline.  Then Leo would have to be restarted.  If you did it this way already then I'm at a loss.

Once the change has been made. if the demo still produces the same error, check what layout commands you do have.  Go into the minibuffer and type layout<TAB>. Here is what I get:

   layout-big-tree
   layout-initialize
   layout-make-tabbed-body-pane
   layout-open-rpcalc-in-tabbed-body
   layout-restore-default
   layout-swap-nav-panel
   layout-toggle-vr-in-split-main
   layout-vr-to-tabbed-body
   layout-vr3-to-tabbed-body


Thomas Passin

unread,
Sep 4, 2024, 6:20:30 PM9/4/24
to leo-editor
Here is an updated copy of the entire layout_script_cpmmands.leo outline.  It also has an added layout with VR.  All layouts for VR now include the version of the VR code that will work with both the new and the older versions of Leo.

This outline is complete and will work on its own.

layout_script_commands.zip

Edward K. Ream

unread,
Sep 5, 2024, 8:27:59 AM9/5/24
to leo-e...@googlegroups.com
On Wed, Sep 4, 2024 at 5:20 PM Thomas Passin <tbp1...@gmail.com> wrote:
Here is an updated copy of the entire layout_script_cpmmands.leo outline.  It also has an added layout with VR.  All layouts for VR now include the version of the VR code that will work with both the new and the older versions of Leo.

I've taken a brief look at a few of the scripts. They look pleasingly simple. Keep up the good work!

Edward

Thomas Passin

unread,
Sep 5, 2024, 8:44:44 AM9/5/24
to leo-editor
I've been able to make substantial simplifications to the initialize and restore commands.  I also have changed the location of the widget cache from the main splitter to c.frame.top.  That is just as permanent, which is the only real requirement, and by moving it out of the main splitter I don't need to make any special cases while scanning the splitter contents.

I have also tuned up the Jacob's "Quadrant" layout and included it. This is significant because the layout adds a whole new splitter, and the new, simplified restore code is able to handle this case perfectly.

I'm just working out one bug I've discovered and then I will post the new Layout Demo outline. I will post it in a new discussion since this one has gotten longish.

Viktor Ransmayr

unread,
Sep 5, 2024, 1:11:31 PM9/5/24
to leo-editor
Hello Thomas,

tbp1...@gmail.com schrieb am Donnerstag, 5. September 2024 um 14:44:44 UTC+2:
I've been able to make substantial simplifications to the initialize and restore commands. 
...
I'm just working out one bug I've discovered and then I will post the new Layout Demo outline. I will post it in a new discussion since this one has gotten longish.

Sorry for not responding earlier. - I had to prioritize other issues ...

I'll wait for your new outline  & will try it again on my side with  'fresh' Debian 12 - as well as - Fedora 40 VMs.

Thanks a lot for your work !

With kind regards,

Viktor
 
Reply all
Reply to author
Forward
0 new messages