aqt.utils
=========

.. py:module:: aqt.utils


Attributes
----------

.. autoapisummary::

   aqt.utils.TextFormat
   aqt.utils.tr
   aqt.utils.HelpPageArgument
   aqt.utils.MenuListChild


Classes
-------

.. autoapisummary::

   aqt.utils.MessageBox
   aqt.utils.ButtonedDialog
   aqt.utils.GetTextDialog
   aqt.utils.MenuList
   aqt.utils.SubMenu
   aqt.utils.MenuItem
   aqt.utils.KeyboardModifiersPressed


Functions
---------

.. autoapisummary::

   aqt.utils.aqt_data_path
   aqt.utils.aqt_data_folder
   aqt.utils.openHelp
   aqt.utils.openLink
   aqt.utils.ask_user
   aqt.utils.ask_user_dialog
   aqt.utils.show_info
   aqt.utils.show_warning
   aqt.utils.show_critical
   aqt.utils.showWarning
   aqt.utils.showCritical
   aqt.utils.showInfo
   aqt.utils.showText
   aqt.utils.askUser
   aqt.utils.askUserDialog
   aqt.utils.getText
   aqt.utils.getOnlyText
   aqt.utils.chooseList
   aqt.utils.getTag
   aqt.utils.disable_help_button
   aqt.utils.setWindowIcon
   aqt.utils.getFile
   aqt.utils.running_in_sandbox
   aqt.utils.getSaveFile
   aqt.utils.saveGeom
   aqt.utils.restoreGeom
   aqt.utils.ensureWidgetInScreenBoundaries
   aqt.utils.saveState
   aqt.utils.restoreState
   aqt.utils.saveSplitter
   aqt.utils.restoreSplitter
   aqt.utils.saveHeader
   aqt.utils.restoreHeader
   aqt.utils.save_is_checked
   aqt.utils.restore_is_checked
   aqt.utils.save_combo_index_for_session
   aqt.utils.restore_combo_index_for_session
   aqt.utils.save_combo_history
   aqt.utils.restore_combo_history
   aqt.utils.mungeQA
   aqt.utils.openFolder
   aqt.utils.show_in_folder
   aqt.utils.osascript_to_args
   aqt.utils.shortcut
   aqt.utils.maybeHideClose
   aqt.utils.downArrow
   aqt.utils.current_window
   aqt.utils.send_to_trash
   aqt.utils.tooltip
   aqt.utils.closeTooltip
   aqt.utils.checkInvalidFilename
   aqt.utils.qtMenuShortcutWorkaround
   aqt.utils.disallow_full_screen
   aqt.utils.add_ellipsis_to_action_label
   aqt.utils.supportText
   aqt.utils.opengl_vendor
   aqt.utils.gfxDriverIsBroken
   aqt.utils.startup_info
   aqt.utils.ensure_editor_saved
   aqt.utils.skip_if_selection_is_empty
   aqt.utils.no_arg_trigger
   aqt.utils.is_gesture_or_zoom_event


Module Contents
---------------

.. py:data:: TextFormat

.. py:function:: aqt_data_path() -> pathlib.Path

.. py:function:: aqt_data_folder() -> str

.. py:data:: tr

.. py:data:: HelpPageArgument

.. py:function:: openHelp(section: HelpPageArgument) -> None

.. py:function:: openLink(link: str | aqt.qt.QUrl) -> None

.. py:class:: 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: :py:obj:`aqt.qt.QMessageBox`


.. py:function:: 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.


.. py:function:: 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.


.. py:function:: 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.


.. py:function:: 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.


.. py:function:: 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.


.. py:function:: 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.


.. py:function:: 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.


.. py:function:: 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.


.. py:function:: 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

.. py:function:: 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.


.. py:class:: ButtonedDialog(text: str, buttons: list[str], parent: aqt.qt.QWidget | None = None, help: HelpPageArgument | None = None, title: str = 'Anki')

   Bases: :py:obj:`aqt.qt.QMessageBox`


   .. py:attribute:: help
      :value: None



   .. py:method:: run() -> str


   .. py:method:: setDefault(idx: int) -> None


.. py:function:: askUserDialog(text: str, buttons: list[str], parent: aqt.qt.QWidget | None = None, help: HelpPageArgument | None = None, title: str = 'Anki') -> ButtonedDialog

.. py:class:: 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: :py:obj:`aqt.qt.QDialog`


   .. py:attribute:: question


   .. py:attribute:: help
      :value: None



   .. py:attribute:: qlabel


   .. py:attribute:: l
      :value: None



   .. py:method:: accept() -> None


   .. py:method:: reject() -> None


   .. py:method:: helpRequested() -> None


.. py:function:: 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).


.. py:function:: getOnlyText(*args: Any, **kwargs: Any) -> str

.. py:function:: chooseList(prompt: str, choices: list[str], startrow: int = 0, parent: Any | None = None) -> int

.. py:function:: getTag(parent: aqt.qt.QWidget, deck: anki.collection.Collection, question: str, **kwargs: Any) -> tuple[str, int]

.. py:function:: disable_help_button(widget: aqt.qt.QWidget) -> None

   Disable the help button in the window titlebar.


.. py:function:: setWindowIcon(widget: aqt.qt.QWidget) -> None

.. py:function:: 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.


.. py:function:: 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.


.. py:function:: 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.


.. py:function:: saveGeom(widget: aqt.qt.QWidget, key: str) -> None

.. py:function:: restoreGeom(widget: aqt.qt.QWidget, key: str, adjustSize: bool = False, default_size: tuple[int, int] | None = None) -> None

.. py:function:: ensureWidgetInScreenBoundaries(widget: aqt.qt.QWidget) -> None

.. py:function:: saveState(widget: aqt.qt.QFileDialog | aqt.qt.QMainWindow, key: str) -> None

.. py:function:: restoreState(widget: aqt.qt.QFileDialog | aqt.qt.QMainWindow, key: str) -> None

.. py:function:: saveSplitter(widget: aqt.qt.QSplitter, key: str) -> None

.. py:function:: restoreSplitter(widget: aqt.qt.QSplitter, key: str) -> None

.. py:function:: saveHeader(widget: aqt.qt.QHeaderView, key: str) -> None

.. py:function:: restoreHeader(widget: aqt.qt.QHeaderView, key: str) -> None

.. py:function:: save_is_checked(widget: aqt.qt.QCheckBox, key: str) -> None

.. py:function:: restore_is_checked(widget: aqt.qt.QCheckBox, key: str) -> None

.. py:function:: save_combo_index_for_session(widget: aqt.qt.QComboBox, key: str) -> None

.. py:function:: restore_combo_index_for_session(widget: aqt.qt.QComboBox, history: list[str], key: str) -> None

.. py:function:: save_combo_history(comboBox: aqt.qt.QComboBox, history: list[str], name: str) -> str

.. py:function:: restore_combo_history(comboBox: aqt.qt.QComboBox, name: str) -> list[str]

.. py:function:: mungeQA(col: anki.collection.Collection, txt: str) -> str

.. py:function:: openFolder(path: str) -> None

.. py:function:: show_in_folder(path: str) -> None

.. py:function:: osascript_to_args(script: str)

.. py:function:: shortcut(key: str) -> str

.. py:function:: maybeHideClose(bbox: aqt.qt.QDialogButtonBox) -> None

.. py:function:: downArrow() -> str

.. py:function:: current_window() -> aqt.qt.QWidget | None

.. py:function:: send_to_trash(path: pathlib.Path) -> None

   Place file/folder in recycling bin, or delete permanently on failure.


.. py:function:: tooltip(msg: str, period: int = 3000, parent: aqt.qt.QWidget | None = None, x_offset: int = 0, y_offset: int = 100) -> None

.. py:function:: closeTooltip() -> None

.. py:function:: checkInvalidFilename(str: checkInvalidFilename.str, dirsep: bool = True) -> bool

.. py:data:: MenuListChild

.. py:class:: MenuList

   .. py:attribute:: children
      :type:  list[MenuListChild | None]
      :value: []



   .. py:method:: addItem(title: str, func: collections.abc.Callable) -> MenuItem


   .. py:method:: addSeparator() -> None


   .. py:method:: addMenu(title: str) -> SubMenu


   .. py:method:: addChild(child: SubMenu | aqt.qt.QAction | MenuList) -> None


   .. py:method:: renderTo(qmenu: aqt.qt.QMenu) -> None


   .. py:method:: popupOver(widget: aqt.qt.QPushButton) -> None


.. py:class:: SubMenu(title: str)

   Bases: :py:obj:`MenuList`


   .. py:attribute:: title


   .. py:method:: renderTo(menu: aqt.qt.QMenu) -> None


.. py:class:: MenuItem(title: str, func: collections.abc.Callable)

   .. py:attribute:: title


   .. py:attribute:: func


   .. py:method:: renderTo(qmenu: aqt.qt.QMenu) -> None


.. py:function:: qtMenuShortcutWorkaround(qmenu: aqt.qt.QMenu) -> None

.. py:function:: disallow_full_screen() -> bool

   Test for OpenGl on Windows, which is known to cause issues with full screen mode.


.. py:function:: 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.


.. py:function:: supportText() -> str

.. py:function:: opengl_vendor() -> str | None

.. py:function:: gfxDriverIsBroken() -> bool

.. py:function:: startup_info() -> Any

   Use subprocess.Popen(startupinfo=...) to avoid opening a console window.


.. py:function:: 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.


.. py:function:: 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.


.. py:function:: 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.


.. py:function:: 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.


.. py:class:: KeyboardModifiersPressed

   Util for type-safe checks of currently-pressed modifier keys.


   .. py:property:: shift
      :type: bool



   .. py:property:: control
      :type: bool



   .. py:property:: alt
      :type: bool



   .. py:property:: meta
      :type: bool



