From 94064b8230adbd956ba1c68cee7306fbd3f3f623 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 7 Jan 2021 14:24:49 +1000 Subject: [PATCH] convert setWindowFlags call into helper, and fix invalid variables "type: ignore" was masking the invalid references to self in places like showText() --- qt/aqt/about.py | 4 ++-- qt/aqt/addcards.py | 3 ++- qt/aqt/addons.py | 7 ++++--- qt/aqt/browser.py | 13 +++++++------ qt/aqt/clayout.py | 9 +++++---- qt/aqt/customstudy.py | 4 ++-- qt/aqt/deckconf.py | 3 ++- qt/aqt/dyndeckconf.py | 13 +++++++++++-- qt/aqt/editcurrent.py | 4 ++-- qt/aqt/editor.py | 3 ++- qt/aqt/emptycards.py | 4 ++-- qt/aqt/exporting.py | 12 ++++++++++-- qt/aqt/fields.py | 13 +++++++++++-- qt/aqt/importing.py | 5 +++-- qt/aqt/main.py | 3 ++- qt/aqt/mediasync.py | 4 ++-- qt/aqt/models.py | 5 +++-- qt/aqt/preferences.py | 12 ++++++++++-- qt/aqt/previewer.py | 4 ++-- qt/aqt/profiles.py | 4 ++-- qt/aqt/progress.py | 4 ++-- qt/aqt/sound.py | 12 ++++++++++-- qt/aqt/stats.py | 5 +++-- qt/aqt/studydeck.py | 3 ++- qt/aqt/sync.py | 11 +++++++++-- qt/aqt/taglimit.py | 4 ++-- qt/aqt/utils.py | 14 ++++++++++---- 27 files changed, 124 insertions(+), 58 deletions(-) diff --git a/qt/aqt/about.py b/qt/aqt/about.py index 48c2044c6..66165ee62 100644 --- a/qt/aqt/about.py +++ b/qt/aqt/about.py @@ -9,7 +9,7 @@ from anki.lang import without_unicode_isolation from anki.utils import versionWithBuild from aqt.addons import AddonManager, AddonMeta from aqt.qt import * -from aqt.utils import TR, supportText, tooltip, tr +from aqt.utils import TR, disable_help_button, supportText, tooltip, tr class ClosableQDialog(QDialog): @@ -28,7 +28,7 @@ class ClosableQDialog(QDialog): def show(mw): dialog = ClosableQDialog(mw) - dialog.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(dialog) mw.setupDialogGC(dialog) abt = aqt.forms.about.Ui_About() abt.setupUi(dialog) diff --git a/qt/aqt/addcards.py b/qt/aqt/addcards.py index 5c41ae08b..080788936 100644 --- a/qt/aqt/addcards.py +++ b/qt/aqt/addcards.py @@ -18,6 +18,7 @@ from aqt.utils import ( TR, addCloseShortcut, askUser, + disable_help_button, downArrow, openHelp, restoreGeom, @@ -37,7 +38,7 @@ class AddCards(QDialog): self.form = aqt.forms.addcards.Ui_Dialog() self.form.setupUi(self) self.setWindowTitle(tr(TR.ACTIONS_ADD)) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) self.setMinimumHeight(300) self.setMinimumWidth(400) self.setupChoosers() diff --git a/qt/aqt/addons.py b/qt/aqt/addons.py index ab33a947f..656379771 100644 --- a/qt/aqt/addons.py +++ b/qt/aqt/addons.py @@ -30,6 +30,7 @@ from aqt.qt import * from aqt.utils import ( TR, askUser, + disable_help_button, getFile, isWin, openFolder, @@ -705,7 +706,7 @@ class AddonsDialog(QDialog): qconnect(self.form.addonList.itemDoubleClicked, self.onConfig) qconnect(self.form.addonList.currentRowChanged, self._onAddonItemSelected) self.setWindowTitle(tr(TR.ADDONS_WINDOW_TITLE)) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) self.setAcceptDrops(True) self.redrawAddons() restoreGeom(self, "addons") @@ -918,7 +919,7 @@ class GetAddons(QDialog): tr(TR.ADDONS_BROWSE_ADDONS), QDialogButtonBox.ActionRole ) qconnect(b.clicked, self.onBrowse) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) restoreGeom(self, "getaddons", adjustSize=True) self.exec_() saveGeom(self, "getaddons") @@ -1296,7 +1297,7 @@ class ConfigEditor(QDialog): ) ) ) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) self.show() def onRestoreDefaults(self) -> None: diff --git a/qt/aqt/browser.py b/qt/aqt/browser.py index 1fdd97e01..4bab317de 100644 --- a/qt/aqt/browser.py +++ b/qt/aqt/browser.py @@ -38,6 +38,7 @@ from aqt.utils import ( MenuList, SubMenu, askUser, + disable_help_button, getOnlyText, getTag, openHelp, @@ -1755,7 +1756,7 @@ where id in %s""" if not cids2: return showInfo(tr(TR.BROWSING_ONLY_NEW_CARDS_CAN_BE_REPOSITIONED)) d = QDialog(self) - d.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(d) d.setWindowModality(Qt.WindowModal) frm = aqt.forms.reposition.Ui_Dialog() frm.setupUi(d) @@ -1791,7 +1792,7 @@ where id in %s""" def _reschedule(self): d = QDialog(self) - d.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(d) d.setWindowModality(Qt.WindowModal) frm = aqt.forms.reschedule.Ui_Dialog() frm.setupUi(d) @@ -1891,7 +1892,7 @@ where id in %s""" def _on_find_replace_diag(self, fields: List[str], nids: List[int]) -> None: d = QDialog(self) - d.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(d) frm = aqt.forms.findreplace.Ui_Dialog() frm.setupUi(d) d.setWindowModality(Qt.WindowModal) @@ -1975,7 +1976,7 @@ where id in %s""" frm = aqt.forms.finddupes.Ui_Dialog() frm.setupUi(d) restoreGeom(d, "findDupes") - d.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(d) searchHistory = restore_combo_history(frm.search, "findDupesFind") fields = sorted( @@ -2141,7 +2142,7 @@ class ChangeModel(QDialog): self.oldModel = browser.card.note().model() self.form = aqt.forms.changemodel.Ui_Dialog() self.form.setupUi(self) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) self.setWindowModality(Qt.WindowModal) self.setup() restoreGeom(self, "changeModel") @@ -2317,7 +2318,7 @@ class CardInfoDialog(QDialog): def __init__(self, browser: Browser, *args, **kwargs): super().__init__(browser, *args, **kwargs) self.browser = browser - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) def reject(self): saveGeom(self, "revlog") diff --git a/qt/aqt/clayout.py b/qt/aqt/clayout.py index 757c02936..5243b4c07 100644 --- a/qt/aqt/clayout.py +++ b/qt/aqt/clayout.py @@ -21,6 +21,7 @@ from aqt.theme import theme_manager from aqt.utils import ( TR, askUser, + disable_help_button, downArrow, getOnlyText, openHelp, @@ -71,7 +72,7 @@ class CardLayout(QDialog): tr(TR.CARD_TEMPLATES_CARD_TYPES_FOR, val=self.model["name"]) ) ) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) v1 = QVBoxLayout() v1.addWidget(self.topArea) v1.addWidget(self.mainArea) @@ -701,7 +702,7 @@ class CardLayout(QDialog): def onBrowserDisplay(self): d = QDialog() - d.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(d) f = aqt.forms.browserdisp.Ui_Dialog() f.setupUi(d) t = self.current_template() @@ -733,7 +734,7 @@ class CardLayout(QDialog): t = self.current_template() d = QDialog(self) d.setWindowTitle("Anki") - d.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(d) d.setMinimumWidth(400) l = QVBoxLayout() lab = QLabel( @@ -763,7 +764,7 @@ class CardLayout(QDialog): diag = QDialog(self) form = aqt.forms.addfield.Ui_Dialog() form.setupUi(diag) - diag.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(diag) fields = [f["name"] for f in self.model["flds"]] form.fields.addItems(fields) form.fields.setCurrentRow(0) diff --git a/qt/aqt/customstudy.py b/qt/aqt/customstudy.py index f6691a40b..416f01bfe 100644 --- a/qt/aqt/customstudy.py +++ b/qt/aqt/customstudy.py @@ -4,7 +4,7 @@ import aqt from anki.consts import * from aqt.qt import * -from aqt.utils import TR, showInfo, showWarning, tr +from aqt.utils import TR, disable_help_button, showInfo, showWarning, tr RADIO_NEW = 1 RADIO_REV = 2 @@ -28,7 +28,7 @@ class CustomStudy(QDialog): self.form = f = aqt.forms.customstudy.Ui_Dialog() self.created_custom_study = False f.setupUi(self) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) self.setWindowModality(Qt.WindowModal) self.setupSignals() f.radioNew.click() diff --git a/qt/aqt/deckconf.py b/qt/aqt/deckconf.py index 8ff788a01..41d5cc077 100644 --- a/qt/aqt/deckconf.py +++ b/qt/aqt/deckconf.py @@ -14,6 +14,7 @@ from aqt.qt import * from aqt.utils import ( TR, askUser, + disable_help_button, getOnlyText, openHelp, restoreGeom, @@ -48,7 +49,7 @@ class DeckConf(QDialog): self.setWindowTitle( without_unicode_isolation(tr(TR.ACTIONS_OPTIONS_FOR, val=self.deck["name"])) ) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) # qt doesn't size properly with altered fonts otherwise restoreGeom(self, "deckconf", adjustSize=True) gui_hooks.deck_conf_will_show(self) diff --git a/qt/aqt/dyndeckconf.py b/qt/aqt/dyndeckconf.py index ff52b578f..2d18de317 100644 --- a/qt/aqt/dyndeckconf.py +++ b/qt/aqt/dyndeckconf.py @@ -6,7 +6,16 @@ from typing import List, Optional import aqt from anki.lang import without_unicode_isolation from aqt.qt import * -from aqt.utils import TR, askUser, openHelp, restoreGeom, saveGeom, showWarning, tr +from aqt.utils import ( + TR, + askUser, + disable_help_button, + openHelp, + restoreGeom, + saveGeom, + showWarning, + tr, +) class DeckConf(QDialog): @@ -23,7 +32,7 @@ class DeckConf(QDialog): label = tr(TR.ACTIONS_REBUILD) self.ok = self.form.buttonBox.addButton(label, QDialogButtonBox.AcceptRole) self.mw.checkpoint(tr(TR.ACTIONS_OPTIONS)) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) self.setWindowModality(Qt.WindowModal) qconnect(self.form.buttonBox.helpRequested, lambda: openHelp("filtered-decks")) self.setWindowTitle( diff --git a/qt/aqt/editcurrent.py b/qt/aqt/editcurrent.py index 4d4892536..d1bbc3491 100644 --- a/qt/aqt/editcurrent.py +++ b/qt/aqt/editcurrent.py @@ -5,7 +5,7 @@ import aqt.editor from aqt import gui_hooks from aqt.main import ResetReason from aqt.qt import * -from aqt.utils import TR, restoreGeom, saveGeom, tooltip, tr +from aqt.utils import TR, disable_help_button, restoreGeom, saveGeom, tooltip, tr class EditCurrent(QDialog): @@ -16,7 +16,7 @@ class EditCurrent(QDialog): self.form = aqt.forms.editcurrent.Ui_Dialog() self.form.setupUi(self) self.setWindowTitle(tr(TR.EDITING_EDIT_CURRENT)) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) self.setMinimumHeight(400) self.setMinimumWidth(250) self.form.buttonBox.button(QDialogButtonBox.Close).setShortcut( diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index f1c8a5bca..cf360b43d 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -31,6 +31,7 @@ from aqt.sound import av_player from aqt.theme import theme_manager from aqt.utils import ( TR, + disable_help_button, getFile, openHelp, qtMenuShortcutWorkaround, @@ -555,7 +556,7 @@ class Editor: form = aqt.forms.edithtml.Ui_Dialog() form.setupUi(d) restoreGeom(d, "htmlEditor") - d.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(d) qconnect(form.buttonBox.helpRequested, lambda: openHelp("editing?id=features")) form.textEdit.setPlainText(self.note.fields[field]) d.show() diff --git a/qt/aqt/emptycards.py b/qt/aqt/emptycards.py index d45d4141d..d7d0d0801 100644 --- a/qt/aqt/emptycards.py +++ b/qt/aqt/emptycards.py @@ -9,7 +9,7 @@ import aqt from anki.backend_pb2 import EmptyCardsReport, NoteWithEmptyCards from aqt import gui_hooks from aqt.qt import QDialog, QDialogButtonBox, qconnect -from aqt.utils import TR, restoreGeom, saveGeom, tooltip, tr +from aqt.utils import TR, disable_help_button, restoreGeom, saveGeom, tooltip, tr def show_empty_cards(mw: aqt.main.AnkiQt) -> None: @@ -38,7 +38,7 @@ class EmptyCardsDialog(QDialog): self.form.setupUi(self) restoreGeom(self, "emptycards") self.setWindowTitle(tr(TR.EMPTY_CARDS_WINDOW_TITLE)) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) self.form.keep_notes.setText(tr(TR.EMPTY_CARDS_PRESERVE_NOTES_CHECKBOX)) self.form.webview.title = "empty cards" self.form.webview.set_bridge_command(self._on_note_link_clicked, self) diff --git a/qt/aqt/exporting.py b/qt/aqt/exporting.py index b9d5e164e..6881dbd19 100644 --- a/qt/aqt/exporting.py +++ b/qt/aqt/exporting.py @@ -13,7 +13,15 @@ import aqt from anki import hooks from anki.exporting import Exporter, exporters from aqt.qt import * -from aqt.utils import TR, checkInvalidFilename, getSaveFile, showWarning, tooltip, tr +from aqt.utils import ( + TR, + checkInvalidFilename, + disable_help_button, + getSaveFile, + showWarning, + tooltip, + tr, +) class ExportDialog(QDialog): @@ -30,7 +38,7 @@ class ExportDialog(QDialog): self.frm.setupUi(self) self.exporter: Optional[Exporter] = None self.cids = cids - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) self.setup(did) self.exec_() diff --git a/qt/aqt/fields.py b/qt/aqt/fields.py index 203d24ec8..549d7e926 100644 --- a/qt/aqt/fields.py +++ b/qt/aqt/fields.py @@ -9,7 +9,16 @@ from anki.rsbackend import TemplateError from aqt import AnkiQt, gui_hooks from aqt.qt import * from aqt.schema_change_tracker import ChangeTracker -from aqt.utils import TR, askUser, getOnlyText, openHelp, showWarning, tooltip, tr +from aqt.utils import ( + TR, + askUser, + disable_help_button, + getOnlyText, + openHelp, + showWarning, + tooltip, + tr, +) class FieldDialog(QDialog): @@ -27,7 +36,7 @@ class FieldDialog(QDialog): self.setWindowTitle( without_unicode_isolation(tr(TR.FIELDS_FIELDS_FOR, val=self.model["name"])) ) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) self.form.buttonBox.button(QDialogButtonBox.Help).setAutoDefault(False) self.form.buttonBox.button(QDialogButtonBox.Cancel).setAutoDefault(False) self.form.buttonBox.button(QDialogButtonBox.Save).setAutoDefault(False) diff --git a/qt/aqt/importing.py b/qt/aqt/importing.py index 8a807efc0..1af505d34 100644 --- a/qt/aqt/importing.py +++ b/qt/aqt/importing.py @@ -20,6 +20,7 @@ from aqt.qt import * from aqt.utils import ( TR, askUser, + disable_help_button, getFile, getOnlyText, openHelp, @@ -38,7 +39,7 @@ class ChangeMap(QDialog): self.model = model self.frm = aqt.forms.changemap.Ui_ChangeMap() self.frm.setupUi(self) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) n = 0 setCurrent = False for field in self.model["flds"]: @@ -86,7 +87,7 @@ class ImportDialog(QDialog): qconnect( self.frm.buttonBox.button(QDialogButtonBox.Help).clicked, self.helpRequested ) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) self.setupMappingFrame() self.setupOptions() self.modelChanged() diff --git a/qt/aqt/main.py b/qt/aqt/main.py index fbbcd65c9..740cd59e5 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -50,6 +50,7 @@ from aqt.utils import ( TR, askUser, checkInvalidFilename, + disable_help_button, getFile, getOnlyText, openHelp, @@ -1345,7 +1346,7 @@ title="%s" %s>%s""" % ( d = self.debugDiag = DebugDialog() d.silentlyClose = True - d.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(d) frm.setupUi(d) restoreGeom(d, "DebugConsoleWindow") restoreSplitter(frm.splitter, "DebugConsoleWindow") diff --git a/qt/aqt/mediasync.py b/qt/aqt/mediasync.py index fa1f2632e..07925f132 100644 --- a/qt/aqt/mediasync.py +++ b/qt/aqt/mediasync.py @@ -20,7 +20,7 @@ from anki.types import assert_exhaustive from anki.utils import intTime from aqt import gui_hooks from aqt.qt import QDialog, QDialogButtonBox, QPushButton, QTextCursor, QTimer, qconnect -from aqt.utils import showWarning, tr +from aqt.utils import disable_help_button, showWarning, tr LogEntry = Union[MediaSyncProgress, str] @@ -164,7 +164,7 @@ class MediaSyncDialog(QDialog): self.form = aqt.forms.synclog.Ui_Dialog() self.form.setupUi(self) self.setWindowTitle(tr(TR.SYNC_MEDIA_LOG_TITLE)) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) self.abort_button = QPushButton(tr(TR.SYNC_ABORT_BUTTON)) qconnect(self.abort_button.clicked, self._on_abort) self.abort_button.setAutoDefault(False) diff --git a/qt/aqt/models.py b/qt/aqt/models.py index b87561d30..572ec2e42 100644 --- a/qt/aqt/models.py +++ b/qt/aqt/models.py @@ -16,6 +16,7 @@ from aqt.qt import * from aqt.utils import ( TR, askUser, + disable_help_button, getText, maybeHideClose, openHelp, @@ -155,7 +156,7 @@ class Models(QDialog): def onAdvanced(self) -> None: nt = self.current_notetype() d = QDialog(self) - d.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(d) frm = aqt.forms.modelopts.Ui_Dialog() frm.setupUi(d) frm.latexsvg.setChecked(nt.get("latexsvg", False)) @@ -211,7 +212,7 @@ class AddModel(QDialog): self.model = None self.dialog = aqt.forms.addmodel.Ui_Dialog() self.dialog.setupUi(self) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) # standard models self.models = [] for (name, func) in stdmodels.get_stock_notetypes(self.col): diff --git a/qt/aqt/preferences.py b/qt/aqt/preferences.py index dc2120c7f..680c9b743 100644 --- a/qt/aqt/preferences.py +++ b/qt/aqt/preferences.py @@ -6,7 +6,15 @@ import aqt from aqt import AnkiQt from aqt.profiles import RecordingDriver, VideoDriver from aqt.qt import * -from aqt.utils import TR, askUser, openHelp, showInfo, showWarning, tr +from aqt.utils import ( + TR, + askUser, + disable_help_button, + openHelp, + showInfo, + showWarning, + tr, +) def video_driver_name_for_platform(driver: VideoDriver) -> str: @@ -31,7 +39,7 @@ class Preferences(QDialog): self.prof = self.mw.pm.profile self.form = aqt.forms.preferences.Ui_Preferences() self.form.setupUi(self) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) self.form.buttonBox.button(QDialogButtonBox.Help).setAutoDefault(False) self.form.buttonBox.button(QDialogButtonBox.Close).setAutoDefault(False) qconnect(self.form.buttonBox.helpRequested, lambda: openHelp("preferences")) diff --git a/qt/aqt/previewer.py b/qt/aqt/previewer.py index e9441e004..29e63251d 100644 --- a/qt/aqt/previewer.py +++ b/qt/aqt/previewer.py @@ -24,7 +24,7 @@ from aqt.qt import ( from aqt.reviewer import replay_audio from aqt.sound import av_player, play_clicked_audio from aqt.theme import theme_manager -from aqt.utils import TR, restoreGeom, saveGeom, tr +from aqt.utils import TR, disable_help_button, restoreGeom, saveGeom, tr from aqt.webview import AnkiWebView @@ -43,7 +43,7 @@ class Previewer(QDialog): self.mw = mw icon = QIcon() icon.addPixmap(QPixmap(":/icons/anki.png"), QIcon.Normal, QIcon.Off) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) self.setWindowIcon(icon) def card(self) -> Optional[Card]: diff --git a/qt/aqt/profiles.py b/qt/aqt/profiles.py index 9cc7b560f..d671a6aa1 100644 --- a/qt/aqt/profiles.py +++ b/qt/aqt/profiles.py @@ -26,7 +26,7 @@ from anki.rsbackend import SyncAuth from anki.utils import intTime, isMac, isWin from aqt import appHelpSite from aqt.qt import * -from aqt.utils import TR, locale_dir, showWarning, tr +from aqt.utils import TR, disable_help_button, locale_dir, showWarning, tr # Profile handling ########################################################################## @@ -542,7 +542,7 @@ create table if not exists profiles d = self.langDiag = NoCloseDiag() f = self.langForm = aqt.forms.setlang.Ui_Dialog() f.setupUi(d) - d.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(d) qconnect(d.accepted, self._onLangSelected) qconnect(d.rejected, lambda: True) # update list diff --git a/qt/aqt/progress.py b/qt/aqt/progress.py index ce22b1aae..2754f9b34 100644 --- a/qt/aqt/progress.py +++ b/qt/aqt/progress.py @@ -8,7 +8,7 @@ from typing import Optional import aqt.forms from aqt.qt import * -from aqt.utils import TR, tr +from aqt.utils import TR, disable_help_button, tr # Progress info ########################################################################## @@ -211,7 +211,7 @@ class ProgressManager: class ProgressDialog(QDialog): def __init__(self, parent): QDialog.__init__(self, parent) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) self.form = aqt.forms.progress.Ui_Dialog() self.form.setupUi(self) self._closingDown = False diff --git a/qt/aqt/sound.py b/qt/aqt/sound.py index fadf8c66f..c0962db3f 100644 --- a/qt/aqt/sound.py +++ b/qt/aqt/sound.py @@ -28,7 +28,15 @@ from aqt.mpv import MPV, MPVBase, MPVCommandError from aqt.profiles import RecordingDriver from aqt.qt import * from aqt.taskman import TaskManager -from aqt.utils import TR, restoreGeom, saveGeom, showWarning, startup_info, tr +from aqt.utils import ( + TR, + disable_help_button, + restoreGeom, + saveGeom, + showWarning, + startup_info, + tr, +) if TYPE_CHECKING: from PyQt5.QtMultimedia import QAudioRecorder @@ -707,7 +715,7 @@ class RecordDialog(QDialog): self._parent = parent self.mw = mw self._on_success = on_success - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) self._start_recording() self._setup_dialog() diff --git a/qt/aqt/stats.py b/qt/aqt/stats.py index 75c8aff90..055a81424 100644 --- a/qt/aqt/stats.py +++ b/qt/aqt/stats.py @@ -12,6 +12,7 @@ from aqt.theme import theme_manager from aqt.utils import ( TR, addCloseShortcut, + disable_help_button, getSaveFile, maybeHideClose, restoreGeom, @@ -34,7 +35,7 @@ class NewDeckStats(QDialog): self.oldPos = None self.wholeCollection = False self.setMinimumWidth(700) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) f = self.form f.setupUi(self) f.groupBox.setVisible(False) @@ -105,7 +106,7 @@ class DeckStats(QDialog): self.oldPos = None self.wholeCollection = False self.setMinimumWidth(700) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) f = self.form if theme_manager.night_mode and not theme_manager.macos_dark_mode(): # the grouping box renders incorrectly in the fusion theme. 5.9+ diff --git a/qt/aqt/studydeck.py b/qt/aqt/studydeck.py index 498214179..3cf6d1e4c 100644 --- a/qt/aqt/studydeck.py +++ b/qt/aqt/studydeck.py @@ -6,6 +6,7 @@ from aqt import gui_hooks from aqt.qt import * from aqt.utils import ( TR, + disable_help_button, getOnlyText, openHelp, restoreGeom, @@ -42,7 +43,7 @@ class StudyDeck(QDialog): gui_hooks.state_did_reset.append(self.onReset) self.geomKey = "studyDeck-" + geomKey restoreGeom(self, self.geomKey) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) if not cancel: self.form.buttonBox.removeButton( self.form.buttonBox.button(QDialogButtonBox.Cancel) diff --git a/qt/aqt/sync.py b/qt/aqt/sync.py index 8192350c4..a4ce2512c 100644 --- a/qt/aqt/sync.py +++ b/qt/aqt/sync.py @@ -32,7 +32,14 @@ from aqt.qt import ( QVBoxLayout, qconnect, ) -from aqt.utils import askUser, askUserDialog, showText, showWarning, tr +from aqt.utils import ( + askUser, + askUserDialog, + disable_help_button, + showText, + showWarning, + tr, +) class FullSyncChoice(enum.Enum): @@ -290,7 +297,7 @@ def get_id_and_pass_from_user( ) -> Tuple[str, str]: diag = QDialog(mw) diag.setWindowTitle("Anki") - diag.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(diag) diag.setWindowModality(Qt.WindowModal) vbox = QVBoxLayout() info_label = QLabel( diff --git a/qt/aqt/taglimit.py b/qt/aqt/taglimit.py index a4c033cce..0fed27f56 100644 --- a/qt/aqt/taglimit.py +++ b/qt/aqt/taglimit.py @@ -4,7 +4,7 @@ from typing import List, Optional import aqt from aqt.qt import * -from aqt.utils import restoreGeom, saveGeom +from aqt.utils import disable_help_button, restoreGeom, saveGeom class TagLimit(QDialog): @@ -16,7 +16,7 @@ class TagLimit(QDialog): self.deck = self.parent.deck self.dialog = aqt.forms.taglimit.Ui_Dialog() self.dialog.setupUi(self) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) s = QShortcut( QKeySequence("ctrl+d"), self.dialog.activeList, context=Qt.WidgetShortcut ) diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index 66cea4b8a..373695d3d 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -7,7 +7,7 @@ import os import re import subprocess import sys -from typing import TYPE_CHECKING, Any, List, Optional, Union +from typing import TYPE_CHECKING, Any, List, Optional, Union, cast import anki import aqt @@ -127,7 +127,7 @@ def showText( parent = aqt.mw.app.activeWindow() or aqt.mw diag = QDialog(parent) diag.setWindowTitle(title) - diag.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(diag) layout = QVBoxLayout(diag) diag.setLayout(layout) text = QTextBrowser() @@ -246,7 +246,7 @@ class GetTextDialog(QDialog): ): QDialog.__init__(self, parent) self.setWindowTitle(title) - self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(self) self.question = question self.help = help self.qlabel = QLabel(question) @@ -318,7 +318,7 @@ def chooseList(prompt, choices, startrow=0, parent=None): if not parent: parent = aqt.mw.app.activeWindow() d = QDialog(parent) - d.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint) # type: ignore + disable_help_button(d) d.setWindowModality(Qt.WindowModal) l = QVBoxLayout() d.setLayout(l) @@ -345,6 +345,12 @@ def getTag(parent, deck, question, tags="user", **kwargs): return ret +def disable_help_button(widget: QWidget) -> None: + "Disable the help button in the window titlebar." + flags = cast(Qt.WindowType, widget.windowFlags() & ~Qt.WindowContextHelpButtonHint) + widget.setWindowFlags(flags) + + # File handling ######################################################################