1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# sb-builder - ribbon actions
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""Ribbon actions shared by the tabs (UI guidelines in AGENTS.md).
Each tab owns two lists of QActions: `actions` for the main ribbon (what it
does, in workflow order) and `view_actions` for the small one (selection and
view controls). The main window shows the current tab's lists.
"""
from PyQt6.QtGui import QAction, QIcon
from PyQt6.QtWidgets import QStyle
def action(parent, text, icon, fallback, slot=None, checkable=False, shortcut=None):
"""A ribbon action: freedesktop icon with a QStyle fallback."""
a = QAction(QIcon.fromTheme(icon, parent.style().standardIcon(fallback)), text, parent,
checkable=checkable)
if slot:
a.triggered.connect(lambda _checked=False: slot())
a.setData(shortcut) # shown in the tooltip; the tab's QShortcut does the work
enable(a, None)
return a
def enable(a, reason):
"""Enable a, or disable it with reason as its tooltip: disabled, never hidden."""
a.setEnabled(not reason)
tip = a.text() + (f" ({a.data()})" if a.data() else "")
a.setToolTip(f"{tip}: {reason}" if reason else tip)
SP = QStyle.StandardPixmap
|