use night mode when dark mode active, using standard macOS theme

This commit is contained in:
Damien Elmes 2020-01-31 13:14:16 +10:00
parent 1552c34bea
commit c42e118339
3 changed files with 33 additions and 3 deletions

View File

@ -5,6 +5,8 @@
import platform
from typing import Dict
import darkdetect
from anki.utils import isMac
from aqt import QApplication, gui_hooks, isWin
from aqt.colors import colors
@ -12,11 +14,21 @@ from aqt.qt import QColor, QIcon, QPalette, QPixmap, QStyleFactory, Qt
class ThemeManager:
night_mode = True
_night_mode_preference = False
_icon_cache: Dict[str, QIcon] = {}
_icon_size = 128
def macos_dark_mode(self) -> bool:
return darkdetect.isDark() is True
def get_night_mode(self) -> bool:
return self.macos_dark_mode() or self._night_mode_preference
def set_night_mode(self, val: bool) -> None:
self._night_mode_preference = val
night_mode = property(get_night_mode, set_night_mode)
def icon_from_resources(self, path: str) -> QIcon:
"Fetch icon from Qt resources, and invert if in night mode."
icon = self._icon_cache.get(path)
@ -109,7 +121,8 @@ QGroupBox {
if not self.night_mode:
return
app.setStyle(QStyleFactory.create("fusion")) # type: ignore
if not self.macos_dark_mode():
app.setStyle(QStyleFactory.create("fusion")) # type: ignore
palette = QPalette()

View File

@ -44,5 +44,6 @@ setuptools.setup(
"jsonschema",
'psutil; sys.platform == "win32"',
'pywin32; sys.platform == "win32"',
'darkdetect; sys.platform == "darwin"',
],
)

View File

@ -43,3 +43,19 @@
background: vars.$fusion-button-hover-bg;
}
}
/* imitate standard macOS dark mode buttons */
.isMac.nightMode button:not(.linkb) {
background: #656565;
box-shadow: 0 1px 2px #222222;
border-top-color: #848484;
border-top-width: 0.5px;
border-bottom: 0;
border-left: 0;
border-right: 0;
padding-top: 2px;
padding-bottom: 2px;
padding-left: 15px;
padding-right: 15px;
color: #e5e5e5;
}