mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Activate toggle on hotkey invocation
This commit is contained in:
parent
59d0e8f036
commit
6afc495035
1 changed files with 15 additions and 1 deletions
|
@ -11,6 +11,7 @@ import urllib.error
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import warnings
|
import warnings
|
||||||
|
from random import randrange
|
||||||
from typing import Callable, List, Optional, Tuple
|
from typing import Callable, List, Optional, Tuple
|
||||||
|
|
||||||
import bs4
|
import bs4
|
||||||
|
@ -252,10 +253,23 @@ class Editor:
|
||||||
if func:
|
if func:
|
||||||
self._links[cmd] = func
|
self._links[cmd] = func
|
||||||
if keys:
|
if keys:
|
||||||
|
def on_activated():
|
||||||
|
func(self)
|
||||||
|
|
||||||
|
if toggleable:
|
||||||
|
# generate a random id for triggering toggle
|
||||||
|
id = id or str(randrange(1_000_000))
|
||||||
|
|
||||||
|
def on_hotkey():
|
||||||
|
on_activated()
|
||||||
|
self.web.eval(f'toggleEditorButton("#{id}");')
|
||||||
|
else:
|
||||||
|
on_hotkey = on_activated
|
||||||
|
|
||||||
QShortcut( # type: ignore
|
QShortcut( # type: ignore
|
||||||
QKeySequence(keys),
|
QKeySequence(keys),
|
||||||
self.widget,
|
self.widget,
|
||||||
activated=lambda s=self: func(s),
|
activated=on_hotkey,
|
||||||
)
|
)
|
||||||
btn = self._addButton(
|
btn = self._addButton(
|
||||||
icon,
|
icon,
|
||||||
|
|
Loading…
Reference in a new issue