diff options
Diffstat (limited to 'sb_builder/ui.py')
| -rw-r--r-- | sb_builder/ui.py | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/sb_builder/ui.py b/sb_builder/ui.py index 087d1a7..82ddc6d 100644 --- a/sb_builder/ui.py +++ b/sb_builder/ui.py @@ -21,8 +21,9 @@ 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 +from PyQt6.QtCore import Qt +from PyQt6.QtGui import QAction, QColor, QIcon, QPainter, QPalette, QPixmap +from PyQt6.QtWidgets import QApplication, QLabel, QLineEdit, QPushButton, QStyle def action(parent, text, icon, fallback, slot=None, checkable=False, shortcut=None): @@ -44,3 +45,44 @@ def enable(a, reason): SP = QStyle.StandardPixmap + + +# ── filter bars: search field, group labels, chips ────────────────────────── + +CHIP_STYLE = ("QPushButton { background: palette(button); border: 1px solid palette(mid);" + " border-radius: 11px; padding: 3px 12px; }" + "QPushButton:hover { border-color: palette(highlight); }" + "QPushButton:checked { background: palette(highlight);" + " color: palette(highlighted-text); border-color: palette(highlight); }") + + +def chip(text, color=None): + """A filter toggle that reads as a button; color: a dot, the one the table uses.""" + b = QPushButton(text, checkable=True) + b.setStyleSheet(CHIP_STYLE) + if color: + pix = QPixmap(10, 10) + pix.fill(Qt.GlobalColor.transparent) + p = QPainter(pix) + p.setRenderHint(QPainter.RenderHint.Antialiasing) + p.setPen(Qt.PenStyle.NoPen) + p.setBrush(QColor(color)) + p.drawEllipse(0, 0, 10, 10) + p.end() + b.setIcon(QIcon(pix)) + return b + + +def group_label(text): + """The muted name in front of a group of chips.""" + label = QLabel(text + ":") + label.setForegroundRole(QPalette.ColorRole.PlaceholderText) + label.setContentsMargins(4, 0, 6, 0) + return label + + +def search_field(placeholder): + q = QLineEdit(placeholderText=placeholder, clearButtonEnabled=True) + icon = QIcon.fromTheme("edit-find", QApplication.style().standardIcon(SP.SP_FileDialogContentsView)) + q.addAction(icon, QLineEdit.ActionPosition.LeadingPosition) + return q |
