mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
Add WidgetGallery to debug dialog
This commit is contained in:
parent
0f0c243aa1
commit
b32482f168
4 changed files with 72 additions and 9 deletions
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>643</width>
|
||||
<height>580</height>
|
||||
<height>582</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -48,6 +48,9 @@
|
|||
<property name="lineWrapMode">
|
||||
<enum>QPlainTextEdit::NoWrap</enum>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string notr="true">Type commands here (Enter to submit)</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPlainTextEdit" name="log">
|
||||
<property name="sizePolicy">
|
||||
|
@ -68,9 +71,28 @@
|
|||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string notr="true">Output</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string notr="true">Styling</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="widgetsButton">
|
||||
<property name="text">
|
||||
<string notr="true">Qt Widget Gallery</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
|
|
@ -1619,6 +1619,8 @@ title="{}" {}>{}</button>""".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="{}" {}>{}</button>""".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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue