bubbleUI 0.5.3a6__tar.gz → 0.5.3a9__tar.gz

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.
Files changed (47) hide show
  1. {bubbleui-0.5.3a6/src/bubbleUI.egg-info → bubbleui-0.5.3a9}/PKG-INFO +1 -1
  2. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/pyproject.toml +1 -1
  3. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/glasskit/__init__.py +15 -7
  4. bubbleui-0.5.3a9/src/bubble/glasskit/backdrop.py +377 -0
  5. bubbleui-0.5.3a9/src/bubble/glasskit/config.py +215 -0
  6. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/glasskit/energy.py +30 -0
  7. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/glasskit/glass.py +85 -33
  8. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/glasskit/settings.py +38 -2
  9. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/navigate.py +9120 -8461
  10. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/uiWindow.py +8 -0
  11. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/uiml.py +123 -12
  12. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9/src/bubbleUI.egg-info}/PKG-INFO +1 -1
  13. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubbleUI.egg-info/SOURCES.txt +6 -0
  14. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/tests/test_color_manager.py +1 -1
  15. bubbleui-0.5.3a9/tests/test_glass_backdrop_config.py +292 -0
  16. bubbleui-0.5.3a9/tests/test_glass_energy_tint.py +181 -0
  17. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/tests/test_icon_opacity.py +1 -1
  18. bubbleui-0.5.3a9/tests/test_navigate_window_glass.py +515 -0
  19. bubbleui-0.5.3a9/tests/test_titlebar_controls.py +165 -0
  20. bubbleui-0.5.3a9/tests/test_titlebar_interactive.py +211 -0
  21. bubbleui-0.5.3a6/src/bubble/glasskit/config.py +0 -78
  22. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/LICENSE +0 -0
  23. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/README.md +0 -0
  24. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/setup.cfg +0 -0
  25. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/QUI.py +0 -0
  26. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/__init__.py +0 -0
  27. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/cards.py +0 -0
  28. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/color_manager.py +0 -0
  29. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/glasskit/gpu.py +0 -0
  30. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/glasskit/imaging.py +0 -0
  31. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/glasskit/transparency.py +0 -0
  32. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/i18n.py +0 -0
  33. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/icon.py +0 -0
  34. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/levels/__init__.py +0 -0
  35. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/levels/component.py +0 -0
  36. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/levels/manager.py +0 -0
  37. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/styles.py +0 -0
  38. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubble/widgets.py +0 -0
  39. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubbleUI.egg-info/dependency_links.txt +0 -0
  40. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubbleUI.egg-info/requires.txt +0 -0
  41. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/src/bubbleUI.egg-info/top_level.txt +0 -0
  42. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/tests/test_i18n.py +0 -0
  43. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/tests/test_import.py +0 -0
  44. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/tests/test_navigate_activation.py +0 -0
  45. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/tests/test_navigate_glass_states.py +0 -0
  46. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/tests/test_nullType.py +0 -0
  47. {bubbleui-0.5.3a6 → bubbleui-0.5.3a9}/tests/test_transparency.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bubbleUI
3
- Version: 0.5.3a6
3
+ Version: 0.5.3a9
4
4
  Author-email: xystudio <173288240@qq.com>
5
5
  License: MIT
6
6
  Project-URL: Homepage, https://github.com/xystudiocode/bubbleUI
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "bubbleUI"
7
- version = "0.5.3a6"
7
+ version = "0.5.3a9"
8
8
  description = ""
9
9
  readme = { file = "README.md", content-type = "text/markdown" }
10
10
  authors = [
@@ -6,8 +6,14 @@ The package contains the reusable pieces only:
6
6
  helper. All material controls, including the vignette, live here. Every
7
7
  field is also exposed as a QSS ``qproperty-frost*`` on the painting widgets
8
8
  (:class:`GlassBackdrop`, :class:`GlassMenuBar`, :class:`GlassPanel`), so the
9
- four presets in :mod:`.config` can be tuned from the theme style sheet; see
9
+ materials can be tuned from the theme style sheet; see
10
10
  :func:`apply_glass_style` for the ``"thin"`` variants.
11
+ * :class:`Backdrop` / :class:`BackdropConfig` -- the named glass
12
+ configurations behind those materials (``backdrop.normal.getItem("bg")``).
13
+ :data:`backdrop` is the library-wide registry; ``Backdrop.setDark()``
14
+ switches the light/dark variants and ``Backdrop.useConfig()`` switches the
15
+ default configuration. ``bubble.navigate.apply_glass_theme`` calls
16
+ ``backdrop.setDark()`` and refreshes the live windows / navigation views.
11
17
  * :class:`BlurredGlassPanel` -- blur the content underneath one widget.
12
18
  * :class:`DesktopSource` -- capture the screen and supply blurred regions for
13
19
  live window-level glass.
@@ -71,7 +77,8 @@ from .transparency import (
71
77
  shared_transparency_watcher,
72
78
  system_transparency_enabled,
73
79
  )
74
- from .config import * # noqa: F403
80
+ from .config import CAPTURE_SCALE, RUNTIME, backdrop
81
+ from .backdrop import Backdrop, BackdropConfig
75
82
 
76
83
  __all__ = [
77
84
  "BACKGROUND_SCREEN",
@@ -105,14 +112,15 @@ __all__ = [
105
112
  "qimage_to_pil",
106
113
  "rounded_path",
107
114
  "system_wallpaper_path",
108
- "BUBBLE_BACKGROUND_NORMAL",
109
- "BUBBLE_BACKGROUND_THIN",
110
- "BUBBLE_SIDEBAR_NORMAL",
111
- "BUBBLE_SIDEBAR_THIN",
115
+ "Backdrop",
116
+ "BackdropConfig",
117
+ "CAPTURE_SCALE",
118
+ "RUNTIME",
119
+ "backdrop",
112
120
  "GlassMainWindow",
113
121
  "GlassDialog",
114
122
  "GlassMenuBar",
115
123
  "GlassPanel",
116
- "FROST_PRESETS",
124
+ "GlassBackdrop",
117
125
  "apply_glass_style"
118
126
  ]
@@ -0,0 +1,377 @@
1
+ """Named glass configurations: the data behind every glass material.
2
+
3
+ This module holds **only data**: named configurations (:class:`BackdropConfig`)
4
+ made of named items, plus the current light/dark mode. Painting stays in
5
+ :mod:`bubble.glasskit.glass` (the ``GlassBackdrop`` *widget* and friends); a
6
+ configuration is not a widget.
7
+
8
+ A configuration item stores a :class:`~.settings.FrostStyle`. Item names are
9
+ free (``addItem`` accepts any name), but two suffixes carry meaning for the
10
+ built-in ones:
11
+
12
+ * ``bg_*`` / ``sidebar_*`` -- the whole-window content material and the
13
+ sidebar / titlebar material;
14
+ * ``_dark`` / ``_light`` -- the variant used in that theme.
15
+
16
+ :meth:`BackdropConfig.getItem` resolves a *base* name (``"bg"``) for the
17
+ current mode, falling back to the other mode and then to the ``normal``
18
+ configuration. An explicit variant name (``"bg_dark"``) is looked up as-is.
19
+ The fallback chain never crosses kinds: a missing ``bg`` item never borrows a
20
+ ``sidebar`` material.
21
+
22
+ The library ships one registry, ``bubble.glasskit.config.backdrop``. Create a
23
+ nested one only for tests or for a completely separate glass theme::
24
+
25
+ from bubble.glasskit import backdrop
26
+
27
+ backdrop.normal.getItem("bg") # 当前模式的背景玻璃
28
+ backdrop.thin.setItem("bg_light", ...) # 内置配置可读写
29
+ backdrop.copyConfig("normal", "acrylic")
30
+ backdrop.useConfig("thin") # 全局切换,已打开窗口立即刷新
31
+ backdrop.useConfig(None) # 不用玻璃材质(窗口级玻璃关闭)
32
+ """
33
+
34
+ from __future__ import annotations
35
+
36
+ import traceback
37
+ from typing import Callable, Iterator
38
+
39
+ from .settings import FrostStyle
40
+
41
+ DARK = "dark"
42
+ LIGHT = "light"
43
+
44
+ _SUFFIXES = (("_dark", DARK), ("_light", LIGHT))
45
+
46
+ #: Name of the configuration whose items back every fallback.
47
+ _FALLBACK_NAME = "normal"
48
+
49
+
50
+ def _other(mode: str) -> str:
51
+ return LIGHT if mode == DARK else DARK
52
+
53
+
54
+ def split_variant(item_name: str) -> tuple[str, str] | None:
55
+ """Split ``"bg_dark"`` into ``("bg", "dark")``; plain names return ``None``."""
56
+ for suffix, mode in _SUFFIXES:
57
+ if item_name.endswith(suffix) and len(item_name) > len(suffix):
58
+ return item_name[: -len(suffix)], mode
59
+ return None
60
+
61
+
62
+ def _check_name(value, what: str) -> str:
63
+ if not isinstance(value, str):
64
+ raise TypeError(f"{what} 名字必须是 str,收到 {type(value).__name__}")
65
+ name = value.strip()
66
+ if not name:
67
+ raise ValueError(f"{what} 名字不能为空")
68
+ return name
69
+
70
+
71
+ def _check_style(config_name: str, item_name: str, value) -> FrostStyle:
72
+ if not isinstance(value, FrostStyle):
73
+ raise TypeError(
74
+ f"配置 {config_name!r} 的 item {item_name!r} 必须是 FrostStyle,"
75
+ f"收到 {type(value).__name__}")
76
+ return value
77
+
78
+
79
+ class BackdropConfig:
80
+ """One named glass configuration: a set of ``item name -> FrostStyle``.
81
+
82
+ Instances belong to a :class:`Backdrop` (``config.owner``), which owns the
83
+ current mode and the ``normal`` fallback configuration. Built-in
84
+ ``normal`` / ``thin`` configurations are read-write: tune them in place or
85
+ build independent copies with :meth:`Backdrop.copyConfig`.
86
+ """
87
+
88
+ def __init__(self, owner: "Backdrop", name: str,
89
+ items: dict[str, FrostStyle] | None = None) -> None:
90
+ self._owner = owner
91
+ self._name = name
92
+ self._items: dict[str, FrostStyle] = {}
93
+ for item_name, value in (items or {}).items():
94
+ key = _check_name(item_name, "item")
95
+ self._items[key] = _check_style(name, key, value)
96
+
97
+ # -- identity ---------------------------------------------------------
98
+ @property
99
+ def name(self) -> str:
100
+ """Configuration name (``"normal"`` / ``"thin"`` / a custom one)."""
101
+ return self._name
102
+
103
+ @property
104
+ def owner(self) -> "Backdrop":
105
+ """The registry this configuration belongs to."""
106
+ return self._owner
107
+
108
+ def __repr__(self) -> str: # pragma: no cover - debugging aid
109
+ return (f"<BackdropConfig {self._name!r} "
110
+ f"items={list(self._items)!r}>")
111
+
112
+ # -- items ------------------------------------------------------------
113
+ def getItem(self, item_name: str) -> FrostStyle:
114
+ """Return the material for ``item_name`` under the current mode.
115
+
116
+ Resolution order (first hit wins):
117
+
118
+ 1. ``"<name>_<current mode>"`` in this configuration;
119
+ 2. ``"<name>_<other mode>"`` in this configuration;
120
+ 3. ``"<name>"`` (mode-independent item) in this configuration;
121
+ 4. the same three steps in the ``normal`` configuration.
122
+
123
+ A name that already carries ``_dark`` / ``_light`` is looked up
124
+ verbatim (step 1 and 4 only), so it never switches modes.
125
+ """
126
+ name = _check_name(item_name, "item")
127
+ variant = split_variant(name)
128
+ if variant is None:
129
+ mode = self._owner.mode
130
+ other = _other(mode)
131
+ keys = (f"{name}_{mode}", f"{name}_{other}", name)
132
+ else:
133
+ keys = (name,)
134
+ for config in self._chain():
135
+ for key in keys:
136
+ style = config._items.get(key)
137
+ if style is not None:
138
+ return style
139
+ available = ", ".join(self._items) or "(空)"
140
+ raise KeyError(
141
+ f"配置 {self._name!r} 没有 item {item_name!r}(当前有: {available})")
142
+
143
+ def addItem(self, item_name: str, value: FrostStyle) -> FrostStyle:
144
+ """Register a new item. Raises ``ValueError`` if the name exists."""
145
+ name = _check_name(item_name, "item")
146
+ style = _check_style(self._name, name, value)
147
+ if name in self._items:
148
+ raise ValueError(
149
+ f"配置 {self._name!r} 已有 item {name!r};覆盖请用 setItem()")
150
+ self._items[name] = style
151
+ self._owner._notify("item")
152
+ return style
153
+
154
+ def setItem(self, item_name: str, value: FrostStyle) -> FrostStyle:
155
+ """Add or overwrite an item (upsert), notifying live surfaces."""
156
+ name = _check_name(item_name, "item")
157
+ style = _check_style(self._name, name, value)
158
+ self._items[name] = style
159
+ self._owner._notify("item")
160
+ return style
161
+
162
+ def removeItem(self, item_name: str) -> None:
163
+ """Delete an item. Raises ``KeyError`` when it does not exist."""
164
+ name = _check_name(item_name, "item")
165
+ if name not in self._items:
166
+ raise KeyError(f"配置 {self._name!r} 没有 item {name!r}")
167
+ del self._items[name]
168
+ self._owner._notify("item")
169
+
170
+ def items(self) -> dict[str, FrostStyle]:
171
+ """Raw item mapping (exact names, shallow copy)."""
172
+ return dict(self._items)
173
+
174
+ def itemNames(self) -> tuple[str, ...]:
175
+ """Raw item names in insertion order."""
176
+ return tuple(self._items)
177
+
178
+ def hasItem(self, item_name: str) -> bool:
179
+ """Whether the *exact* item name exists (no mode / fallback lookup)."""
180
+ if not isinstance(item_name, str):
181
+ return False
182
+ return item_name.strip() in self._items
183
+
184
+ def copy(self, name: str) -> "BackdropConfig":
185
+ """Deep-copy this configuration under ``name`` (not registered)."""
186
+ return BackdropConfig(
187
+ self._owner, _check_name(name, "配置"),
188
+ {item_name: style.copy() for item_name, style in self._items.items()})
189
+
190
+ def __contains__(self, item_name) -> bool:
191
+ return self.hasItem(item_name)
192
+
193
+ def __len__(self) -> int:
194
+ return len(self._items)
195
+
196
+ def __iter__(self) -> Iterator[str]:
197
+ return iter(self._items)
198
+
199
+ # -- helpers ----------------------------------------------------------
200
+ def _chain(self) -> tuple["BackdropConfig", ...]:
201
+ """This configuration followed by the ``normal`` fallback."""
202
+ fallback = self._owner.normalConfig
203
+ return (self,) if self is fallback else (self, fallback)
204
+
205
+
206
+ class Backdrop:
207
+ """Registry of named glass configurations plus the current mode.
208
+
209
+ ``normal`` always exists and doubles as the fallback for every other
210
+ configuration. ``useConfig()`` selects the default configuration used by
211
+ surfaces that do not pin one (navigation views, content cards, flyouts).
212
+ """
213
+
214
+ def __init__(self, *, dark: bool = True) -> None:
215
+ self._dark = bool(dark)
216
+ self._configs: dict[str, BackdropConfig] = {}
217
+ self._listeners: list[Callable[[str], None]] = []
218
+ self._default: BackdropConfig = self.addConfig(_FALLBACK_NAME)
219
+
220
+ # -- mode -------------------------------------------------------------
221
+ @property
222
+ def mode(self) -> str:
223
+ """Current glass mode: ``"dark"`` or ``"light"``."""
224
+ return DARK if self._dark else LIGHT
225
+
226
+ def isDark(self) -> bool:
227
+ """Whether the current glass mode is dark."""
228
+ return self._dark
229
+
230
+ def setDark(self, dark: bool) -> bool:
231
+ """Switch the glass mode; returns whether it actually changed."""
232
+ dark = bool(dark)
233
+ if dark == self._dark:
234
+ return False
235
+ self._dark = dark
236
+ self._notify("theme")
237
+ return True
238
+
239
+ # -- configurations ---------------------------------------------------
240
+ def getConfig(self, name: str) -> BackdropConfig:
241
+ """Return the named configuration. Unknown names raise ``KeyError``."""
242
+ key = _check_name(name, "配置")
243
+ try:
244
+ return self._configs[key]
245
+ except KeyError:
246
+ available = ", ".join(self._configs) or "(空)"
247
+ raise KeyError(f"未知玻璃配置 {key!r}(可用: {available})") from None
248
+
249
+ def addConfig(self, name: str) -> BackdropConfig:
250
+ """Create an empty configuration. Duplicate names raise ``ValueError``."""
251
+ key = _check_name(name, "配置")
252
+ if key in self._configs:
253
+ raise ValueError(f"玻璃配置 {key!r} 已存在")
254
+ config = BackdropConfig(self, key)
255
+ self._configs[key] = config
256
+ self._notify("registry")
257
+ return config
258
+
259
+ def copyConfig(self, old_name, new_name: str) -> BackdropConfig:
260
+ """Register ``new_name`` as an independent deep copy of ``old_name``.
261
+
262
+ The copy owns copies of every :class:`FrostStyle`, so editing or
263
+ removing items on it never changes the source configuration. Its
264
+ fallback chain still points at the real ``normal`` configuration.
265
+ """
266
+ source = self._resolve(old_name)
267
+ key = _check_name(new_name, "配置")
268
+ if key in self._configs:
269
+ raise ValueError(f"玻璃配置 {key!r} 已存在")
270
+ config = source.copy(key)
271
+ self._configs[key] = config
272
+ self._notify("registry")
273
+ return config
274
+
275
+ def configs(self) -> tuple[str, ...]:
276
+ """Registered configuration names in insertion order."""
277
+ return tuple(self._configs)
278
+
279
+ @property
280
+ def defaultConfig(self) -> "BackdropConfig | None":
281
+ """Configuration currently used as the global default.
282
+
283
+ ``None`` means "no glass material": :meth:`useConfig` was called with
284
+ ``None``, so surfaces that follow the default switch window-level glass
285
+ off. Use :attr:`materialConfig` when a widget still needs a material.
286
+ """
287
+ return self._default
288
+
289
+ @property
290
+ def normalConfig(self) -> BackdropConfig:
291
+ """The ``normal`` configuration (fallback base for every lookup)."""
292
+ return self._configs[_FALLBACK_NAME]
293
+
294
+ @property
295
+ def materialConfig(self) -> BackdropConfig:
296
+ """Configuration used to resolve a material while glass is off.
297
+
298
+ With ``useConfig(None)`` the default is ``None`` (window-level glass is
299
+ off), but glass widgets still have to paint *something*; they resolve
300
+ their items against ``normal`` instead of failing.
301
+ """
302
+ return self._default if self._default is not None else self.normalConfig
303
+
304
+ def useConfig(self, config) -> "BackdropConfig | None":
305
+ """Make ``config`` (name or object) the global default configuration.
306
+
307
+ ``useConfig(None)`` means "no glass material": the default becomes
308
+ ``None`` and windows / navigation views that follow it switch their
309
+ window-level glass off (they reopen when a real configuration is used
310
+ again). Pass a name / :class:`BackdropConfig` to select a glass
311
+ configuration. All live glass surfaces are refreshed; use
312
+ ``TitleBarWindow.setGlassBackdrop()`` afterwards to pin a window.
313
+ """
314
+ resolved = None if config is None else self._resolve(config)
315
+ if self._default is resolved:
316
+ return resolved
317
+ self._default = resolved
318
+ self._notify("config")
319
+ return resolved
320
+
321
+ def __getattr__(self, name: str) -> BackdropConfig:
322
+ # ``backdrop.normal`` / ``backdrop.thin`` style access.
323
+ if name.startswith("_"):
324
+ raise AttributeError(name)
325
+ try:
326
+ return self._configs[name]
327
+ except KeyError:
328
+ available = ", ".join(self._configs) or "(空)"
329
+ raise AttributeError(
330
+ f"{type(self).__name__} 没有玻璃配置 {name!r}"
331
+ f"(可用: {available})") from None
332
+
333
+ def __repr__(self) -> str: # pragma: no cover - debugging aid
334
+ default = None if self._default is None else self._default.name
335
+ return (f"<Backdrop mode={self.mode!r} "
336
+ f"default={default!r} configs={list(self._configs)!r}>")
337
+
338
+ # -- observation ------------------------------------------------------
339
+ def addListener(self, callback: Callable[[str], None]):
340
+ """Subscribe to configuration changes; returns an unsubscribe callable.
341
+
342
+ ``callback`` receives one of ``"theme"`` (mode switch), ``"config"``
343
+ (``useConfig``), ``"item"`` (item added / changed / removed) or
344
+ ``"registry"`` (configuration added). Listeners are plain Python
345
+ callables so this module never depends on a Qt application instance.
346
+ """
347
+ if not callable(callback):
348
+ raise TypeError("listener 必须是可调用对象")
349
+ self._listeners.append(callback)
350
+
351
+ def unsubscribe() -> None:
352
+ try:
353
+ self._listeners.remove(callback)
354
+ except ValueError:
355
+ pass
356
+
357
+ return unsubscribe
358
+
359
+ def _resolve(self, value) -> BackdropConfig:
360
+ if isinstance(value, BackdropConfig):
361
+ if value.owner is not self:
362
+ raise ValueError("该玻璃配置属于另一个 Backdrop,不能在这里使用")
363
+ return value
364
+ return self.getConfig(value)
365
+
366
+ def _notify(self, reason: str) -> None:
367
+ for callback in tuple(self._listeners):
368
+ try:
369
+ callback(reason)
370
+ except RuntimeError:
371
+ # Qt object 已销毁:刷新失败不影响配置本身。
372
+ continue
373
+ except Exception: # pragma: no cover - 监听器里的意外错误
374
+ traceback.print_exc()
375
+
376
+
377
+ __all__ = ["DARK", "LIGHT", "Backdrop", "BackdropConfig", "split_variant"]
@@ -0,0 +1,215 @@
1
+ """内置玻璃配置仓库:``backdrop = Backdrop()``。
2
+
3
+ 每个具名配置由若干 item 组成,item 的值是 :class:`~.settings.FrostStyle`:
4
+
5
+ * ``normal`` —— 默认配置,也是所有配置的**兜底基准**;
6
+ * ``thin`` —— 轻薄配置,只覆盖背景 / 侧边栏,flyout 回退到 ``normal``。
7
+
8
+ item 名字含义(``bg`` = 内容区整窗玻璃,``sidebar`` = 侧边栏 / 标题栏玻璃):
9
+
10
+ * ``bg_dark`` / ``bg_light`` —— 暗色 / 亮色模式的内容区玻璃;
11
+ * ``sidebar_dark`` / ``sidebar_light`` —— 暗色 / 亮色模式的侧边栏玻璃;
12
+ * ``flyout_dark`` / ``flyout_light`` —— 导航 flyout 玻璃(只有 ``normal`` 定义);
13
+ * ``flyout_fold_dark`` / ``flyout_fold_light`` —— 折叠子菜单 flyout 玻璃。
14
+
15
+ 取值规则见 :meth:`bubble.glasskit.backdrop.BackdropConfig.getItem`:先找当前
16
+ 模式的变体,再找另一模式的变体,再找无后缀 item,最后回退到 ``normal`` 的
17
+ 同名 kind(``bg`` 不会拿到 ``sidebar`` 的材质)。
18
+
19
+ 用法::
20
+
21
+ from bubble.glasskit import backdrop
22
+
23
+ backdrop.normal.getItem("sidebar") # 当前主题的侧边栏玻璃
24
+ backdrop.thin.setItem("bg_dark", ...) # 内置配置可读写
25
+ backdrop.copyConfig("normal", "acrylic") # 独立副本
26
+ backdrop.useConfig("thin") # 全局切换(已打开窗口立即刷新)
27
+ backdrop.useConfig(None) # 不用玻璃材质(关闭窗口级玻璃)
28
+ backdrop.setDark(True) # 切换亮暗(apply_glass_theme 内部调用)
29
+ """
30
+
31
+ from .backdrop import Backdrop, BackdropConfig
32
+ from .settings import (
33
+ BACKGROUND_WALLPAPER,
34
+ FrostStyle,
35
+ GlassRuntimeSettings,
36
+ )
37
+
38
+ RUNTIME = GlassRuntimeSettings(
39
+ background_mode=BACKGROUND_WALLPAPER,
40
+ fps=0,
41
+ gpu=False,
42
+ auto_energy_on_focus_loss=True,
43
+ transition_ms=250,
44
+ respect_system_transparency=True,
45
+ )
46
+ CAPTURE_SCALE = 0.5 # region capture scale; 1.0 = sharper, more CPU
47
+
48
+ # ---------------------------------------------------------------------------
49
+ # 玻璃配置仓库
50
+ # ---------------------------------------------------------------------------
51
+ #: 全局配置仓库。内置 ``normal`` / ``thin`` 可读写;主题亮暗由
52
+ #: :meth:`Backdrop.setDark` 维护(``bubble.navigate.apply_glass_theme`` 会调用),
53
+ #: 默认与 ``ColorModeManager`` 的初始暗色一致。
54
+ backdrop = Backdrop(dark=True)
55
+
56
+ # -- normal:默认配置(同时是兜底基准)-------------------------------------
57
+ _normal = backdrop.normalConfig
58
+
59
+ #: 内容区整窗玻璃(暗 / 亮)。
60
+ _normal.addItem("bg_dark", FrostStyle(
61
+ tint="#272727",
62
+ opacity=90,
63
+ blur=96,
64
+ frost=0,
65
+ noise=0,
66
+ sheen=0,
67
+ saturation=50,
68
+ brightness=95,
69
+ ))
70
+ _normal.addItem("bg_light", FrostStyle(
71
+ tint="#f9f9f9",
72
+ opacity=90,
73
+ blur=96,
74
+ frost=0,
75
+ noise=0,
76
+ sheen=0,
77
+ saturation=50,
78
+ brightness=100,
79
+ ))
80
+
81
+ #: 侧边栏 / 标题栏玻璃(暗 / 亮)。
82
+ _normal.addItem("sidebar_dark", FrostStyle(
83
+ tint="#202020",
84
+ opacity=80,
85
+ blur=108,
86
+ frost=0,
87
+ noise=0,
88
+ sheen=0,
89
+ saturation=85,
90
+ brightness=60,
91
+ ))
92
+ _normal.addItem("sidebar_light", FrostStyle(
93
+ tint="#f3f3f3",
94
+ opacity=95,
95
+ blur=96,
96
+ frost=0,
97
+ noise=0,
98
+ sheen=0,
99
+ saturation=80,
100
+ brightness=100,
101
+ ))
102
+
103
+ #: 导航 flyout 玻璃(圆角 4px)。
104
+ _normal.addItem("flyout_dark", FrostStyle(
105
+ tint="#2e2e2e",
106
+ opacity=58,
107
+ blur=40,
108
+ frost=18,
109
+ noise=6,
110
+ sheen=14,
111
+ saturation=95,
112
+ brightness=105,
113
+ border=24,
114
+ radius=4,
115
+ vignette=6,
116
+ ))
117
+ _normal.addItem("flyout_light", FrostStyle(
118
+ tint="#f3f3f3",
119
+ opacity=58,
120
+ blur=40,
121
+ frost=18,
122
+ noise=6,
123
+ sheen=14,
124
+ saturation=95,
125
+ brightness=105,
126
+ border=24,
127
+ radius=4,
128
+ vignette=6,
129
+ ))
130
+
131
+ #: 折叠项子菜单 flyout 专用玻璃。
132
+ _normal.addItem("flyout_fold_dark", FrostStyle(
133
+ tint="#202020",
134
+ opacity=65,
135
+ blur=30,
136
+ frost=4,
137
+ noise=2,
138
+ sheen=3,
139
+ saturation=95,
140
+ brightness=105,
141
+ border=24,
142
+ radius=4,
143
+ vignette=6,
144
+ ))
145
+ _normal.addItem("flyout_fold_light", FrostStyle(
146
+ tint="#f3f3f3",
147
+ opacity=65,
148
+ blur=30,
149
+ frost=4,
150
+ noise=2,
151
+ sheen=3,
152
+ saturation=95,
153
+ brightness=105,
154
+ border=24,
155
+ radius=4,
156
+ vignette=6,
157
+ ))
158
+
159
+ # -- thin:轻薄配置 --------------------------------------------------------
160
+ # flyout 不在这里定义:``thin.getItem("flyout")`` 会回退到 ``normal`` 的
161
+ # ``flyout_dark`` / ``flyout_light``。
162
+ _thin = backdrop.addConfig("thin")
163
+
164
+ _thin.addItem("bg_dark", FrostStyle(
165
+ tint="#202020",
166
+ energy_tint="#272727",
167
+ opacity=90,
168
+ blur=96,
169
+ frost=0,
170
+ noise=0,
171
+ sheen=0,
172
+ saturation=50,
173
+ brightness=95,
174
+ ))
175
+ _thin.addItem("bg_light", FrostStyle(
176
+ tint="#f3f3f3",
177
+ opacity=60,
178
+ blur=24,
179
+ frost=20,
180
+ noise=0,
181
+ sheen=15,
182
+ saturation=100,
183
+ brightness=105,
184
+ ))
185
+
186
+ _thin.addItem("sidebar_dark", FrostStyle(
187
+ tint="#101010",
188
+ energy_tint="#202020",
189
+ opacity=60,
190
+ blur=128,
191
+ frost=0,
192
+ noise=0,
193
+ sheen=0,
194
+ saturation=70,
195
+ brightness=55,
196
+ ))
197
+ _thin.addItem("sidebar_light", FrostStyle(
198
+ tint="#ffffff",
199
+ energy_tint="#f3f3f3",
200
+ opacity=60,
201
+ blur=128,
202
+ frost=0,
203
+ noise=0,
204
+ sheen=00,
205
+ saturation=70,
206
+ brightness=80,
207
+ ))
208
+
209
+ __all__ = [
210
+ "RUNTIME",
211
+ "CAPTURE_SCALE",
212
+ "Backdrop",
213
+ "BackdropConfig",
214
+ "backdrop",
215
+ ]