In the recent discussion about problems with the Add-Editor command and its 
added editor, I floated the idea of making the body pane be a tabbed widget 
instead of the current stacked widget.  I found it was simple to make this 
change in Leo's core code. Trying it out, I wrote a script to put VR3 into 
the tabbed body pane.  I learned that I like to use it that way.

Then I realized that I could write script so that anyone could try out a 
tabbed body pane without needing to make any changes in Leo's code. My 
scripts are in the attached outline. There are three: one to make the 
change, one to add a VR3 tab, and one to add a VR tab.  You have to run the 
first one first: *Convert Body Editor parent from QStackedWidget to 
QTabWidget on the fly.* This changes the body pane into a tabbed widget. 
The tabs are draggable so you can change their order.

I don't have scripts to reverse these changes but they would be easy to 
write.

-- 
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 leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/94c2057f-000a-44a0-96a2-157fcf652df1n%40googlegroups.com.
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo: https://leo-editor.github.io/leo-editor/leo_toc.html -->
<leo_file xmlns:leo="https://leo-editor.github.io/leo-editor/namespaces/leo-python-editor/1.1"; >
<leo_header file_format="2"/>
<globals/>
<preferences/>
<find_panel_settings/>
<vnodes>
<v t="tom.20240826111544.2"><vh>Tabbed Body Scripts</vh>
<v t="tom.20240826111554.1"><vh>Convert Body Editor parent from QStackedWidget to QTabWidget on the fly</vh></v>
<v t="tom.20240826111640.1"><vh>Add To Tabbed Body Frame</vh>
<v t="tom.20240826111640.2"><vh>VR3</vh></v>
<v t="tom.20240826112310.1"><vh>VR</vh></v>
</v>
</v>
</vnodes>
<tnodes>
<t tx="tom.20240826111544.2"></t>
<t tx="tom.20240826111554.1">from leo.core.leoQt import QtWidgets
c.doCommandByName('tp-restore-default-layout')

# Find splitters, etc.
gui = g.app.gui
ms = gui.find_widget_by_name(c, 'main_splitter')
bp2 = gui.find_widget_by_name(c, 'bodyPage2')
sw = gui.find_widget_by_name(c, 'bodyStackedWidget')

# Find or make singleton bodyTabWidget
tw = gui.find_widget_by_name(c, 'bodyTabWidget')
if not tw:
    tw = QtWidgets.QTabWidget(None)
    tw.setObjectName('bodyTabWidget')
    tw.setMovable(True)

tw.addTab(bp2, 'Body Editor')
sw.addWidget(tw)
</t>
<t tx="tom.20240826111640.1"></t>
<t tx="tom.20240826111640.2">@language python
"""Add widget to body frame tabbed widget.

Only works if the bodyStackedWidget has been changed to or
contains a QTabWidget. Otherwise VR3 will open stacked in 
a new tab in the Log frame.
"""
from leo.plugins import viewrendered3 as v3

vr3 = v3.getVr3({'c':c})

gui = g.app.gui
tw = gui.find_widget_by_name(c, 'bodyStackedWidget')
if 'QTabWidget' not in f'{type(tw)}':
    tw = gui.find_widget_by_name(c, 'bodyTabWidget')
if tw:
    vr3.set_unfreeze()
    index = tw.indexOf(vr3)
    if index == -1:
        index = tw.addTab(vr3, 'VR3')
    tw.setCurrentIndex(index)
else:
    c.doCommandByName('vr3-tab')

</t>
<t tx="tom.20240826112310.1">@language python
"""Add widget to body frame tabbed widget.

Only works if the bodyStackedWidget has been changed to or
contains a QTabWidget. Otherwise VR will open in its default position.
"""
from leo.plugins import viewrendered as v

vr = v.viewrendered({'c': c})
gui = g.app.gui
tw = gui.find_widget_by_name(c, 'bodyStackedWidget')
if 'QTabWidget' not in f'{type(tw)}':
    tw = gui.find_widget_by_name(c, 'bodyTabWidget')
if tw:
    index = tw.indexOf(vr)
    if index == -1:
        index = tw.addTab(vr, 'VR')
    tw.setCurrentIndex(index)
</t>
</tnodes>
</leo_file>

Reply via email to