Multirow iconbar

37 views
Skip to first unread message

Luka Golibrodo

unread,
Mar 29, 2021, 11:14:52 AM3/29/21
to leo-e...@googlegroups.com
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.

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
MakeIconbarMultirow.py

Edward K. Ream

unread,
Mar 30, 2021, 10:41:29 AM3/30/21
to leo-editor
On Monday, March 29, 2021 at 10:14:52 AM UTC-5 Luka wrote:
I started using some advanced features of Leo in "real life" and here is my first customization attempt :)

Thanks for this.  I'll take a look soon.

Edward
Reply all
Reply to author
Forward
0 new messages