aqt.main
========

.. py:module:: aqt.main


Attributes
----------

.. autoapisummary::

   aqt.main.MainWindowState
   aqt.main.T


Classes
-------

.. autoapisummary::

   aqt.main.MainWebView
   aqt.main.AnkiQt
   aqt.main.ResetReason


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

.. py:data:: MainWindowState

.. py:data:: T

.. py:class:: MainWebView(mw: AnkiQt)

   Bases: :py:obj:`aqt.webview.AnkiWebView`


   .. py:attribute:: mw


   .. py:method:: dragEnterEvent(event: QDragEnterEvent) -> None


   .. py:method:: dropEvent(event: QDropEvent) -> None


   .. py:method:: eventFilter(obj: QObject | None, evt: QEvent | None) -> bool


.. py:class:: AnkiQt(app: aqt.AnkiApp, profileManager: aqt.profiles.ProfileManager, backend: anki._backend.RustBackend, opts: argparse.Namespace, args: list[Any])

   Bases: :py:obj:`QMainWindow`


   .. py:attribute:: col
      :type:  anki.collection.Collection


   .. py:attribute:: pm
      :type:  aqt.profiles.ProfileManager


   .. py:attribute:: web
      :type:  MainWebView


   .. py:attribute:: bottomWeb
      :type:  aqt.toolbar.BottomWebView


   .. py:attribute:: backend


   .. py:attribute:: state
      :type:  MainWindowState
      :value: 'startup'



   .. py:attribute:: opts


   .. py:attribute:: taskman


   .. py:attribute:: media_syncer


   .. py:attribute:: app


   .. py:attribute:: fullscreen
      :value: False



   .. py:attribute:: safeMode


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


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

      Actions that are deferred until after add-on loading.



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


   .. py:method:: weakref() -> AnkiQt

      Shortcut to create a weak reference that doesn't break code completion.



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


   .. py:method:: on_focus_changed(old: QWidget, new: QWidget) -> None


   .. py:class:: ProfileManager

      Bases: :py:obj:`QMainWindow`


      .. py:attribute:: onClose


      .. py:attribute:: closeFires
         :value: True



      .. py:method:: closeEvent(evt: QCloseEvent) -> None


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



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


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


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


   .. py:method:: onProfileRowChange(n: int) -> None


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


   .. py:method:: onOpenProfile(*, callback: collections.abc.Callable[[], None] | None = None) -> None


   .. py:method:: profileNameOk(name: str) -> bool


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


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


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


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


   .. py:method:: loadProfile(onsuccess: collections.abc.Callable | None = None) -> None


   .. py:method:: unloadProfile(onsuccess: collections.abc.Callable) -> None


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


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


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


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


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


   .. py:method:: prepare_card_text_for_display(text: str) -> str


   .. py:method:: loadCollection() -> bool


   .. py:method:: reopen(after_full_sync: bool = False) -> None


   .. py:method:: unloadCollection(onsuccess: collections.abc.Callable) -> None


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

      Setup audio after collection loaded.



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


   .. py:method:: moveToState(state: MainWindowState, *args: Any) -> None


   .. py:method:: on_operation_did_execute(changes: anki.collection.OpChanges, handler: object | None) -> None

      Notify current screen of changes.



   .. py:method:: on_focus_did_change(new_focus: QWidget | None, _old: QWidget | None) -> None

      If main window has received focus, ensure current UI state is updated.



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


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


   .. py:method:: reset(unused_arg: bool = False) -> None

      Legacy method of telling UI to refresh after changes made to DB.

      New code should use CollectionOp() instead.



   .. py:method:: requireReset(modal: bool = False, reason: Any | None = None, context: Any | None = None) -> None


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


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


   .. py:method:: button(link: str, name: str, key: str | None = None, class_: str = '', id: str = '', extra: str = '') -> str


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


   .. py:method:: closeAllWindows(onsuccess: collections.abc.Callable) -> None


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


   .. py:method:: onUnixSignal(signum: Any, frame: Any) -> None


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


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


   .. py:method:: setupAddons(args: list | None) -> None


   .. py:method:: maybe_check_for_addon_updates(on_done: collections.abc.Callable[[list[aqt.addons.DownloadLogEntry]], None] | None = None) -> None


   .. py:method:: check_for_addon_updates(by_user: bool, on_done: collections.abc.Callable[[list[aqt.addons.DownloadLogEntry]], None] | None = None) -> None


   .. py:method:: on_updates_installed(log: list[aqt.addons.DownloadLogEntry]) -> None


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


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


   .. py:method:: inMainThread() -> bool


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


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


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


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


   .. py:method:: maybe_auto_sync_on_open_close(after_sync: collections.abc.Callable[[bool], None]) -> None

      If disabled, after_sync() is called immediately.



   .. py:method:: can_auto_sync() -> bool

      True if syncing on startup/shutdown enabled.



   .. py:attribute:: onSync


   .. py:method:: raiseMain() -> bool


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


   .. py:method:: set_theme(theme: aqt.theme.Theme) -> None


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


   .. py:method:: applyShortcuts(shortcuts: collections.abc.Sequence[tuple[str, collections.abc.Callable]]) -> list[QShortcut]


   .. py:method:: setStateShortcuts(shortcuts: list[tuple[str, collections.abc.Callable]]) -> None


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


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


   .. py:method:: closeEvent(event: QCloseEvent) -> None


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

      Call operations/collection.py:undo() directly instead.



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

      Call operations/collection.py:redo() directly instead.



   .. py:method:: undo_actions_info() -> aqt.undo.UndoActionsInfo

      Info about the current undo/redo state for updating menus.



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

      Tell the UI to redraw the undo/redo menu actions based on the current state.

      Usually you do not need to call this directly; it is called when a
      CollectionOp is run, and will be called when the legacy .reset() or
      .checkpoint() methods are used.



   .. py:method:: checkpoint(name: str) -> None


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


   .. py:attribute:: onUndo


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


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


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


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


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


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


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


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


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


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


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


   .. py:method:: onDeckConf(deck: anki.decks.DeckDict | None = None) -> None


   .. py:method:: handleImport(path: str) -> None

      Importing triggered via file double-click, or dragging file onto Anki icon.



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

      Importing triggered via File>Import.



   .. py:method:: onExport(did: anki.decks.DeckId | None = None) -> None


   .. py:method:: installAddon(path: str, startup: bool = False) -> None


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


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


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


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


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


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


   .. py:method:: setup_auto_update(_log: list[aqt.addons.DownloadLogEntry]) -> None


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


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


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


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

      Create a backup if enough time has elapsed and collection changed.



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


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

      Create a backup immediately, regardless of when the last one was created.
      Waits until the backup completes. Intended to be used as part of a longer-running
      CollectionOp/QueryOp.



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


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


   .. py:method:: on_av_player_will_play(tag: anki.sound.AVTag) -> None

      Record active window to restore after video playing.



   .. py:method:: on_av_player_did_end_playing(player: Any) -> None

      Restore window focus after a video was played.



   .. py:method:: onRemNotes(col: anki.collection.Collection, nids: collections.abc.Sequence[anki.notes.NoteId]) -> None


   .. py:method:: onSchemaMod(arg: bool) -> bool


   .. py:method:: confirm_schema_modification() -> bool

      If schema unmodified, ask user to confirm change.
      True if confirmed or already modified.



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


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


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


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


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


   .. py:method:: maybeHideAccelerators(tgt: Any | None = None) -> None


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


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


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


   .. py:method:: onAppMsg(buf: str) -> None


   .. py:method:: interactiveState() -> bool

      True if not in profile manager, syncing, etc.



   .. py:method:: garbage_collect_on_dialog_finish(dialog: QDialog) -> None


   .. py:method:: deferred_delete_and_garbage_collect(obj: QObject) -> None


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


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


   .. py:attribute:: setupDialogGC


   .. py:attribute:: gcWindow


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


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


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


.. py:class:: ResetReason(*args, **kwds)

   Bases: :py:obj:`enum.Enum`


   Create a collection of name/value pairs.

   Example enumeration:

   >>> class Color(Enum):
   ...     RED = 1
   ...     BLUE = 2
   ...     GREEN = 3

   Access them by:

   - attribute access:

     >>> Color.RED
     <Color.RED: 1>

   - value lookup:

     >>> Color(1)
     <Color.RED: 1>

   - name lookup:

     >>> Color['RED']
     <Color.RED: 1>

   Enumerations can be iterated over, and know how many members they have:

   >>> len(Color)
   3

   >>> list(Color)
   [<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

   Methods can be added to enumerations, and members can have their own
   attributes -- see the documentation for details.


   .. py:attribute:: Unknown
      :value: 'unknown'



   .. py:attribute:: AddCardsAddNote
      :value: 'addCardsAddNote'



   .. py:attribute:: EditCurrentInit
      :value: 'editCurrentInit'



   .. py:attribute:: EditorBridgeCmd
      :value: 'editorBridgeCmd'



   .. py:attribute:: BrowserSetDeck
      :value: 'browserSetDeck'



   .. py:attribute:: BrowserAddTags
      :value: 'browserAddTags'



   .. py:attribute:: BrowserRemoveTags
      :value: 'browserRemoveTags'



   .. py:attribute:: BrowserSuspend
      :value: 'browserSuspend'



   .. py:attribute:: BrowserReposition
      :value: 'browserReposition'



   .. py:attribute:: BrowserReschedule
      :value: 'browserReschedule'



   .. py:attribute:: BrowserFindReplace
      :value: 'browserFindReplace'



   .. py:attribute:: BrowserTagDupes
      :value: 'browserTagDupes'



   .. py:attribute:: BrowserDeleteDeck
      :value: 'browserDeleteDeck'



