Skip to content

Commit a5e1a8f

Browse files
authored
Sync with Mac accent color (#219)
1 parent 1f2dd88 commit a5e1a8f

28 files changed

+255
-61
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ repos:
4141
hooks:
4242
- id: check-jsonschema
4343
name: Validate color map json files with json schema
44-
files: ^style/colors
45-
exclude: ^style/colors/validate.json$
46-
args: ["--schemafile", "style/colors/validate.json"]
44+
files: ^style/colors/themes
45+
exclude: ^style/colors/themes/validate.json$
46+
args: ["--schemafile", "style/colors/themes/validate.json"]
4747

4848
- repo: https://github.com/asottile/pyupgrade
4949
rev: v3.2.2

.vscode/settings.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"json.schemas": [
33
{
44
"fileMatch": [
5-
"/style/colors/*"
5+
"/style/colors/themes/*"
66
],
7-
"url": "/style/colors/validate.json"
7+
"url": "/style/colors/themes/validate.json"
88
}
99
],
1010
"python.testing.pytestEnabled": true,
@@ -18,23 +18,28 @@
1818
"cSpell.words": [
1919
"AARRGGBB",
2020
"absolufy",
21+
"alloc",
2122
"argb",
2223
"autofix",
24+
"Autorelease",
2325
"backticks",
2426
"cmpfiles",
2527
"codecov",
2628
"darkdetect",
2729
"docstrings",
2830
"Duquesnoy",
2931
"filecmp",
32+
"HIGHDPI",
3033
"isort",
3134
"jakebailey",
3235
"jsonschema",
3336
"kargs",
37+
"libobjc",
3438
"linebreak",
3539
"markdownlint",
3640
"maxdepth",
3741
"ncipollo",
42+
"objc",
3843
"Pixmap",
3944
"Pixmaps",
4045
"pydata",

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Check out the [complete documentation](https://pyqtdarktheme.readthedocs.io).
2121
- A flat dark and light theme
2222
- Support PySide and PyQt
2323
- Support PyInstaller
24-
- Sync with OS's theme (Mac, Windows, Linux)
24+
- Sync with OS's theme and accent (Mac, Windows, Linux)
2525
- Resolve the style differences between Qt versions
2626
- Provide dark/light theme QPalette
2727
- Override Qt old standard icons
@@ -99,14 +99,17 @@ For Qt6 bindings, HiDPI “just works” without using this function.
9999
qdarktheme.setup_theme("light")
100100
```
101101

102-
### Sync with OS's theme
102+
### Sync with OS's theme and accent
103103

104104
```Python
105105
qdarktheme.setup_theme("auto")
106106
```
107107

108108
![sync with os theme](https://raw.githubusercontent.com/5yutan5/PyQtDarkTheme/main/images/sync_with_os_theme.gif)
109109

110+
On macOS, qdarktheme also syncs with accent colors.
111+
![sync with os accent](https://raw.githubusercontent.com/5yutan5/PyQtDarkTheme/main/images/sync_with_os_accent.gif)
112+
110113
### Customizing colors
111114

112115
You can customize theme color.
@@ -148,7 +151,7 @@ python -m qdarktheme.widget_gallery
148151

149152
## License
150153

151-
The svg files for the PyQtDarkTheme are derived [Material design icons](https://fonts.google.com/icons)(Apache License Version 2.0). Qt stylesheets are originally fork of [QDarkStyleSheet](https://github.com/ColinDuquesnoy/QDarkStyleSheet)(MIT License). Other files are covered by PyQtDarkTheme's MIT license.
154+
The svg files for the PyQtDarkTheme are derived [Material design icons](https://fonts.google.com/icons)(Apache License Version 2.0). Qt stylesheets are originally fork of [QDarkStyleSheet](https://github.com/ColinDuquesnoy/QDarkStyleSheet)(MIT License). Other files are covered by PyQtDarkTheme's MIT license. The accent detector(qdarktheme/_os_appearance/_accent/_mac_detect) is inspired by [darkdetect](https://github.com/albertosottile/darkdetect)(3-clause BSD License).
152155

153156
## Contributing
154157

docs/source/how_to_use.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ If you want to enable HiDPI, you can use ``qdarktheme.enable_hi_dpi()``. For Qt6
4242
Toggle dark/light Theme
4343
-----------------------
4444

45-
If you add ``theme`` argument as "auto", your Qt Application sync with OS's theme.
45+
If you add ``theme`` argument as "auto", your Qt Application sync with OS's theme. On macOS, qdarktheme also syncs with accent colors.
4646

4747
.. tab-set::
4848

docs/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ PyQtDarkTheme applies a flat dark theme to QtWidgets application(PySide and PyQt
2525

2626
* A flat dark/light theme
2727
* Support PySide, PyQt and PyInstaller
28-
* Sync with OS's theme (Mac, Windows, Linux)
28+
* Sync with OS's theme and accent (Mac, Windows, Linux)
2929
* Resolve the style differences between Qt versions
3030
* Provide dark/light theme QPalette
3131
* :ref:`Override Qt old standard icons <how_to_use:Use overridden Qt default icons>`.

images/sync_with_os_accent.gif

65.1 MB
Loading

images/sync_with_os_theme.gif

11.9 MB
Loading

qdarktheme/_icon/svg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@lru_cache()
1212
def _svg_resources() -> dict[str, str]:
13-
return json.loads(_resources.SVG_RESOURCES)
13+
return json.loads(_resources.svg.SVG_RESOURCES)
1414

1515

1616
class Svg:

qdarktheme/_main.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ def _apply_style(app, additional_qss: str | None, **kargs) -> None:
3636

3737

3838
def _sync_theme_with_system(app, callback) -> None:
39-
from qdarktheme._theme_listener import OSThemeSwitchListener
39+
from qdarktheme._os_appearance import listener
4040

4141
global _listener
4242
if _listener is not None:
4343
_listener.sig_run.emit(True)
4444
return
4545

46-
_listener = OSThemeSwitchListener(callback)
46+
_listener = listener.OSThemeSwitchListener(callback)
4747

4848
if platform.system() == "Darwin":
4949
app.installEventFilter(_listener)
@@ -100,9 +100,10 @@ def setup_theme(
100100
101101
Args:
102102
theme: The theme name. There are `dark`, `light` and `auto`.
103-
If ``auto``, try to sync with system theme.
104-
If failed to detect system theme,
105-
use the theme set in argument ``default_theme``.
103+
If ``auto``, try to sync with system theme and accent(only on Mac).
104+
If failed to detect system theme, use the theme set in argument ``default_theme``.
105+
When primary color including child color(eg. ``primary>selection.background``) set to
106+
custom_colors, disable to sync with accent.
106107
corner_shape: The corner shape. There are `rounded` and `sharp` shape.
107108
custom_colors: The custom color map. Overrides the default color for color id you set.
108109
Also you can customize a specific theme only. See example 5.

qdarktheme/_os_appearance/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from qdarktheme._os_appearance._accent import accent

0 commit comments

Comments
 (0)