aboutsummaryrefslogtreecommitdiffstats
path: root/sb_builder/ui.py
diff options
context:
space:
mode:
Diffstat (limited to 'sb_builder/ui.py')
-rw-r--r--sb_builder/ui.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/sb_builder/ui.py b/sb_builder/ui.py
new file mode 100644
index 0000000..087d1a7
--- /dev/null
+++ b/sb_builder/ui.py
@@ -0,0 +1,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