robotframework-mind 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- robot_mind.py +442 -0
- robot_mind_app/__init__.py +2 -0
- robot_mind_app/__main__.py +105 -0
- robot_mind_app/community_panel.py +106 -0
- robot_mind_app/editors.py +59 -0
- robot_mind_app/engine.py +24 -0
- robot_mind_app/folders.py +52 -0
- robot_mind_app/graph.py +140 -0
- robot_mind_app/graph_layout.py +97 -0
- robot_mind_app/graph_view.py +244 -0
- robot_mind_app/icons.py +141 -0
- robot_mind_app/lucide.py +71 -0
- robot_mind_app/settings.py +84 -0
- robot_mind_app/theme.py +204 -0
- robot_mind_app/widgets.py +157 -0
- robot_mind_app/window.py +621 -0
- robot_mind_app/worker.py +100 -0
- robotframework_mind-0.1.1.dist-info/METADATA +123 -0
- robotframework_mind-0.1.1.dist-info/RECORD +23 -0
- robotframework_mind-0.1.1.dist-info/WHEEL +5 -0
- robotframework_mind-0.1.1.dist-info/entry_points.txt +2 -0
- robotframework_mind-0.1.1.dist-info/licenses/NOTICE +9 -0
- robotframework_mind-0.1.1.dist-info/top_level.txt +2 -0
robot_mind_app/icons.py
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""Icons drawn from SVG at the exact size and pixel ratio asked for, so they stay sharp at any scale."""
|
|
2
|
+
import math
|
|
3
|
+
import os
|
|
4
|
+
import tempfile
|
|
5
|
+
|
|
6
|
+
from PySide6.QtCore import QByteArray, QPointF, QRectF, QSize, Qt
|
|
7
|
+
from PySide6.QtGui import QColor, QGuiApplication, QIcon, QIconEngine, QImage, QPainter, QPen, QPixmap
|
|
8
|
+
from PySide6.QtSvg import QSvgRenderer
|
|
9
|
+
|
|
10
|
+
from .lucide import ICONS
|
|
11
|
+
|
|
12
|
+
ICON_SIZE = QSize(16, 16) # square icons only; the icon-text gap is the stylesheet's padding
|
|
13
|
+
# What the app calls an icon -> the Lucide name. Rename here, never at call sites.
|
|
14
|
+
ICON_NAMES = {"edit": "mouse-pointer-click", "inspect": "scan-search", "run": "play", "clear": "trash-2",
|
|
15
|
+
"undo": "undo-2", "target": "bot", "secret": "lock", "record": "circle-dot"}
|
|
16
|
+
BRAND = "#4361ee" # the app icon's background; keep it equal to the light theme's accent
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def svg_bytes(name, color, opacity=1.0, pixels=24):
|
|
20
|
+
"""The icon's SVG; `pixels` is the physical size it is drawn at, so the stroke can land on whole pixels."""
|
|
21
|
+
# Lucide strokes are 2 units on a 24-unit grid: 1.67 px at 20 px (16 px at 125%), which antialiasing
|
|
22
|
+
# smears over two pixels. Round the stroke to whole device pixels instead.
|
|
23
|
+
width = max(1, round(2 * pixels / 24)) * 24 / pixels
|
|
24
|
+
return ('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%s" stroke-opacity="%s" '
|
|
25
|
+
'stroke-width="%.3f" stroke-linecap="round" stroke-linejoin="round">%s</svg>'
|
|
26
|
+
% (QColor(color).name(), opacity, width, ICONS[ICON_NAMES.get(name, name)])).encode()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class SvgIconEngine(QIconEngine):
|
|
30
|
+
"""Draws the SVG at the painter's real size and device pixel ratio; `on_color` is the checked state."""
|
|
31
|
+
|
|
32
|
+
def __init__(self, name, color, on_color=None):
|
|
33
|
+
super().__init__()
|
|
34
|
+
self.name, self.color, self.on_color = name, color, on_color
|
|
35
|
+
|
|
36
|
+
def paint(self, painter, rect, mode, state):
|
|
37
|
+
color = self.on_color if state == QIcon.State.On and self.on_color else self.color
|
|
38
|
+
side = min(rect.width(), rect.height())
|
|
39
|
+
ratio = painter.device().devicePixelRatioF() if painter.device() else 1.0
|
|
40
|
+
renderer = QSvgRenderer(QByteArray(svg_bytes(self.name, color, 0.4 if mode == QIcon.Mode.Disabled else 1.0,
|
|
41
|
+
side * ratio)))
|
|
42
|
+
painter.save()
|
|
43
|
+
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
44
|
+
renderer.render(painter, QRectF(rect.x() + (rect.width() - side) / 2, rect.y() + (rect.height() - side) / 2,
|
|
45
|
+
side, side))
|
|
46
|
+
painter.restore()
|
|
47
|
+
|
|
48
|
+
def pixmap(self, size, mode, state):
|
|
49
|
+
pm = QPixmap(size)
|
|
50
|
+
pm.fill(Qt.GlobalColor.transparent)
|
|
51
|
+
painter = QPainter(pm)
|
|
52
|
+
self.paint(painter, pm.rect(), mode, state)
|
|
53
|
+
painter.end()
|
|
54
|
+
return pm
|
|
55
|
+
|
|
56
|
+
def clone(self):
|
|
57
|
+
return SvgIconEngine(self.name, self.color, self.on_color)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def icon(name, color, on_color=None):
|
|
61
|
+
"""An outline icon drawn in `color`; `on_color` draws the checked state (for example on an accent fill)."""
|
|
62
|
+
return QIcon(SvgIconEngine(name, color, on_color))
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
_ICON_DIR = None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _icon_dir():
|
|
69
|
+
"""A per-process temp folder: not a predictable path another process could plant files in."""
|
|
70
|
+
global _ICON_DIR
|
|
71
|
+
if _ICON_DIR is None:
|
|
72
|
+
_ICON_DIR = tempfile.mkdtemp(prefix="robotframework-mind-icons-")
|
|
73
|
+
return _ICON_DIR
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def stylesheet_icon(name, color):
|
|
77
|
+
"""Path of one icon as a PNG (plus @2x) in a temp folder: stylesheets take image files, not icons."""
|
|
78
|
+
folder = _icon_dir()
|
|
79
|
+
os.makedirs(folder, exist_ok=True)
|
|
80
|
+
base = os.path.join(folder, "%s-%s" % (name, QColor(color).name()[1:]))
|
|
81
|
+
for suffix, side in (("", 16), ("@2x", 32)):
|
|
82
|
+
image = QImage(side, side, QImage.Format.Format_ARGB32)
|
|
83
|
+
image.fill(Qt.GlobalColor.transparent)
|
|
84
|
+
painter = QPainter(image)
|
|
85
|
+
QSvgRenderer(QByteArray(svg_bytes(name, color, pixels=side))).render(painter, QRectF(0, 0, side, side))
|
|
86
|
+
painter.end()
|
|
87
|
+
image.save(base + suffix + ".png")
|
|
88
|
+
return (base + ".png").replace("\\", "/") # QSS wants forward slashes
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def chevrons(color):
|
|
92
|
+
"""Chevron image paths for the stylesheet, keyed chevron_right and chevron_down."""
|
|
93
|
+
return {name.replace("-", "_"): stylesheet_icon(name, color) for name in ("chevron-right", "chevron-down")}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
DOT_MARGIN = 1 # px of clear space around a dot, so its antialiased edge is never cut
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def dot_pixmap(color, size=10, hollow=False, ratio=None):
|
|
100
|
+
"""A filled (or hollow) status dot of `size` px plus DOT_MARGIN all round, drawn at the device pixel ratio."""
|
|
101
|
+
if ratio is None:
|
|
102
|
+
screen = QGuiApplication.primaryScreen()
|
|
103
|
+
ratio = screen.devicePixelRatio() if screen else 1.0
|
|
104
|
+
side = math.ceil((size + 2 * DOT_MARGIN) * ratio)
|
|
105
|
+
pm = QPixmap(side, side)
|
|
106
|
+
pm.fill(Qt.GlobalColor.transparent)
|
|
107
|
+
p = QPainter(pm)
|
|
108
|
+
p.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
109
|
+
box = QRectF(0, 0, size * ratio, size * ratio)
|
|
110
|
+
box.moveCenter(QPointF(side / 2, side / 2))
|
|
111
|
+
if hollow:
|
|
112
|
+
pen = 1.5 * ratio
|
|
113
|
+
p.setPen(QPen(QColor(color), pen))
|
|
114
|
+
p.setBrush(Qt.BrushStyle.NoBrush)
|
|
115
|
+
box = box.adjusted(pen / 2, pen / 2, -pen / 2, -pen / 2)
|
|
116
|
+
else:
|
|
117
|
+
p.setPen(Qt.PenStyle.NoPen)
|
|
118
|
+
p.setBrush(QColor(color))
|
|
119
|
+
p.drawEllipse(box)
|
|
120
|
+
p.end()
|
|
121
|
+
pm.setDevicePixelRatio(ratio)
|
|
122
|
+
return pm
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def app_icon(glyph="target"):
|
|
126
|
+
"""The window, taskbar and bundle icon: a white glyph on a rounded brand square, drawn for each size."""
|
|
127
|
+
result = QIcon()
|
|
128
|
+
for side in (16, 24, 32, 48, 64, 128, 256):
|
|
129
|
+
pm = QPixmap(side, side)
|
|
130
|
+
pm.fill(Qt.GlobalColor.transparent)
|
|
131
|
+
p = QPainter(pm)
|
|
132
|
+
p.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
133
|
+
p.setPen(Qt.PenStyle.NoPen)
|
|
134
|
+
p.setBrush(QColor(BRAND))
|
|
135
|
+
p.drawRoundedRect(QRectF(0, 0, side, side), side * 0.22, side * 0.22)
|
|
136
|
+
inset = side * 0.18
|
|
137
|
+
QSvgRenderer(QByteArray(svg_bytes(glyph, "#ffffff", pixels=side - 2 * inset))).render(
|
|
138
|
+
p, QRectF(inset, inset, side - 2 * inset, side - 2 * inset))
|
|
139
|
+
p.end()
|
|
140
|
+
result.addPixmap(pm)
|
|
141
|
+
return result
|
robot_mind_app/lucide.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Icons from Lucide (https://lucide.dev), lucide-static version 1.58.0, vendored unchanged apart from
|
|
2
|
+
# whitespace. Lucide is licensed under the ISC license; its full license text follows.
|
|
3
|
+
#
|
|
4
|
+
# ISC License
|
|
5
|
+
#
|
|
6
|
+
# Copyright (c) 2026 Lucide Icons and Contributors
|
|
7
|
+
#
|
|
8
|
+
# Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
+
# purpose with or without fee is hereby granted, provided that the above
|
|
10
|
+
# copyright notice and this permission notice appear in all copies.
|
|
11
|
+
#
|
|
12
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
13
|
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
14
|
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
15
|
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
16
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
17
|
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
18
|
+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
+
#
|
|
20
|
+
# ---
|
|
21
|
+
#
|
|
22
|
+
# The following Lucide icons are derived from the Feather project:
|
|
23
|
+
#
|
|
24
|
+
# airplay, alert-circle, alert-octagon, alert-triangle, aperture, arrow-down-circle, arrow-down-left, arrow-down-right, arrow-down, arrow-left-circle, arrow-left, arrow-right-circle, arrow-right, arrow-up-circle, arrow-up-left, arrow-up-right, arrow-up, at-sign, calendar, cast, check, chevron-down, chevron-left, chevron-right, chevron-up, chevrons-down, chevrons-left, chevrons-right, chevrons-up, circle, clipboard, clock, code, columns, command, compass, corner-down-left, corner-down-right, corner-left-down, corner-left-up, corner-right-down, corner-right-up, corner-up-left, corner-up-right, crosshair, database, divide-circle, divide-square, dollar-sign, download, external-link, feather, frown, hash, headphones, help-circle, info, italic, key, layout, life-buoy, link-2, link, loader, lock, log-in, log-out, maximize, meh, minimize, minimize-2, minus-circle, minus-square, minus, monitor, moon, more-horizontal, more-vertical, move, music, navigation-2, navigation, octagon, pause-circle, percent, plus-circle, plus-square, plus, power, radio, rss, search, server, share, shopping-bag, sidebar, smartphone, smile, square, table-2, tablet, target, terminal, trash-2, trash, triangle, tv, type, upload, x-circle, x-octagon, x-square, x, zoom-in, zoom-out
|
|
25
|
+
#
|
|
26
|
+
# The MIT License (MIT) (for the icons listed above)
|
|
27
|
+
#
|
|
28
|
+
# Copyright (c) 2013-present Cole Bemis
|
|
29
|
+
#
|
|
30
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
31
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
32
|
+
# in the Software without restriction, including without limitation the rights
|
|
33
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
34
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
35
|
+
# furnished to do so, subject to the following conditions:
|
|
36
|
+
#
|
|
37
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
38
|
+
# copies or substantial portions of the Software.
|
|
39
|
+
#
|
|
40
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
41
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
42
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
43
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
44
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
45
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
46
|
+
# SOFTWARE.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
"""Lucide outline icons as SVG bodies (stroke is set by icons.svg_bytes). Add more with the skill's add_icons.py."""
|
|
50
|
+
|
|
51
|
+
LUCIDE_VERSION = "1.58.0"
|
|
52
|
+
|
|
53
|
+
ICONS = {
|
|
54
|
+
"bot": ('<path d="M12 8V4H8" /> <rect width="16" height="12" x="4" y="8" rx="2" /> <path d="M2 14h2" /> '
|
|
55
|
+
'<path d="M20 14h2" /> <path d="M15 13v2" /> <path d="M9 13v2" />'),
|
|
56
|
+
"check": ('<path d="M20 6 9 17l-5-5" />'),
|
|
57
|
+
"chevron-down": ('<path d="m6 9 6 6 6-6" />'),
|
|
58
|
+
"chevron-right": ('<path d="m9 18 6-6-6-6" />'),
|
|
59
|
+
"circle-dot": ('<circle cx="12" cy="12" r="1" /> <circle cx="12" cy="12" r="10" />'),
|
|
60
|
+
"copy": ('<rect width="14" height="14" x="8" y="8" rx="2" ry="2" /> <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2" />'),
|
|
61
|
+
"lock": ('<rect width="18" height="11" x="3" y="11" rx="2" ry="2" /> <path d="M7 11V7a5 5 0 0 1 10 0v4" />'),
|
|
62
|
+
"monitor": ('<rect width="20" height="14" x="2" y="3" rx="2" /> <line x1="8" x2="16" y1="21" y2="21" /> <line x1="12" x2="12" y1="17" y2="21" />'),
|
|
63
|
+
"moon": ('<path d="M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401" />'),
|
|
64
|
+
"mouse-pointer-click": ('<path d="M14 4.1 12 6" /> <path d="m5.1 8-2.9-.8" /> <path d="m6 12-1.9 2" /> <path d="M7.2 2.2 8 5.1" /> <path d="M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z" />'),
|
|
65
|
+
"play": ('<path d="M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z" />'),
|
|
66
|
+
"save": ('<path d="M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z" /> <path d="M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7" /> <path d="M7 3v4a1 1 0 0 0 1 1h7" />'),
|
|
67
|
+
"scan-search": ('<path d="M3 7V5a2 2 0 0 1 2-2h2" /> <path d="M17 3h2a2 2 0 0 1 2 2v2" /> <path d="M21 17v2a2 2 0 0 1-2 2h-2" /> <path d="M7 21H5a2 2 0 0 1-2-2v-2" /> <circle cx="12" cy="12" r="3" /> <path d="m16 16-1.9-1.9" />'),
|
|
68
|
+
"sun": ('<circle cx="12" cy="12" r="4" /> <path d="M12 2v2" /> <path d="M12 20v2" /> <path d="m4.93 4.93 1.41 1.41" /> <path d="m17.66 17.66 1.41 1.41" /> <path d="M2 12h2" /> <path d="M20 12h2" /> <path d="m6.34 17.66-1.41 1.41" /> <path d="m19.07 4.93-1.41 1.41" />'),
|
|
69
|
+
"trash-2": ('<path d="M10 11v6" /> <path d="M14 11v6" /> <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6" /> <path d="M3 6h18" /> <path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />'),
|
|
70
|
+
"undo-2": ('<path d="M9 14 4 9l5-5" /> <path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11" />'),
|
|
71
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""Persistent app state in QSettings: saved repos, query history, and the editor command."""
|
|
2
|
+
import shlex
|
|
3
|
+
from pathlib import PurePath
|
|
4
|
+
from urllib.parse import quote
|
|
5
|
+
|
|
6
|
+
from PySide6.QtCore import QSettings
|
|
7
|
+
|
|
8
|
+
VSCODE = "vscode" # open through VS Code's vscode:// link: no console, no shell
|
|
9
|
+
DEFAULT_EDITOR = VSCODE
|
|
10
|
+
SCRIPT_SUFFIXES = {".cmd", ".bat"} # Windows runs these through cmd.exe, which re-reads the file name
|
|
11
|
+
MAX_REPOS = 20
|
|
12
|
+
MAX_HISTORY = 30
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AppSettings:
|
|
16
|
+
def __init__(self, settings: QSettings):
|
|
17
|
+
self.s = settings
|
|
18
|
+
|
|
19
|
+
# ---------------------------------------------------------------- saved repos
|
|
20
|
+
def repos(self) -> list[str]:
|
|
21
|
+
value = self.s.value("repos", []) or []
|
|
22
|
+
return [str(r) for r in value] if isinstance(value, (list, tuple)) else [str(value)]
|
|
23
|
+
|
|
24
|
+
def add_repo(self, path: str):
|
|
25
|
+
repos = [r for r in self.repos() if r != path]
|
|
26
|
+
repos.insert(0, path)
|
|
27
|
+
self.s.setValue("repos", repos[:MAX_REPOS])
|
|
28
|
+
|
|
29
|
+
# ---------------------------------------------------------------- query history
|
|
30
|
+
def history(self) -> list[tuple[str, str]]:
|
|
31
|
+
value = self.s.value("history", []) or []
|
|
32
|
+
if isinstance(value, str):
|
|
33
|
+
value = [value]
|
|
34
|
+
out = []
|
|
35
|
+
for item in value:
|
|
36
|
+
text = str(item)
|
|
37
|
+
if "\t" in text:
|
|
38
|
+
command, term = text.split("\t", 1)
|
|
39
|
+
out.append((command, term))
|
|
40
|
+
return out
|
|
41
|
+
|
|
42
|
+
def add_history(self, command: str, term: str):
|
|
43
|
+
items = [h for h in self.history() if h != (command, term)]
|
|
44
|
+
items.insert(0, (command, term))
|
|
45
|
+
self.s.setValue("history", [f"{c}\t{t}" for c, t in items[:MAX_HISTORY]])
|
|
46
|
+
|
|
47
|
+
# ---------------------------------------------------------------- editor
|
|
48
|
+
def editor_command(self) -> str:
|
|
49
|
+
value = str(self.s.value("editor", DEFAULT_EDITOR) or "").strip()
|
|
50
|
+
return value or DEFAULT_EDITOR
|
|
51
|
+
|
|
52
|
+
def set_editor_command(self, command: str):
|
|
53
|
+
self.s.setValue("editor", command)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _unquote(token: str) -> str:
|
|
57
|
+
if len(token) >= 2 and token[0] == token[-1] and token[0] in ("'", '"'):
|
|
58
|
+
return token[1:-1]
|
|
59
|
+
return token
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _file_arg(file: str) -> str:
|
|
63
|
+
"""Prefix a name starting with '-' so it is not read as an option (S2)."""
|
|
64
|
+
return "./" + file if file.startswith("-") else file
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def editor_url(root: str, file: str, line: int, scheme: str = VSCODE) -> str:
|
|
68
|
+
"""The scheme://file link (vscode, cursor) that opens root/file at line."""
|
|
69
|
+
path = PurePath(root, file).as_posix()
|
|
70
|
+
return f"{scheme}://file/{quote(path, safe='/:')}:{line}"
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def check_program(path: str) -> str:
|
|
74
|
+
"""The program itself, or ValueError for a .cmd or .bat launcher (it would open a console and pass the
|
|
75
|
+
file name through cmd.exe)."""
|
|
76
|
+
if PurePath(path).suffix.lower() in SCRIPT_SUFFIXES:
|
|
77
|
+
raise ValueError(f"{PurePath(path).name} is a script; point the editor at its .exe instead")
|
|
78
|
+
return path
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def open_in_editor(file: str, line: int, command: str = DEFAULT_EDITOR) -> list[str]:
|
|
82
|
+
"""The argv that opens `file` at `line`; the caller runs it (no shell, so spaces in a path are safe)."""
|
|
83
|
+
parts = [_unquote(part) for part in shlex.split(command, posix=False)]
|
|
84
|
+
return [part.replace("{file}", _file_arg(file)).replace("{line}", str(line)) for part in parts]
|
robot_mind_app/theme.py
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"""Light and dark themes from one set of design tokens: Fusion style, a palette and one stylesheet."""
|
|
2
|
+
from PySide6.QtCore import QEvent, QObject, Qt
|
|
3
|
+
from PySide6.QtGui import QColor, QPalette
|
|
4
|
+
from PySide6.QtWidgets import QMenu, QProxyStyle, QStyle, QWidget
|
|
5
|
+
|
|
6
|
+
from .icons import chevrons, stylesheet_icon
|
|
7
|
+
|
|
8
|
+
# One set of names for both themes, so every widget, stylesheet rule and custom painter reads the same palette.
|
|
9
|
+
# ground: window background; panel: cards; raised: inputs and pills; ink/ink2/ink3: text, secondary, hint.
|
|
10
|
+
# Light lifts cards on a shadow; dark lifts them on a crisp top edge (shadows vanish on a dark ground).
|
|
11
|
+
THEMES = {
|
|
12
|
+
"light": {"ground": "#e9ecf1", "panel": "#ffffff", "raised": "#f4f6f9", "hover": "#eceff4", "line": "#d6dae3",
|
|
13
|
+
"ink": "#0f1216", "ink2": "#5a6372", "ink3": "#757d8c", "accent": "#4361ee", "accent_soft": "#e4e9fd",
|
|
14
|
+
"accent_text": "#3a56d9", "accent_ink": "#ffffff", "bad": "#e5484d", "bad_soft": "#fde4e5",
|
|
15
|
+
"ok": "#137538", "ok_soft": "#dcf5e5", "warn": "#a14a06", "warn_soft": "#fdebd0", "select": "#4361ee",
|
|
16
|
+
"shadow_alpha": 70, "shadow_blur": 28, "shadow_y": 6, "edge": "transparent", "card_line": "transparent"},
|
|
17
|
+
"dark": {"ground": "#050608", "panel": "#181c24", "raised": "#20252f", "hover": "#2a303c", "line": "#303746",
|
|
18
|
+
"ink": "#f5f7fa", "ink2": "#a3acba", "ink3": "#7d8696", "accent": "#7b93ff", "accent_soft": "#252d4d",
|
|
19
|
+
"accent_text": "#7b93ff", "accent_ink": "#0d0f13", "bad": "#ff6369", "bad_soft": "#3a1d20",
|
|
20
|
+
"ok": "#3ecf8e", "ok_soft": "#16342a", "warn": "#f5b14c", "warn_soft": "#3b2d14", "select": "#7b93ff",
|
|
21
|
+
"shadow_alpha": 0, "shadow_blur": 44, "shadow_y": 12, "edge": "#3d4555", "card_line": "#303746"},
|
|
22
|
+
}
|
|
23
|
+
THEME_MODES = ("system", "light", "dark")
|
|
24
|
+
THEME_ICONS = {"system": "monitor", "light": "sun", "dark": "moon"}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def theme_name(app, mode="system"):
|
|
28
|
+
"""light or dark: the mode itself, or what the system uses when the mode is system."""
|
|
29
|
+
if mode in ("light", "dark"):
|
|
30
|
+
return mode
|
|
31
|
+
try:
|
|
32
|
+
return "dark" if app.styleHints().colorScheme() == Qt.ColorScheme.Dark else "light"
|
|
33
|
+
except AttributeError: # Qt before 6.5
|
|
34
|
+
return "light"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
QSS = """
|
|
38
|
+
QWidget {{ color: {ink}; font-size: 13px; }}
|
|
39
|
+
QMainWindow, QWidget#ground {{ background: {ground}; }}
|
|
40
|
+
/* cards lift on a shadow in light and on a crisp edge in dark, never both */
|
|
41
|
+
QFrame#card {{ background: {panel}; border: 1px solid {card_line}; border-top-color: {edge}; border-radius: 14px; }}
|
|
42
|
+
QFrame#bar {{ background: {panel}; border: 1px solid {card_line}; border-top-color: {edge}; border-radius: 12px; }}
|
|
43
|
+
QToolBar#shell {{ background: {panel}; border: 0; border-bottom: 1px solid {line}; padding: 10px 16px; spacing: 4px; }}
|
|
44
|
+
QToolBar#shell QToolButton, QFrame#bar QToolButton {{ background: transparent; border: 1px solid transparent;
|
|
45
|
+
border-radius: 8px; padding: 6px 10px; color: {ink}; }}
|
|
46
|
+
QToolBar#shell QToolButton:hover, QFrame#bar QToolButton:hover {{ background: {hover}; }}
|
|
47
|
+
QToolBar#shell QToolButton:checked, QFrame#bar QToolButton:checked {{ background: {accent_soft}; color: {accent}; }}
|
|
48
|
+
QToolBar#shell QToolButton:disabled, QFrame#bar QToolButton:disabled {{ color: {ink3}; }}
|
|
49
|
+
QToolBar#shell QToolButton:focus, QFrame#bar QToolButton:focus {{ border-color: {accent}; }}
|
|
50
|
+
QFrame#bar QToolButton {{ padding: 4px 6px; font-size: 12px; }}
|
|
51
|
+
QToolBar#shell QToolButton::menu-indicator {{ image: none; width: 0px; }}
|
|
52
|
+
QFrame#seg {{ background: {raised}; border: 1px solid {line}; border-radius: 11px; }}
|
|
53
|
+
QFrame#seg QToolButton {{ background: transparent; border: 1px solid transparent; border-radius: 8px;
|
|
54
|
+
padding: 4px 14px; color: {ink}; }}
|
|
55
|
+
QFrame#seg QToolButton:hover {{ background: {hover}; }}
|
|
56
|
+
QFrame#seg QToolButton:checked {{ background: {accent}; color: {accent_ink}; }}
|
|
57
|
+
QFrame#seg QToolButton:focus {{ border-color: {accent}; }}
|
|
58
|
+
QGraphicsView#graph {{ background: transparent; border: 0; }}
|
|
59
|
+
QScrollArea#community_scroll, QWidget#community_rows {{ background: transparent; border: 0; }}
|
|
60
|
+
QFrame#pill {{ background: {raised}; border: 1px solid {line}; border-radius: 14px; }}
|
|
61
|
+
QFrame#pill QLabel {{ background: transparent; }}
|
|
62
|
+
QFrame#pill[menu="true"]:hover {{ background: {hover}; }}
|
|
63
|
+
QLabel#product {{ font-size: 17px; font-weight: 700; padding-right: 8px; }}
|
|
64
|
+
QLabel#title {{ font-size: 17px; font-weight: 700; color: {ink}; }}
|
|
65
|
+
QLabel#hint, QLabel#message {{ color: {ink2}; font-size: 12px; }}
|
|
66
|
+
QLabel#chip {{ background: {accent_soft}; color: {accent_text}; font-size: 11px; font-weight: 600; border-radius: 9px;
|
|
67
|
+
padding: 2px 8px; }}
|
|
68
|
+
QLabel#empty_title {{ font-size: 14px; font-weight: 600; color: {ink}; }}
|
|
69
|
+
QLabel#empty_text {{ font-size: 12px; color: {ink2}; }}
|
|
70
|
+
QPushButton {{ background: {raised}; border: 1px solid {line}; border-radius: 8px; padding: 6px 12px; }}
|
|
71
|
+
QPushButton:hover {{ background: {hover}; }}
|
|
72
|
+
QPushButton:pressed {{ background: {line}; }}
|
|
73
|
+
QPushButton:focus {{ border-color: {accent}; }}
|
|
74
|
+
QPushButton#primary {{ background: {accent}; color: {accent_ink}; border-color: {accent}; font-weight: 600; }}
|
|
75
|
+
QPushButton#primary:hover {{ background: {select}; }}
|
|
76
|
+
QLineEdit {{ background: {raised}; border: 1px solid {line}; border-radius: 8px; padding: 6px 10px;
|
|
77
|
+
selection-background-color: {accent_soft}; selection-color: {ink}; }}
|
|
78
|
+
QLineEdit:focus {{ border-color: {accent}; background: {panel}; }}
|
|
79
|
+
QTableWidget, QTreeWidget, QListWidget {{ background: transparent; border: 0; outline: 0; gridline-color: transparent; }}
|
|
80
|
+
QTableWidget::item, QListWidget::item {{ padding: 4px 8px; border: 0; border-radius: 6px; }}
|
|
81
|
+
QTableWidget::item:hover, QListWidget::item:hover {{ background: {hover}; }}
|
|
82
|
+
QTableWidget::item:selected, QListWidget::item:selected {{ background: {accent_soft}; color: {ink}; }}
|
|
83
|
+
QTreeView {{ show-decoration-selected: 1; }}
|
|
84
|
+
QTreeView::item {{ padding: 4px 8px 4px 6px; border: 0; }}
|
|
85
|
+
QTreeView::item:selected, QTreeView::item:selected:active, QTreeView::item:selected:!active {{
|
|
86
|
+
background: {accent_soft}; color: {ink}; }}
|
|
87
|
+
QTreeView::branch {{ background: transparent; }}
|
|
88
|
+
QTreeView::branch:selected {{ background: {accent_soft}; }}
|
|
89
|
+
QTreeView::branch:closed:has-children {{ image: url({chevron_right}); }}
|
|
90
|
+
QTreeView::branch:open:has-children {{ image: url({chevron_down}); }}
|
|
91
|
+
QHeaderView {{ background: transparent; }}
|
|
92
|
+
QHeaderView::section {{ background: transparent; color: {ink2}; border: 0; border-bottom: 1px solid {line};
|
|
93
|
+
padding: 6px 8px; font-size: 12px; font-weight: 600; }}
|
|
94
|
+
QTableCornerButton::section {{ background: transparent; border: 0; }}
|
|
95
|
+
QScrollBar:vertical {{ background: transparent; border: 0; width: 8px; margin: 6px 2px; }}
|
|
96
|
+
QScrollBar:horizontal {{ background: transparent; border: 0; height: 8px; margin: 2px 6px; }}
|
|
97
|
+
QScrollBar::handle {{ background: {line}; border-radius: 4px; min-height: 28px; min-width: 28px; }}
|
|
98
|
+
QScrollBar::handle:hover {{ background: {ink3}; }}
|
|
99
|
+
QScrollBar::add-line, QScrollBar::sub-line {{ width: 0px; height: 0px; border: 0; background: none;
|
|
100
|
+
subcontrol-origin: margin; }}
|
|
101
|
+
QScrollBar::add-page, QScrollBar::sub-page {{ background: none; }}
|
|
102
|
+
QSplitter::handle {{ background: transparent; }}
|
|
103
|
+
QMenu {{ background: {panel}; border: 1px solid {line}; border-radius: 10px; padding: 6px; }}
|
|
104
|
+
QMenu::item {{ padding: 7px 16px 7px 12px; border-radius: 6px; }}
|
|
105
|
+
QMenu::item:selected {{ background: {accent_soft}; color: {ink}; }}
|
|
106
|
+
QMenu::item:disabled {{ color: {ink2}; }}
|
|
107
|
+
QMenu::separator {{ height: 1px; background: {line}; margin: 4px 8px; }}
|
|
108
|
+
QMenu::indicator {{ width: 0; }}
|
|
109
|
+
QMenu::indicator:checked {{ width: 14px; height: 14px; padding-left: 6px; image: url({check_accent}); }}
|
|
110
|
+
QCheckBox {{ spacing: 8px; }}
|
|
111
|
+
QCheckBox::indicator, QTreeView::indicator {{ width: 14px; height: 14px; border: 1px solid {line};
|
|
112
|
+
border-radius: 4px; background: {raised}; }}
|
|
113
|
+
QCheckBox::indicator:hover, QTreeView::indicator:hover {{ border-color: {accent}; }}
|
|
114
|
+
QCheckBox::indicator:checked, QTreeView::indicator:checked {{ background: {accent}; border-color: {accent};
|
|
115
|
+
image: url({check_on_accent}); }}
|
|
116
|
+
QTreeView::indicator:indeterminate {{ background: {accent_soft}; border-color: {accent}; }}
|
|
117
|
+
QLabel#banner {{ background: {bad_soft}; color: {ink}; border: 1px solid {bad}; border-radius: 8px;
|
|
118
|
+
padding: 8px 12px; }}
|
|
119
|
+
QToolButton#folders_toggle {{ background: transparent; border: 0; color: {ink2}; font-size: 11px;
|
|
120
|
+
font-weight: 600; padding: 2px 0; text-align: left; }}
|
|
121
|
+
QToolButton#folders_toggle:hover {{ color: {ink}; }}
|
|
122
|
+
QToolTip {{ background: {raised}; color: {ink}; border: 1px solid {line}; border-radius: 6px; padding: 4px 8px; }}
|
|
123
|
+
QFrame#sidebar {{ background: {panel}; border: 0; border-right: 1px solid {line}; }}
|
|
124
|
+
QLabel#label {{ color: {ink2}; font-size: 11px; font-weight: 600; }}
|
|
125
|
+
QListWidget#nav {{ background: transparent; border: 0; outline: 0; }}
|
|
126
|
+
QListWidget#nav::item {{ padding: 6px 8px; border-radius: 7px; color: {ink}; }}
|
|
127
|
+
QListWidget#nav::item:hover {{ background: {hover}; }}
|
|
128
|
+
QListWidget#nav::item:selected {{ background: {accent_soft}; color: {ink}; }}
|
|
129
|
+
QPushButton#command {{ background: {raised}; border: 1px solid {line}; border-radius: 8px;
|
|
130
|
+
padding: 6px 28px; color: {ink}; text-align: center; }}
|
|
131
|
+
QPushButton#command:hover {{ background: {hover}; }}
|
|
132
|
+
QPushButton#command:focus {{ border-color: {accent}; }}
|
|
133
|
+
QPushButton#command::menu-indicator {{ image: url({chevron_down}); width: 12px; height: 12px;
|
|
134
|
+
subcontrol-position: center right; subcontrol-origin: padding; right: 8px; }}
|
|
135
|
+
QSpinBox {{ background: {raised}; border: 1px solid {line}; border-radius: 8px; padding: 6px 8px;
|
|
136
|
+
color: {ink}; }}
|
|
137
|
+
QSpinBox:focus {{ border-color: {accent}; background: {panel}; }}
|
|
138
|
+
QSpinBox::up-button, QSpinBox::down-button {{ width: 0; border: 0; }}
|
|
139
|
+
QLabel#brand {{ font-size: 15px; font-weight: 700; }}
|
|
140
|
+
QLabel#pagetitle {{ font-size: 22px; font-weight: 700; }}
|
|
141
|
+
QToolButton#theme {{ background: transparent; border: 0; border-radius: 8px; padding: 5px; }}
|
|
142
|
+
QToolButton#theme:hover {{ background: {hover}; }}
|
|
143
|
+
QToolButton#theme:focus {{ border: 1px solid {accent}; }}
|
|
144
|
+
"""
|
|
145
|
+
|
|
146
|
+
TIP_DELAY = 50 # ms before a tooltip shows; Qt's default of 700 reads as lag
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class AppStyle(QProxyStyle):
|
|
150
|
+
"""Fusion with quick tooltips."""
|
|
151
|
+
|
|
152
|
+
def styleHint(self, hint, option=None, widget=None, returnData=None):
|
|
153
|
+
if hint == QStyle.StyleHint.SH_ToolTip_WakeUpDelay:
|
|
154
|
+
return TIP_DELAY
|
|
155
|
+
return super().styleHint(hint, option, widget, returnData)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class SurfaceFilter(QObject):
|
|
159
|
+
"""Menus and tooltips are popup windows: make them frameless and see-through before they show, so only the
|
|
160
|
+
stylesheet's rounded surface is drawn and not a square window behind it (the "two backgrounds" look)."""
|
|
161
|
+
|
|
162
|
+
def eventFilter(self, obj, event):
|
|
163
|
+
if event.type() == QEvent.Type.Polish and isinstance(obj, QWidget) and (
|
|
164
|
+
isinstance(obj, QMenu) or obj.metaObject().className() == "QTipLabel"):
|
|
165
|
+
if not obj.testAttribute(Qt.WidgetAttribute.WA_TranslucentBackground):
|
|
166
|
+
obj.setWindowFlags(obj.windowFlags() | Qt.WindowType.FramelessWindowHint
|
|
167
|
+
| Qt.WindowType.NoDropShadowWindowHint)
|
|
168
|
+
obj.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
|
|
169
|
+
return False
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def apply_theme(app, mode="system"):
|
|
173
|
+
"""Themes the whole app (Fusion looks the same on Windows, Linux and macOS); returns the tokens in use."""
|
|
174
|
+
t = dict(THEMES[theme_name(app, mode)])
|
|
175
|
+
if not hasattr(app, "app_style"): # set once; these objects must outlive every call
|
|
176
|
+
app.app_style, app.surface_filter = AppStyle("Fusion"), SurfaceFilter(app)
|
|
177
|
+
app.setStyle(app.app_style)
|
|
178
|
+
app.installEventFilter(app.surface_filter)
|
|
179
|
+
for effect in (Qt.UIEffect.UI_FadeTooltip, Qt.UIEffect.UI_AnimateTooltip): # no fade on top of the wait
|
|
180
|
+
app.setEffectEnabled(effect, False)
|
|
181
|
+
p = QPalette()
|
|
182
|
+
for role, key in ((QPalette.ColorRole.Window, "ground"), (QPalette.ColorRole.Base, "panel"),
|
|
183
|
+
(QPalette.ColorRole.AlternateBase, "raised"), (QPalette.ColorRole.Button, "raised"),
|
|
184
|
+
(QPalette.ColorRole.Text, "ink"), (QPalette.ColorRole.WindowText, "ink"),
|
|
185
|
+
(QPalette.ColorRole.ButtonText, "ink"), (QPalette.ColorRole.Highlight, "accent"),
|
|
186
|
+
(QPalette.ColorRole.HighlightedText, "accent_ink"), (QPalette.ColorRole.PlaceholderText, "ink3"),
|
|
187
|
+
(QPalette.ColorRole.ToolTipBase, "raised"), (QPalette.ColorRole.ToolTipText, "ink")):
|
|
188
|
+
p.setColor(role, QColor(t[key]))
|
|
189
|
+
app.setPalette(p)
|
|
190
|
+
images = chevrons(t["ink2"]) | {"check_on_accent": stylesheet_icon("check", t["accent_ink"]),
|
|
191
|
+
"check_accent": stylesheet_icon("check", t["accent"])}
|
|
192
|
+
app.setStyleSheet(QSS.format(**t, **images))
|
|
193
|
+
return t
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def contrast(fg, bg):
|
|
197
|
+
"""WCAG contrast ratio of two colors; text needs 4.5, large text and icons 3."""
|
|
198
|
+
def lum(color):
|
|
199
|
+
c = QColor(color)
|
|
200
|
+
parts = [v / 255 for v in (c.red(), c.green(), c.blue())]
|
|
201
|
+
r, g, b = [v / 12.92 if v <= 0.03928 else ((v + 0.055) / 1.055) ** 2.4 for v in parts]
|
|
202
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b
|
|
203
|
+
hi, lo = sorted((lum(fg), lum(bg)), reverse=True)
|
|
204
|
+
return (hi + 0.05) / (lo + 0.05)
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""Building blocks: plain labels, empty states, cards with shadows, the target pill and a segmented switch."""
|
|
2
|
+
from PySide6.QtCore import QSize, Qt, Signal
|
|
3
|
+
from PySide6.QtGui import QColor
|
|
4
|
+
from PySide6.QtWidgets import (QFrame, QGraphicsDropShadowEffect, QHBoxLayout, QLabel, QSizePolicy, QToolButton,
|
|
5
|
+
QVBoxLayout, QWidget)
|
|
6
|
+
|
|
7
|
+
from .icons import ICON_SIZE, icon
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def plain_label(text="", name=""):
|
|
11
|
+
"""Text from files, servers or users is shown as text, never parsed as HTML."""
|
|
12
|
+
label = QLabel(text)
|
|
13
|
+
label.setTextFormat(Qt.TextFormat.PlainText)
|
|
14
|
+
label.setOpenExternalLinks(False)
|
|
15
|
+
label.setObjectName(name)
|
|
16
|
+
return label
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ElidedLabel(QLabel):
|
|
20
|
+
"""One line of plain text that ends in an ellipsis when it does not fit; the tooltip keeps all of it."""
|
|
21
|
+
|
|
22
|
+
def __init__(self, text, name=""):
|
|
23
|
+
super().__init__()
|
|
24
|
+
self.full = text
|
|
25
|
+
self.setTextFormat(Qt.TextFormat.PlainText)
|
|
26
|
+
self.setObjectName(name)
|
|
27
|
+
self.setToolTip(text)
|
|
28
|
+
self.setSizePolicy(QSizePolicy.Policy.Ignored, QSizePolicy.Policy.Preferred)
|
|
29
|
+
self.setText(text)
|
|
30
|
+
|
|
31
|
+
def resizeEvent(self, event):
|
|
32
|
+
self.setText(self.fontMetrics().elidedText(self.full, Qt.TextElideMode.ElideRight, self.width()))
|
|
33
|
+
super().resizeEvent(event)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class EmptyState(QWidget):
|
|
37
|
+
"""A centred icon, title and one line of help, for a pane with nothing to show yet."""
|
|
38
|
+
|
|
39
|
+
def __init__(self, theme, name, title, text):
|
|
40
|
+
super().__init__()
|
|
41
|
+
self.t, self.name = theme, name
|
|
42
|
+
layout = QVBoxLayout(self)
|
|
43
|
+
layout.setContentsMargins(24, 24, 24, 24)
|
|
44
|
+
layout.setSpacing(6)
|
|
45
|
+
layout.addStretch()
|
|
46
|
+
self.icon = plain_label("", "empty_icon")
|
|
47
|
+
self.title, self.text = plain_label("", "empty_title"), plain_label("", "empty_text")
|
|
48
|
+
self.text.setWordWrap(True)
|
|
49
|
+
for widget in (self.icon, self.title, self.text):
|
|
50
|
+
widget.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
51
|
+
layout.addWidget(widget)
|
|
52
|
+
layout.addStretch()
|
|
53
|
+
self.show_text(title, text)
|
|
54
|
+
|
|
55
|
+
def show_text(self, title, text, name=None):
|
|
56
|
+
self.name = name or self.name
|
|
57
|
+
self.title.setText(title)
|
|
58
|
+
self.text.setText(text)
|
|
59
|
+
self.retheme(self.t)
|
|
60
|
+
|
|
61
|
+
def retheme(self, theme):
|
|
62
|
+
self.t = theme
|
|
63
|
+
self.icon.setPixmap(icon(self.name, theme["ink3"]).pixmap(QSize(32, 32), self.devicePixelRatioF()))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
SHADOW_ROOM = 14 # px around a card for its shadow; the bottom gets twice that (the shadow falls down)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def card(widget, theme):
|
|
70
|
+
"""A pane on the window's ground: a rounded panel with a soft drop shadow (light) or a crisp edge (dark).
|
|
71
|
+
|
|
72
|
+
The content is inset a little, so its square children never paint over the rounded corners."""
|
|
73
|
+
frame = QFrame()
|
|
74
|
+
frame.setObjectName("card")
|
|
75
|
+
layout = QVBoxLayout(frame)
|
|
76
|
+
layout.setContentsMargins(6, 6, 6, 6)
|
|
77
|
+
layout.addWidget(widget)
|
|
78
|
+
frame.setGraphicsEffect(QGraphicsDropShadowEffect(frame))
|
|
79
|
+
return floating(frame, theme)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def floating(frame, theme):
|
|
83
|
+
"""Holds a frame that has a drop shadow in a transparent widget with room for that shadow."""
|
|
84
|
+
shade(frame, theme)
|
|
85
|
+
# A shadow is drawn outside the frame and whatever holds the frame clips it: give it room on every side,
|
|
86
|
+
# most at the bottom, sized for the deepest shadow in THEMES.
|
|
87
|
+
holder = QWidget()
|
|
88
|
+
holder.frame = frame
|
|
89
|
+
room = QVBoxLayout(holder)
|
|
90
|
+
room.setContentsMargins(SHADOW_ROOM, SHADOW_ROOM // 2, SHADOW_ROOM, SHADOW_ROOM * 2)
|
|
91
|
+
room.addWidget(frame)
|
|
92
|
+
return holder
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def shade(frame, theme):
|
|
96
|
+
"""(Re)applies the theme's shadow; call it for every card on a theme change."""
|
|
97
|
+
effect = frame.graphicsEffect()
|
|
98
|
+
effect.setEnabled(theme["shadow_alpha"] > 0) # dark cards use an edge instead
|
|
99
|
+
effect.setColor(QColor(0, 0, 0, theme["shadow_alpha"]))
|
|
100
|
+
effect.setBlurRadius(theme["shadow_blur"])
|
|
101
|
+
effect.setOffset(0, theme["shadow_y"])
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class Pill(QFrame):
|
|
105
|
+
"""A rounded status pill (icon, dot, text, chevron); with a menu set, a click on it opens the menu."""
|
|
106
|
+
|
|
107
|
+
clicked = Signal()
|
|
108
|
+
|
|
109
|
+
def __init__(self):
|
|
110
|
+
super().__init__()
|
|
111
|
+
self.setObjectName("pill")
|
|
112
|
+
self.setSizePolicy(QSizePolicy.Policy.Maximum, QSizePolicy.Policy.Fixed) # a toolbar would stretch it
|
|
113
|
+
row = QHBoxLayout(self)
|
|
114
|
+
row.setContentsMargins(10, 4, 12, 4)
|
|
115
|
+
row.setSpacing(6)
|
|
116
|
+
self.glyph, self.dot = plain_label("", "glyph"), plain_label("", "dot")
|
|
117
|
+
self.text, self.chevron = plain_label("", "state"), plain_label("", "chevron")
|
|
118
|
+
for widget in (self.glyph, self.dot, self.text):
|
|
119
|
+
row.addWidget(widget)
|
|
120
|
+
row.addStretch(1) # the pill is as wide as its menu: spare room goes before the chevron
|
|
121
|
+
row.addWidget(self.chevron)
|
|
122
|
+
|
|
123
|
+
def mousePressEvent(self, event):
|
|
124
|
+
if event.button() == Qt.MouseButton.LeftButton and self.property("menu"):
|
|
125
|
+
self.clicked.emit()
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def segmented(actions):
|
|
129
|
+
"""A pill-shaped exclusive switch from checkable actions (put them in one exclusive QActionGroup)."""
|
|
130
|
+
seg = QFrame()
|
|
131
|
+
seg.setObjectName("seg")
|
|
132
|
+
seg.setSizePolicy(QSizePolicy.Policy.Maximum, QSizePolicy.Policy.Fixed)
|
|
133
|
+
row = QHBoxLayout(seg)
|
|
134
|
+
row.setContentsMargins(3, 3, 3, 3)
|
|
135
|
+
row.setSpacing(2)
|
|
136
|
+
for action in actions:
|
|
137
|
+
row.addWidget(tool_button(action))
|
|
138
|
+
return seg
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def tool_button(action, text=True):
|
|
142
|
+
"""A flat button for an action: icon beside text, or icon only (then the action's text is its accessible name)."""
|
|
143
|
+
button = QToolButton()
|
|
144
|
+
button.setDefaultAction(action)
|
|
145
|
+
button.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon if text
|
|
146
|
+
else Qt.ToolButtonStyle.ToolButtonIconOnly)
|
|
147
|
+
button.setIconSize(ICON_SIZE)
|
|
148
|
+
button.setAutoRaise(True)
|
|
149
|
+
button.setAccessibleName(action.text())
|
|
150
|
+
return button
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def gap(width=8):
|
|
154
|
+
"""Blank space between toolbar groups (the toolbar's own spacing is added on both sides)."""
|
|
155
|
+
spacer = QWidget()
|
|
156
|
+
spacer.setFixedWidth(width)
|
|
157
|
+
return spacer
|