I started using some advanced features of Leo in "real life" and here is my
first customization attempt :)

The problem is: I created so much buttons in iconbar, that they don't fit
in a single row. By default the iconbar has only single row and can be
expanded for a moment with a ">>" button on the right side. But then it
becomes single-row again. I did not find a simple solution to make iconbar
stay multirow,  only a deprecated "toolbar" plugin for Tk GUI, but not for
Qt. So I had to make some customizations. The following code is mainly
based on stackoverflow solution
<https://stackoverflow.com/questions/55930004/keep-qtoolbar-showing-always-all-items>
.

This solution is a little bit 'hacky', but it's advantage that it does not
change any code of iconbar in Leo codebase.

Everything together is attached in .py file (execute with ctrl+b)

First, expand iconbar:
from leo.core.leoQt import QtWidgets, QtCore
iconbar=c.frame.iconBar.w
lay = iconbar.findChild(QtWidgets.QLayout)
if lay is not None:
    lay.setExpanded(True)

Second, hide ">>" button:
button = iconbar.findChild(QtWidgets.QToolButton, "qt_toolbar_ext_button")
if button is not None:
    button.setFixedSize(0, 0)

Third, override "Leave" event (triggered when mouse leaves iconbar):
class eventfilterinst(QtCore.QObject):
    def eventFilter(self, obj, event):
        if event.type() == QtCore.QEvent.Leave: # and obj is qt_widget:
            return True
        return super().eventFilter(obj, event)
ieventfilterinst=eventfilterinst()
c.frame.iconBar.w.installEventFilter(ieventfilterinst)

Now, the iconbar will stay expanded. But when expanded it overlaps body and
tree widgets, so enlarge it:
c.frame.iconBar.w.setFixedHeight(100)

The problem is that this behavior will reset when outline is saved, so
register a Leo event handler:
def expandiconbar(tag, keywords):
    global ieventfilterinst
    # the same code as above
    iconbar=c.frame.iconBar.w
    lay = iconbar.findChild(QtWidgets.QLayout)
    if lay is not None:
        lay.setExpanded(True)
    ieventfilterinst=eventfilterinst()
    c.frame.iconBar.w.installEventFilter(ieventfilterinst)
g.registerHandler('save2',expandiconbar)

I share this for everyone who is concerned about the same problem.
Any comments are welcome!

--
With Best Regards,
Luka

-- 
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/CAP4-pGpo9Q%2B80UZh0jiJzCTne0V2oeHFoOmPdb-ar8972YNKtg%40mail.gmail.com.
#@+leo-ver=5-thin
#@+node:lukagolibrodo.20210329145317.1: * @file /home/me/leo-environment/MakeIconbarMultirow.py
#@@language python

from leo.core.leoQt import QtWidgets, QtCore

# This script make iconbar always expanded. Mainly based on this solution:
#https://stackoverflow.com/questions/55930004/keep-qtoolbar-showing-always-all-items


class eventfilterinst(QtCore.QObject):
    def eventFilter(self, obj, event):
        if event.type() == QtCore.QEvent.Leave: # and obj is qt_widget:
            return True
        return super().eventFilter(obj, event)

#first, do it immediately
#@+<<hacks for iconbar>>
#@+node:lukagolibrodo.20210329151339.1: ** <<hacks for iconbar>>
iconbar=c.frame.iconBar.w
lay = iconbar.findChild(QtWidgets.QLayout)
if lay is not None:
    lay.setExpanded(True)

button = iconbar.findChild(QtWidgets.QToolButton, "qt_toolbar_ext_button")
if button is not None:
    button.setFixedSize(0, 0)

ieventfilterinst=eventfilterinst()
c.frame.iconBar.w.installEventFilter(ieventfilterinst)
#@-<<hacks for iconbar>>

#maybe there is some elegant solution, but if only to expand iconbar it overlaps with body and tree areas -> so just enlarge it
c.frame.iconBar.w.setFixedHeight(100)

#second, register hook (if not, behavoir of iconbar reset when save)
#this code may be dirty because every time new objects are created
def expandiconbar(tag, keywords):
    global ieventfilterinst #?
    #@+<<hacks for iconbar>>
    #@+node:lukagolibrodo.20210329151339.1: ** <<hacks for iconbar>>
    iconbar=c.frame.iconBar.w
    lay = iconbar.findChild(QtWidgets.QLayout)
    if lay is not None:
        lay.setExpanded(True)

    button = iconbar.findChild(QtWidgets.QToolButton, "qt_toolbar_ext_button")
    if button is not None:
        button.setFixedSize(0, 0)

    ieventfilterinst=eventfilterinst()
    c.frame.iconBar.w.installEventFilter(ieventfilterinst)
    #@-<<hacks for iconbar>>

g.registerHandler('save2',expandiconbar)

g.es('fin')

#@-leo

Reply via email to