aqt.utils#
Attributes#
Classes#
Util for type-safe checks of currently-pressed modifier keys. |
Functions#
|
|
|
|
|
|
|
|
|
Shows a yes/no question, passes the answer to the callback function as a bool. |
|
Shows a question to the user, passes the index of the button clicked to the callback. |
|
Show a small info window with an OK button. |
|
Show a small warning window with an OK button. |
|
Show a small critical error window with an OK button. |
|
Show a small warning with an OK button. |
|
Show a small critical error with an OK button. |
|
Show a small info window with an OK button. |
|
|
|
Show a yes/no question. Return true if yes. |
|
|
|
Returns (string, succeeded). |
|
|
|
|
|
|
|
Disable the help button in the window titlebar. |
|
|
|
Ask the user for a file. |
Check whether running in Flatpak or Snap. When in such a sandbox, Qt |
|
|
Ask the user for a file to save. Use DIR_DESCRIPTION as config |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Place file/folder in recycling bin, or delete permanently on failure. |
|
|
|
|
|
|
|
|
|
Test for OpenGl on Windows, which is known to cause issues with full screen mode. |
|
Pass actions to add '...' to their labels, indicating that more input is |
|
|
|
|
|
|
|
Use subprocess.Popen(startupinfo=...) to avoid opening a console window. |
|
Ensure the current editor's note is saved before running the wrapped function. |
|
Make the wrapped method a no-op and show a hint if the table selection is empty. |
|
Tells Qt this function takes no args. |
|
If the event is a gesture and/or will trigger zoom. |
Module Contents#
- aqt.utils.TextFormat#
- aqt.utils.aqt_data_path() pathlib.Path#
- aqt.utils.aqt_data_folder() str#
- aqt.utils.tr#
- aqt.utils.HelpPageArgument#
- aqt.utils.openHelp(section: HelpPageArgument) None#
- aqt.utils.openLink(link: str | aqt.qt.QUrl) None#
- class aqt.utils.MessageBox(text: str, callback: collections.abc.Callable[[int], None] | None = None, parent: aqt.qt.QWidget | None = None, icon: aqt.qt.QMessageBox.Icon = QMessageBox.Icon.NoIcon, help: HelpPageArgument | None = None, title: str = 'Anki', buttons: collections.abc.Sequence[str | aqt.qt.QMessageBox.StandardButton | tuple[str, aqt.qt.QMessageBox.ButtonRole]] | None = None, default_button: int = 0, textFormat: aqt.qt.Qt.TextFormat = Qt.TextFormat.PlainText, modality: aqt.qt.Qt.WindowModality = Qt.WindowModality.WindowModal)#
Bases:
aqt.qt.QMessageBox
- aqt.utils.ask_user(text: str, callback: collections.abc.Callable[[bool], None], defaults_yes: bool = True, **kwargs: Any) MessageBox#
Shows a yes/no question, passes the answer to the callback function as a bool.
- aqt.utils.ask_user_dialog(text: str, callback: collections.abc.Callable[[int], None], buttons: collections.abc.Sequence[str | aqt.qt.QMessageBox.StandardButton | tuple[str, aqt.qt.QMessageBox.ButtonRole]] | None = None, default_button: int = 1, parent: aqt.qt.QWidget | None = None, title: str = 'Anki', **kwargs: Any) MessageBox#
Shows a question to the user, passes the index of the button clicked to the callback.
- aqt.utils.show_info(text: str, callback: collections.abc.Callable | None = None, parent: aqt.qt.QWidget | None = None, **kwargs: Any) MessageBox#
Show a small info window with an OK button.
- aqt.utils.show_warning(text: str, callback: collections.abc.Callable | None = None, parent: aqt.qt.QWidget | None = None, **kwargs: Any) MessageBox#
Show a small warning window with an OK button.
- aqt.utils.show_critical(text: str, callback: collections.abc.Callable | None = None, parent: aqt.qt.QWidget | None = None, **kwargs: Any) MessageBox#
Show a small critical error window with an OK button.
- aqt.utils.showWarning(text: str, parent: aqt.qt.QWidget | None = None, help: HelpPageArgument | None = None, title: str = 'Anki', textFormat: TextFormat | None = None) int#
Show a small warning with an OK button.
- aqt.utils.showCritical(text: str, parent: aqt.qt.QDialog | None = None, help: str = '', title: str = 'Anki', textFormat: TextFormat | None = None) int#
Show a small critical error with an OK button.
- aqt.utils.showInfo(text: str, parent: aqt.qt.QWidget | None = None, help: HelpPageArgument | None = None, type: str = 'info', title: str = 'Anki', textFormat: TextFormat | None = None, customBtns: list[aqt.qt.QMessageBox.StandardButton] | None = None) int#
Show a small info window with an OK button.
- aqt.utils.showText(txt: str, parent: aqt.qt.QWidget | None = None, type: str = 'text', run: bool = True, geomKey: str | None = None, minWidth: int = 500, minHeight: int = 400, title: str = 'Anki', copyBtn: bool = False, plain_text_edit: bool = False) tuple[aqt.qt.QDialog, aqt.qt.QDialogButtonBox] | None#
- aqt.utils.askUser(text: str, parent: aqt.qt.QWidget | None = None, help: HelpPageArgument | None = None, defaultno: bool = False, msgfunc: collections.abc.Callable | None = None, title: str = 'Anki') bool#
Show a yes/no question. Return true if yes.
- class aqt.utils.ButtonedDialog(text: str, buttons: list[str], parent: aqt.qt.QWidget | None = None, help: HelpPageArgument | None = None, title: str = 'Anki')#
Bases:
aqt.qt.QMessageBox- help = None#
- run() str#
- setDefault(idx: int) None#
- aqt.utils.askUserDialog(text: str, buttons: list[str], parent: aqt.qt.QWidget | None = None, help: HelpPageArgument | None = None, title: str = 'Anki') ButtonedDialog#
- class aqt.utils.GetTextDialog(parent: aqt.qt.QWidget | None, question: str, help: HelpPageArgument | None = None, edit: aqt.qt.QLineEdit | None = None, default: str = '', title: str = 'Anki', minWidth: int = 400)#
Bases:
aqt.qt.QDialog- question#
- help = None#
- qlabel#
- l = None#
- accept() None#
- reject() None#
- helpRequested() None#
- aqt.utils.getText(prompt: str, parent: aqt.qt.QWidget | None = None, help: HelpPageArgument | None = None, edit: aqt.qt.QLineEdit | None = None, default: str = '', title: str = 'Anki', geomKey: str | None = None, **kwargs: Any) tuple[str, int]#
Returns (string, succeeded).
- aqt.utils.getOnlyText(*args: Any, **kwargs: Any) str#
- aqt.utils.chooseList(prompt: str, choices: list[str], startrow: int = 0, parent: Any | None = None) int#
- aqt.utils.getTag(parent: aqt.qt.QWidget, deck: anki.collection.Collection, question: str, **kwargs: Any) tuple[str, int]#
- aqt.utils.disable_help_button(widget: aqt.qt.QWidget) None#
Disable the help button in the window titlebar.
- aqt.utils.setWindowIcon(widget: aqt.qt.QWidget) None#
- aqt.utils.getFile(parent: aqt.qt.QWidget, title: str, cb: collections.abc.Callable[[str | collections.abc.Sequence[str]], None] | None, filter: str = '*', dir: str | None = None, key: str | None = None, multi: bool = False) collections.abc.Sequence[str] | str | None#
Ask the user for a file.
- aqt.utils.running_in_sandbox()#
Check whether running in Flatpak or Snap. When in such a sandbox, Qt will not report the true location of user-chosen files, but instead a temporary location from which the sandboxing software will copy the file to the user-chosen destination. Thus file renames are impossible and caching the reported file location is unhelpful.
- aqt.utils.getSaveFile(parent: aqt.qt.QDialog, title: str, dir_description: str, key: str, ext: str, fname: str = '') str | None#
Ask the user for a file to save. Use DIR_DESCRIPTION as config variable. The file dialog will default to open with FNAME.
- aqt.utils.saveGeom(widget: aqt.qt.QWidget, key: str) None#
- aqt.utils.restoreGeom(widget: aqt.qt.QWidget, key: str, adjustSize: bool = False, default_size: tuple[int, int] | None = None) None#
- aqt.utils.ensureWidgetInScreenBoundaries(widget: aqt.qt.QWidget) None#
- aqt.utils.saveState(widget: aqt.qt.QFileDialog | aqt.qt.QMainWindow, key: str) None#
- aqt.utils.restoreState(widget: aqt.qt.QFileDialog | aqt.qt.QMainWindow, key: str) None#
- aqt.utils.saveSplitter(widget: aqt.qt.QSplitter, key: str) None#
- aqt.utils.restoreSplitter(widget: aqt.qt.QSplitter, key: str) None#
- aqt.utils.saveHeader(widget: aqt.qt.QHeaderView, key: str) None#
- aqt.utils.restoreHeader(widget: aqt.qt.QHeaderView, key: str) None#
- aqt.utils.save_is_checked(widget: aqt.qt.QCheckBox, key: str) None#
- aqt.utils.restore_is_checked(widget: aqt.qt.QCheckBox, key: str) None#
- aqt.utils.save_combo_index_for_session(widget: aqt.qt.QComboBox, key: str) None#
- aqt.utils.restore_combo_index_for_session(widget: aqt.qt.QComboBox, history: list[str], key: str) None#
- aqt.utils.save_combo_history(comboBox: aqt.qt.QComboBox, history: list[str], name: str) str#
- aqt.utils.restore_combo_history(comboBox: aqt.qt.QComboBox, name: str) list[str]#
- aqt.utils.mungeQA(col: anki.collection.Collection, txt: str) str#
- aqt.utils.openFolder(path: str) None#
- aqt.utils.show_in_folder(path: str) None#
- aqt.utils.osascript_to_args(script: str)#
- aqt.utils.shortcut(key: str) str#
- aqt.utils.maybeHideClose(bbox: aqt.qt.QDialogButtonBox) None#
- aqt.utils.downArrow() str#
- aqt.utils.current_window() aqt.qt.QWidget | None#
- aqt.utils.send_to_trash(path: pathlib.Path) None#
Place file/folder in recycling bin, or delete permanently on failure.
- aqt.utils.tooltip(msg: str, period: int = 3000, parent: aqt.qt.QWidget | None = None, x_offset: int = 0, y_offset: int = 100) None#
- aqt.utils.closeTooltip() None#
- aqt.utils.checkInvalidFilename(str: checkInvalidFilename.str, dirsep: bool = True) bool#
- aqt.utils.MenuListChild#
- class aqt.utils.MenuList#
- children: list[MenuListChild | None] = []#
- addSeparator() None#
- renderTo(qmenu: aqt.qt.QMenu) None#
- popupOver(widget: aqt.qt.QPushButton) None#
- class aqt.utils.MenuItem(title: str, func: collections.abc.Callable)#
- title#
- func#
- renderTo(qmenu: aqt.qt.QMenu) None#
- aqt.utils.qtMenuShortcutWorkaround(qmenu: aqt.qt.QMenu) None#
- aqt.utils.disallow_full_screen() bool#
Test for OpenGl on Windows, which is known to cause issues with full screen mode.
- aqt.utils.add_ellipsis_to_action_label(*actions: aqt.qt.QAction | aqt.qt.QPushButton) None#
Pass actions to add ‘…’ to their labels, indicating that more input is required before they can be performed.
This approach is used so that the same fluent translations can be used on mobile, where the ‘…’ convention does not exist.
- aqt.utils.supportText() str#
- aqt.utils.opengl_vendor() str | None#
- aqt.utils.gfxDriverIsBroken() bool#
- aqt.utils.startup_info() Any#
Use subprocess.Popen(startupinfo=…) to avoid opening a console window.
- aqt.utils.ensure_editor_saved(func: collections.abc.Callable) collections.abc.Callable#
Ensure the current editor’s note is saved before running the wrapped function.
Must be used on functions that may be invoked from a shortcut key while the editor has focus. For functions that can’t be activated while the editor has focus, you don’t need this.
Will look for the editor as self.editor.
- aqt.utils.skip_if_selection_is_empty(func: collections.abc.Callable) collections.abc.Callable#
Make the wrapped method a no-op and show a hint if the table selection is empty.
- aqt.utils.no_arg_trigger(func: collections.abc.Callable) collections.abc.Callable#
Tells Qt this function takes no args.
This ensures PyQt doesn’t attempt to pass a toggled arg into functions connected to a triggered signal.
- aqt.utils.is_gesture_or_zoom_event(evt: aqt.qt.QEvent) bool#
If the event is a gesture and/or will trigger zoom.
Includes zoom by pinching, and Ctrl-scrolling on Win and Linux.