mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
Workaround for AltGr '@' issue.
This commit is contained in:
parent
039f6bb382
commit
1e433a7cdd
1 changed files with 35 additions and 0 deletions
|
@ -84,6 +84,30 @@ class AnkiWebPage(QWebEnginePage):
|
||||||
def _onCmd(self, str):
|
def _onCmd(self, str):
|
||||||
return self._onBridgeCmd(str)
|
return self._onBridgeCmd(str)
|
||||||
|
|
||||||
|
def runJavaScriptSync(page, js, timeout=500):
|
||||||
|
result = None
|
||||||
|
eventLoop = QEventLoop()
|
||||||
|
called = False
|
||||||
|
|
||||||
|
def callback(val):
|
||||||
|
nonlocal result, called
|
||||||
|
result = val
|
||||||
|
called = True
|
||||||
|
eventLoop.quit()
|
||||||
|
|
||||||
|
page.runJavaScript(js, callback)
|
||||||
|
|
||||||
|
if not called:
|
||||||
|
timer = QTimer()
|
||||||
|
timer.setSingleShot(True)
|
||||||
|
timer.timeout.connect(eventLoop.quit)
|
||||||
|
timer.start(timeout)
|
||||||
|
eventLoop.exec_()
|
||||||
|
|
||||||
|
if not called:
|
||||||
|
print('runJavaScriptSync() timed out')
|
||||||
|
return result
|
||||||
|
|
||||||
# Main web view
|
# Main web view
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
@ -119,6 +143,17 @@ class AnkiWebView(QWebEngineView):
|
||||||
QShortcut(QKeySequence("ctrl+shift+v"), self,
|
QShortcut(QKeySequence("ctrl+shift+v"), self,
|
||||||
context=Qt.WidgetWithChildrenShortcut, activated=self.onPaste)
|
context=Qt.WidgetWithChildrenShortcut, activated=self.onPaste)
|
||||||
|
|
||||||
|
def event(self, evt):
|
||||||
|
if evt.type() == QEvent.ShortcutOverride:
|
||||||
|
# alt-gr bug workaround
|
||||||
|
exceptChars = (str(num) for num in range(1, 10))
|
||||||
|
if evt.text() not in exceptChars:
|
||||||
|
js = '["INPUT", "TEXTAREA"].indexOf(document.activeElement.tagName) !== -1'
|
||||||
|
if runJavaScriptSync(self.page(), js, timeout=100):
|
||||||
|
evt.accept()
|
||||||
|
return True
|
||||||
|
return QWebEngineView.event(self, evt)
|
||||||
|
|
||||||
def eventFilter(self, obj, evt):
|
def eventFilter(self, obj, evt):
|
||||||
# disable pinch to zoom gesture
|
# disable pinch to zoom gesture
|
||||||
if isinstance(evt, QNativeGestureEvent):
|
if isinstance(evt, QNativeGestureEvent):
|
||||||
|
|
Loading…
Reference in a new issue