* Fix button focus highlight on Windows
* Use none instead of none for outline and box-shadow
* Unnest selectors in reviewer-bottom
Co-authored-by: Henrik Giesel <hengiesel@gmail.com>
* Make webview zoom optional
Also suppress mouse wheel zooming.
* Disable zoom for top and bottom bars in main view
* Factor in macos zoom by scrolling and refactor
* Support drag & drop in main window to import files
* Pass drag & drop events to super when not in deck browser
Seems this is required so that JS in the reviewer receives dragover
* Remove unused allowDrops
Fixes#983
This has been a long-standing issue that was infrequent enough on
developer machines that we weren't able to get to the bottom of it before
now. As luck would have it, the new ARM build had just the right timing
for this to occur every few invocations, and I was able to narrow it down
to the call that turns off the cache.
We don't really want the cache, so this is not a great solution. But I
ran into trouble when trying to figure out a better solution:
- Calling setHttpCacheType() earlier (eg immediately after creating the
page) fails.
- It even fails if you attempt to change the setting in the shared
default profile before any webviews are loaded:
```
def setupMainWindow(self) -> None:
QWebEngineProfile.defaultProfile().setHttpCacheType(QWebEngineProfile.HttpCacheType.NoCache)
```
- Creating a profile separately, and passing it into QWebEnginePage()
does work. But it introduces a warning each time a webview is deallocated,
and I fear it may lead to crashes:
```
Release of profile requested but WebEnginePage still not deleted. Expect troubles !
```
I tried various combinations of parents for the profile and page, and
turning web._page into an unretained property, but could not figure it out.
Some Googling pulls up a bunch of other people who seem to have hit similar
issues with PyQt. If anyone has any ideas, they'd be welcome; in the mean
time, I guess we're better off using up some of the user's disk
space than sometimes failing to load.
The profile-in-advance code I tried is below:
```
diff --git a/qt/aqt/webview.py b/qt/aqt/webview.py
index 1c96112d8..4f3e91284 100644
--- a/qt/aqt/webview.py
+++ b/qt/aqt/webview.py
@@ -23,9 +23,49 @@ serverbaseurl = re.compile(r"^.+:\/\/[^\/]+")
BridgeCommandHandler = Callable[[str], Any]
+def _create_profile(parent: QObject) -> QWebEngineProfile:
+ qwebchannel = ":/qtwebchannel/qwebchannel.js"
+ jsfile = QFile(qwebchannel)
+ if not jsfile.open(QIODevice.OpenModeFlag.ReadOnly):
+ print(f"Error opening '{qwebchannel}': {jsfile.error()}", file=sys.stderr)
+ jstext = bytes(cast(bytes, jsfile.readAll())).decode("utf-8")
+ jsfile.close()
+
+ script = QWebEngineScript()
+ script.setSourceCode(
+ jstext
+ + """
+ var pycmd, bridgeCommand;
+ new QWebChannel(qt.webChannelTransport, function(channel) {
+ bridgeCommand = pycmd = function (arg, cb) {
+ var resultCB = function (res) {
+ // pass result back to user-provided callback
+ if (cb) {
+ cb(JSON.parse(res));
+ }
+ }
+
+ channel.objects.py.cmd(arg, resultCB);
+ return false;
+ }
+ pycmd("domDone");
+ });
+ """
+ )
+ script.setWorldId(QWebEngineScript.ScriptWorldId.MainWorld)
+ script.setInjectionPoint(QWebEngineScript.InjectionPoint.DocumentReady)
+ script.setRunsOnSubFrames(False)
+
+ profile = QWebEngineProfile(parent)
+ profile.setHttpCacheType(QWebEngineProfile.HttpCacheType.NoCache)
+ profile.scripts().insert(script)
+ return profile
+
+
class AnkiWebPage(QWebEnginePage):
- def __init__(self, onBridgeCmd: BridgeCommandHandler) -> None:
- QWebEnginePage.__init__(self)
+ def __init__(self, onBridgeCmd: BridgeCommandHandler, parent: QObject) -> None:
+ profile = _create_profile(parent)
+ QWebEnginePage.__init__(self, profile, parent)
self._onBridgeCmd = onBridgeCmd
self._setupBridge()
self.open_links_externally = True
@@ -46,39 +86,6 @@ class AnkiWebPage(QWebEnginePage):
self._channel.registerObject("py", self._bridge)
self.setWebChannel(self._channel)
- qwebchannel = ":/qtwebchannel/qwebchannel.js"
- jsfile = QFile(qwebchannel)
- if not jsfile.open(QIODevice.OpenModeFlag.ReadOnly):
- print(f"Error opening '{qwebchannel}': {jsfile.error()}", file=sys.stderr)
- jstext = bytes(cast(bytes, jsfile.readAll())).decode("utf-8")
- jsfile.close()
-
- script = QWebEngineScript()
- script.setSourceCode(
- jstext
- + """
- var pycmd, bridgeCommand;
- new QWebChannel(qt.webChannelTransport, function(channel) {
- bridgeCommand = pycmd = function (arg, cb) {
- var resultCB = function (res) {
- // pass result back to user-provided callback
- if (cb) {
- cb(JSON.parse(res));
- }
- }
-
- channel.objects.py.cmd(arg, resultCB);
- return false;
- }
- pycmd("domDone");
- });
- """
- )
- script.setWorldId(QWebEngineScript.ScriptWorldId.MainWorld)
- script.setInjectionPoint(QWebEngineScript.InjectionPoint.DocumentReady)
- script.setRunsOnSubFrames(False)
- self.profile().scripts().insert(script)
-
def javaScriptConsoleMessage(
self,
level: QWebEnginePage.JavaScriptConsoleMessageLevel,
@@ -228,7 +235,7 @@ class AnkiWebView(QWebEngineView):
) -> None:
QWebEngineView.__init__(self, parent=parent)
self.set_title(title)
- self._page = AnkiWebPage(self._onBridgeCmd)
+ self._page = AnkiWebPage(self._onBridgeCmd, self)
self._page.setBackgroundColor(
self.get_window_bg_color(theme_manager.night_mode)
@@ -242,7 +249,6 @@ class AnkiWebView(QWebEngineView):
self.requiresCol = True
self.setPage(self._page)
- self._page.profile().setHttpCacheType(QWebEngineProfile.HttpCacheType.NoCache)
self.resetHandlers()
self.allowDrops = False
self._filterSet = False
```
* Flip arrows of Bootstrap-styled <select>s for RTL langs
* Use the dir attribute to set document direction
* Remove unused variable and fix use of CSS var
* Allow theme change at runtime and add hook
* Save or restore default palette on theme change
* Update aqt widget styles on theme change
* styling fixes
- drop _light_palette, as default_palette serves the same purpose
- save default platform theme, and restore it when switching away
from nightmode
- update macOS light/dark mode on theme switch
- fix unreadable menus on Windows
* update night-mode classes on theme change
This is the easy part - CSS styling that uses standard_css or our
css variables should update automatically. The main remaining issue
is JS code that sets colors based on the theme at the time it's run -
eg the graph code, and the editor.
* switch night mode value on toggle
* expose current theme via a store; switch graphs to use it
https://github.com/ankitects/anki/issues/1471#issuecomment-972402492
* start using currentTheme in editor/components
This fixes basic editing - there are still components that need updating.
* add simple xcodeproj for code completion
* add helper to get currently-active system theme on macOS
* fix setCurrentTheme not being immediately available
* live update tag color
* style().name() doesn't work on Qt5
* automatic theme switching on Windows/Mac
* currentTheme -> pageTheme
* Replace `nightModeKey` with `pageTheme`
Co-authored-by: Damien Elmes <gpg@ankiweb.net>
* PEP8 dbproxy.py
* PEP8 errors.py
* PEP8 httpclient.py
* PEP8 lang.py
* PEP8 latex.py
* Add decorator to deprectate key words
* Make replacement for deprecated attribute optional
* Use new helper `_print_replacement_warning()`
* PEP8 media.py
* PEP8 rsbackend.py
* PEP8 sound.py
* PEP8 stdmodels.py
* PEP8 storage.py
* PEP8 sync.py
* PEP8 tags.py
* PEP8 template.py
* PEP8 types.py
* Fix DeprecatedNamesMixinForModule
The class methods need to be overridden with instance methods, so every
module has its own dicts.
* Use `# pylint: disable=invalid-name` instead of id
* PEP8 utils.py
* Only decorate `__getattr__` with `@no_type_check`
* Fix mypy issue with snakecase
Importing it from `anki._vendor` raises attribute errors.
* Format
* Remove inheritance of DeprecatedNamesMixin
There's almost no shared code now and overriding classmethods with
instance methods raises mypy issues.
* Fix traceback frames of deprecation warnings
* remove fn/TimedLog (dae)
Neither Anki nor add-ons appear to have been using it
* fix some issues with stringcase use (dae)
- the wheel was depending on the PyPI version instead of our vendored
version
- _vendor:stringcase should not have been listed in the anki py_library.
We already include the sources in py_srcs, and need to refer to them
directly. By listing _vendor:stringcase as well, we were making a
top-level stringcase library available, which would have only worked for
distributing because the wheel definition was also incorrect.
- mypy errors are what caused me to mistakenly add the above - they
were because the type: ignore at the top of stringcase.py was causing
mypy to completely ignore the file, so it was not aware of any attributes
it contained.
The enum changes should work on PyQt 5.x, and are required in PyQt 6.x.
They are not supported by the PyQt5 typings however, so we need to run
our tests with PyQt6.
This reverts commit 54f51da944.
This breaks in the PyQt6 upgrade. There are no globals anymore, only
page profiles - but the code should probably be modifying a specific
webview instead of globals anyway.
This adds Python 3.9 and 3.10 typing syntax to files that import
attributions from __future___. Python 3.9 should be able to cope with
the 3.10 syntax, but Python 3.8 will no longer work.
On Windows/Mac, install the latest Python 3.9 version from python.org.
There are currently no orjson wheels for Python 3.10 on Windows/Mac,
which will break the build unless you have Rust installed separately.
On Linux, modern distros should have Python 3.9 available already. If
you're on an older distro, you'll need to build Python from source first.
including the following changes:
- rename "_getWindowColor" to "get_window_bg_color" to follow PEP8
- add "night_mode" argument to "get_window_bg_color"
- make it possible to get the correct colors regardless of the current theme
The default 1 rem is fine, but we need to apply the default font size
to the html element instead of the body for the definition of rem to
update.
Fixes#1174