mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Enable strict_optional for aqt/preferences.py (#3519)
* Enable strict_optional for aqt/preferences.py * Fix mypy errors
This commit is contained in:
parent
939cc5a268
commit
507050c876
2 changed files with 20 additions and 7 deletions
|
@ -40,6 +40,8 @@ strict_optional = True
|
|||
strict_optional = True
|
||||
[mypy-aqt.editor]
|
||||
strict_optional = True
|
||||
[mypy-aqt.preferences]
|
||||
strict_optional = True
|
||||
[mypy-anki.scheduler.base]
|
||||
strict_optional = True
|
||||
[mypy-anki._backend.rsbridge]
|
||||
|
|
|
@ -46,13 +46,16 @@ class Preferences(QDialog):
|
|||
self.form.network_timeout,
|
||||
):
|
||||
spinbox.setSuffix(f" {spinbox.suffix()}")
|
||||
|
||||
disable_help_button(self)
|
||||
self.form.buttonBox.button(QDialogButtonBox.StandardButton.Help).setAutoDefault(
|
||||
False
|
||||
)
|
||||
self.form.buttonBox.button(
|
||||
QDialogButtonBox.StandardButton.Close
|
||||
).setAutoDefault(False)
|
||||
help_button = self.form.buttonBox.button(QDialogButtonBox.StandardButton.Help)
|
||||
assert help_button is not None
|
||||
help_button.setAutoDefault(False)
|
||||
|
||||
close_button = self.form.buttonBox.button(QDialogButtonBox.StandardButton.Close)
|
||||
assert close_button is not None
|
||||
close_button.setAutoDefault(False)
|
||||
|
||||
qconnect(
|
||||
self.form.buttonBox.helpRequested, lambda: openHelp(HelpPage.PREFERENCES)
|
||||
)
|
||||
|
@ -218,6 +221,7 @@ class Preferences(QDialog):
|
|||
qconnect(self.form.syncAnkiHubLogin.clicked, self.ankihub_sync_login)
|
||||
|
||||
def update_login_status(self) -> None:
|
||||
assert self.prof is not None
|
||||
if not self.prof.get("syncKey"):
|
||||
self.form.syncUser.setText(tr.preferences_ankiweb_intro())
|
||||
self.form.syncLogin.setVisible(True)
|
||||
|
@ -241,6 +245,7 @@ class Preferences(QDialog):
|
|||
|
||||
def sync_login(self) -> None:
|
||||
def on_success():
|
||||
assert self.prof is not None
|
||||
if self.prof.get("syncKey"):
|
||||
self.update_login_status()
|
||||
self.confirm_sync_after_login()
|
||||
|
@ -251,6 +256,7 @@ class Preferences(QDialog):
|
|||
if self.mw.media_syncer.is_syncing():
|
||||
showWarning("Can't log out while sync in progress.")
|
||||
return
|
||||
assert self.prof is not None
|
||||
self.prof["syncKey"] = None
|
||||
self.mw.col.media.force_resync()
|
||||
self.update_login_status()
|
||||
|
@ -263,7 +269,10 @@ class Preferences(QDialog):
|
|||
ankihub_login(self.mw, on_success)
|
||||
|
||||
def ankihub_sync_logout(self) -> None:
|
||||
ankihub_logout(self.mw, self.update_login_status, self.mw.pm.ankihub_token())
|
||||
ankihub_token = self.mw.pm.ankihub_token()
|
||||
if ankihub_token is None:
|
||||
return
|
||||
ankihub_logout(self.mw, self.update_login_status, ankihub_token)
|
||||
|
||||
def confirm_sync_after_login(self) -> None:
|
||||
from aqt import mw
|
||||
|
@ -272,6 +281,7 @@ class Preferences(QDialog):
|
|||
self.accept_with_callback(self.mw.on_sync_button_clicked)
|
||||
|
||||
def update_network(self) -> None:
|
||||
assert self.prof is not None
|
||||
self.prof["autoSync"] = self.form.syncOnProgramOpen.isChecked()
|
||||
self.prof["syncMedia"] = self.form.syncMedia.isChecked()
|
||||
self.mw.pm.set_periodic_sync_media_minutes(
|
||||
|
@ -378,6 +388,7 @@ class Preferences(QDialog):
|
|||
self.mw.set_theme(Theme(index))
|
||||
|
||||
def on_reset_window_sizes(self) -> None:
|
||||
assert self.prof is not None
|
||||
regexp = re.compile(r"(Geom(etry)?|State|Splitter|Header)(\d+.\d+)?$")
|
||||
for key in list(self.prof.keys()):
|
||||
if regexp.search(key):
|
||||
|
|
Loading…
Reference in a new issue