-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenus.py
48 lines (33 loc) · 1.43 KB
/
menus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import functools
from gettext import gettext as _
from aqt import mw
from aqt.qt import *
from .ajt_common.about_menu import menu_root_entry
from .config import config
from .options_dialog import ADDON_NAME, AutocopySettingsDialog
TOGGLE_ACTION = "ajt__toggle_autocopy_action"
def update_toggle_action() -> None:
toggle_action: QAction = getattr(mw, TOGGLE_ACTION)
toggle_action.setChecked(config.activated)
def on_open_settings() -> None:
dialog = AutocopySettingsDialog(config, mw)
qconnect(dialog.accepted, update_toggle_action)
dialog.exec()
def setup_settings_action(parent: QWidget) -> QAction:
action_settings = QAction(_(f"{ADDON_NAME} Options..."), parent)
qconnect(action_settings.triggered, on_open_settings)
return action_settings
def toggle_activated(self: QAction) -> None:
config.activated = not config.activated
self.setChecked(config.activated)
config.write_config()
def setup_toggle_action(parent: QWidget) -> QAction:
setattr(mw, TOGGLE_ACTION, toggle_action := QAction(_(f"Activate {ADDON_NAME}"), parent))
toggle_action.setCheckable(True)
toggle_action.setChecked(config.activated)
qconnect(toggle_action.triggered, functools.partial(toggle_activated, self=toggle_action))
return toggle_action
def setup() -> None:
root_menu = menu_root_entry()
root_menu.addAction(setup_toggle_action(root_menu))
root_menu.addAction(setup_settings_action(root_menu))