Script to expand toolbar

83 views
Skip to first unread message

lewis

unread,
Apr 2, 2024, 5:25:35 AM4/2/24
to leo-editor
@vitalije first provided a script to expand the toolbar in https://github.com/leo-editor/leo-editor/issues/407
Here is an update that works with PyQt6

"""
Expand button bar
"""

from PyQt6.QtCore import QPointF, Qt
from PyQt6.QtGui import QMouseEvent
from PyQt6.QtWidgets import QApplication

pos = QPointF(0, 0)
button = Qt.MouseButton.LeftButton
btns = Qt.MouseButton(0)
mods = Qt.KeyboardModifier(0)

# Define the event types directly without accessing them through Qt
e1 = QMouseEvent(QMouseEvent.Type.MouseButtonPress, pos, button, btns, mods)
e2 = QMouseEvent(QMouseEvent.Type.MouseButtonRelease, pos, button, btns, mods)

# Assuming 'c' and 'w' are already defined
for w in c.frame.iconBar.w.children():
    if w.objectName() == 'qt_toolbar_ext_button':
        QApplication.sendEvent(w, e1)
        QApplication.sendEvent(w, e2)
        break


Again thanks to Vitalije for the original script.

Edward K. Ream

unread,
Apr 2, 2024, 5:39:56 AM4/2/24
to leo-editor
On Tuesday, April 2, 2024 at 4:25:35 AM UTC-5 lewis wrote:
@vitalije first provided a script to expand the toolbar in https://github.com/leo-editor/leo-editor/issues/407
Here is an update that works with PyQt6

Hurray! I'll check it out soon!

Edward

Edward K. Ream

unread,
Apr 2, 2024, 9:26:44 AM4/2/24
to leo-e...@googlegroups.com
On Tue, Apr 2, 2024 at 4:25 AM lewis <lewi...@fastmail.com.au> wrote:
@vitalije first provided a script to expand the toolbar in https://github.com/leo-editor/leo-editor/issues/407
Here is an update that works with PyQt6

It doesn't work for me.  Where is qt_toolbar_ext_button defined??

Edward

"""
Expand button bar
"""

from PyQt6.QtCore import QPointF, Qt
from PyQt6.QtGui import QMouseEvent
from PyQt6.QtWidgets import QApplication

pos = QPointF(0, 0)
button = Qt.MouseButton.LeftButton
btns = Qt.MouseButton(0)
mods = Qt.KeyboardModifier(0)

# Define the event types directly without accessing them through Qt
e1 = QMouseEvent(QMouseEvent.Type.MouseButtonPress, pos, button, btns, mods)
e2 = QMouseEvent(QMouseEvent.Type.MouseButtonRelease, pos, button, btns, mods)

# Assuming 'c' and 'w' are already defined
for w in c.frame.iconBar.w.children():
    if w.objectName() == 'qt_toolbar_ext_button':
        QApplication.sendEvent(w, e1)
        QApplication.sendEvent(w, e2)
        break


Again thanks to Vitalije for the original script.

--
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/6590e9b3-9ffa-4ed8-ba38-cf403c4ed62fn%40googlegroups.com.


--
-----------------------------------------------------------------
Edward K. Ream: edre...@gmail.com
-----------------------------------------------------------------

lewis

unread,
Apr 2, 2024, 5:28:58 PM4/2/24
to leo-editor
From original issue #407 - You can put that in @button expand-toolbar node in your myLeoSettings.leo under @buttons node.
If it is first child of @buttons then this button will be on left side of toolbar and it will be easier to click this button and then to find button you need.

I confirmed it also works for me as a script using Ctrl-B.

I'm not aware of where  w.objectName() == 'qt_toolbar_ext_button'   is defined.

Edward K. Ream

unread,
Apr 3, 2024, 5:54:32 AM4/3/24
to leo-e...@googlegroups.com
On Tue, Apr 2, 2024 at 4:29 PM lewis <lewi...@fastmail.com.au> wrote:
From original issue #407 - You can put that in @button expand-toolbar node in your myLeoSettings.leo under @buttons node.
If it is first child of @buttons then this button will be on left side of toolbar and it will be easier to click this button and then to find button you need.

I confirmed it also works for me as a script using Ctrl-B.

Thanks for the clarification.  It took me a while to understand what the @button node is doing.

If all buttons are visible in the icon bar, the script does nothing. Otherwise, clicking (and releasing) `@button expand-toolbar` will (temporarily!) show all buttons.

I'm satisfied neither with #407 nor with the script. I would prefer some ways of splitting the icon bar at specific places. I have just created #3851.

Edward




Edward K. Ream

unread,
Apr 3, 2024, 10:56:16 AM4/3/24
to leo-editor
On Wednesday, April 3, 2024 at 4:54:32 AM UTC-5 Edward K. Ream wrote:

It took me a while to understand what the @button node is doing.
...
I'm satisfied neither with #407 nor with the script. I would prefer some ways of splitting the icon bar at specific places. I have just created #3851.

Alright, I think I understand the bounds of the problem.


Googling shows that the QToolbar class has inherent limitations. There is no way to split QToolButton widgets into separate rows. Happily, the toolbar shows an extension icon on the far right when there are too many buttons. Clicking this icon will show the remaining widgets on separate lines. The newly revealed icons remain visible until the user clicks the extension icon again.


I never noticed this behavior before. Worse, my dark theme obscured the extension icon! I've corrected that bug by giving the icon a lighter background color.


@button expand-toolbar


This script needs more explanation. The script creates a button that duplicates the purpose of the extension icon. The script (@button node) does nothing if everything in the icon bar is already visible.


The script simulates a single keypress (and release) on the extension icon. Therefore, the newly revealed icons will remain visible until the user presses the button (or the actual extension icon).


The test:  if w.objectName() == 'qt_toolbar_ext_button':


looks for the name that Qt assigns to the expansion icon. This name has nothing to do with the headline of the @button node!


Summary


At long last, I understand the inherent limitations of the QToolbar widget. There seems to be no way to split its contents into separate (always visible) lines.


Otoh, the extension icon shows all widgets when clicked and continues to do so until clicked again. This behavior is good enough for most purposes.


I've corrected my dark theme to show the extension icon. The icon must not have a black background.


The given @button script works, but it needs some explanation. I'll amend #3851 accordingly.


Edward

Thomas Passin

unread,
Apr 3, 2024, 12:04:00 PM4/3/24
to leo-editor
It's not just a black background that hides it.  There must be a css selector for it, mustn't there? 

Edward K. Ream

unread,
Apr 3, 2024, 12:44:21 PM4/3/24
to leo-editor
On Wednesday, April 3, 2024 at 11:04:00 AM UTC-5 Tom wrote:
It's not just a black background that hides it.  There must be a css selector for it, mustn't there? 

Probably yes, but the defaults for buttons should work.  Here is my selector:

QToolButton#qt_toolbar_ext_button
{
    background-color: @solarized-blue;
    border: none;
}

Edward

Edward K. Ream

unread,
Apr 3, 2024, 12:47:35 PM4/3/24
to leo-editor
On Wednesday, April 3, 2024 at 9:56:16 AM UTC-5 Edward K. Ream wrote:

Googling shows that the QToolbar class has inherent limitations. There is no way to split QToolButton widgets into separate rows.


This statement is misleading. The easiest workaround is to assign buttons/widgets to multiple QToolbar instances.

And one can probably use QLayouts to control placement of toolbar items.

But I'll leave all such issues to the interested reader, hehe.

Edward

Thomas Passin

unread,
Apr 3, 2024, 2:10:13 PM4/3/24
to leo-editor
Better, I think: background-color: @text-foreground; This should work for any (dark) color theme. If you omit the #qt_toolbar_ext_button, the style will get applied to the menubar's "menu-indicator" also, as well as any other toolbar (yes, the menubar also has an overflow indicator, if you can see it).  This is most likely what one wants.

Edward K. Ream

unread,
Apr 3, 2024, 4:35:11 PM4/3/24
to leo-e...@googlegroups.com
On Wed, Apr 3, 2024 at 1:10 PM Thomas Passin <tbp1...@gmail.com> wrote:
Better, I think: background-color: @text-foreground; This should work for any (dark) color theme. If you omit the #qt_toolbar_ext_button, the style will get applied to the menubar's "menu-indicator" also, as well as any other toolbar (yes, the menubar also has an overflow indicator, if you can see it).  This is most likely what one wants.

Thanks for the tip.  I'll try it out.

Edward

Edward K. Ream

unread,
Apr 4, 2024, 4:31:26 AM4/4/24
to leo-e...@googlegroups.com
On Wed, Apr 3, 2024 at 1:10 PM Thomas Passin <tbp1...@gmail.com> wrote:
Better, I think: background-color: @text-foreground; This should work for any (dark) color theme. If you omit the #qt_toolbar_ext_button, the style will get applied to the menubar's "menu-indicator" also, as well as any other toolbar (yes, the menubar also has an overflow indicator, if you can see it).  This is most likely what one wants.

Thanks Thomas. Your suggestions are exactly right.

Edward
Reply all
Reply to author
Forward
0 new messages