From b32482f1685eb6d76cfc6f6dcb61d6134d90a9d3 Mon Sep 17 00:00:00 2001
From: Matthias Metelka <62722460+kleinerpirat@users.noreply.github.com>
Date: Thu, 29 Dec 2022 00:16:00 +0100
Subject: [PATCH] Add WidgetGallery to debug dialog
---
qt/aqt/forms/debug.ui | 24 +++++++++++++++++++++++-
qt/aqt/main.py | 8 ++++++++
qt/aqt/profiles.py | 33 ++++++++++++++++++++++++++++-----
qt/aqt/theme.py | 16 +++++++++++++---
4 files changed, 72 insertions(+), 9 deletions(-)
diff --git a/qt/aqt/forms/debug.ui b/qt/aqt/forms/debug.ui
index 5767301ac..898a42329 100644
--- a/qt/aqt/forms/debug.ui
+++ b/qt/aqt/forms/debug.ui
@@ -7,7 +7,7 @@
0
0
643
- 580
+ 582
@@ -48,6 +48,9 @@
QPlainTextEdit::NoWrap
+
+ Type commands here (Enter to submit)
+
@@ -68,9 +71,28 @@
true
+
+ Output
+
+ -
+
+
+ Styling
+
+
+
-
+
+
+ Qt Widget Gallery
+
+
+
+
+
+
diff --git a/qt/aqt/main.py b/qt/aqt/main.py
index e0a7a688c..fd5ac5c5d 100644
--- a/qt/aqt/main.py
+++ b/qt/aqt/main.py
@@ -1619,6 +1619,8 @@ title="{}" {}>{}""".format(
s = self.debugDiagShort = QShortcut(QKeySequence("ctrl+shift+l"), d)
qconnect(s.activated, frm.text.clear)
+ qconnect(frm.widgetsButton.clicked, self._on_widgetGallery)
+
def addContextMenu(
ev: Union[QCloseEvent, QContextMenuEvent], name: str
) -> None:
@@ -1640,6 +1642,12 @@ title="{}" {}>{}""".format(
gui_hooks.debug_console_will_show(d)
d.show()
+ def _on_widgetGallery(self) -> None:
+ from aqt.widgetgallery import WidgetGallery
+
+ self.widgetGallery = WidgetGallery(self)
+ self.widgetGallery.show()
+
def _captureOutput(self, on: bool) -> None:
mw2 = self
diff --git a/qt/aqt/profiles.py b/qt/aqt/profiles.py
index 1b377894f..335df1758 100644
--- a/qt/aqt/profiles.py
+++ b/qt/aqt/profiles.py
@@ -23,7 +23,7 @@ from anki.sync import SyncAuth
from anki.utils import int_time, is_mac, is_win, point_version
from aqt import appHelpSite
from aqt.qt import *
-from aqt.theme import Theme, theme_manager
+from aqt.theme import AnkiStyles, Theme, theme_manager
from aqt.utils import disable_help_button, send_to_trash, showWarning, tr
if TYPE_CHECKING:
@@ -540,11 +540,34 @@ create table if not exists profiles
def set_theme(self, theme: Theme) -> None:
self.meta["theme"] = theme.value
- def force_custom_styles(self) -> bool:
- return self.meta.get("force_custom_styles", False)
+ def set_forced_style(self, style: AnkiStyles | None) -> None:
+ if style:
+ self.meta[f"force_{AnkiStyles(style).name.lower()}_styles"] = True
- def set_force_custom_styles(self, enabled: bool) -> None:
- self.meta["force_custom_styles"] = enabled
+ for member in AnkiStyles:
+ if member != style:
+ self.meta[f"force_{AnkiStyles(member).name.lower()}_styles"] = False
+
+ theme_manager.apply_style()
+
+ def has_forced_style(self) -> bool:
+ for member in AnkiStyles:
+ if self.meta[f"force_{AnkiStyles(member).name.lower()}_styles"]:
+ return True
+ return False
+
+ # These getters are used by ThemeManager
+ def unset_forced_styles(self) -> None:
+ self.set_forced_style(None)
+
+ def force_anki_styles(self) -> bool:
+ return self.meta.get("force_anki_styles", False)
+
+ def force_fusion_styles(self) -> bool:
+ return self.meta.get("force_fusion_styles", False)
+
+ def force_native_styles(self) -> bool:
+ return self.meta.get("force_native_styles", False)
def browser_layout(self) -> BrowserLayout:
from aqt.browser.layout import BrowserLayout
diff --git a/qt/aqt/theme.py b/qt/aqt/theme.py
index 20df25cef..9352bbf5c 100644
--- a/qt/aqt/theme.py
+++ b/qt/aqt/theme.py
@@ -43,6 +43,12 @@ class ColoredIcon:
return ColoredIcon(path=self.path, color=color)
+class AnkiStyles(enum.IntEnum):
+ ANKI = 0
+ FUSION = 1
+ NATIVE = 2
+
+
class Theme(enum.IntEnum):
FOLLOW_SYSTEM = 0
LIGHT = 1
@@ -230,9 +236,11 @@ class ThemeManager:
def _apply_style(self, app: QApplication) -> None:
from aqt.stylesheets import splitter_styles
- buf = splitter_styles(self)
+ buf = splitter_styles(self) if not aqt.mw.pm.force_native_styles() else ""
- if not is_mac or aqt.mw.pm.force_custom_styles():
+ if aqt.mw.pm.force_anki_styles() or not (
+ aqt.mw.pm.force_native_styles() or aqt.mw.pm.force_fusion_styles() or is_mac
+ ):
from aqt.stylesheets import (
button_styles,
checkbox_styles,
@@ -267,7 +275,9 @@ class ThemeManager:
def _apply_palette(self, app: QApplication) -> None:
set_macos_dark_mode(self.night_mode)
- if is_mac and not (qtmajor == 5 or aqt.mw.pm.force_custom_styles()):
+ if aqt.mw.pm.force_native_styles() or (
+ is_mac and not (qtmajor == 5 or aqt.mw.pm.force_anki_styles())
+ ):
app.setStyle(QStyleFactory.create(self._default_style)) # type: ignore
self.default_palette.setColor(
QPalette.ColorRole.Window, self.qcolor(colors.CANVAS)