aqt.progress
============

.. py:module:: aqt.progress


Classes
-------

.. autoapisummary::

   aqt.progress.ProgressManager
   aqt.progress.ProgressDialog
   aqt.progress.ProgressUpdate


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

.. py:class:: ProgressManager(mw: aqt.AnkiQt)

   .. py:attribute:: mw


   .. py:attribute:: app


   .. py:attribute:: inDB
      :value: False



   .. py:attribute:: blockUpdates
      :value: False



   .. py:method:: timer(ms: int, func: collections.abc.Callable, repeat: bool, requiresCollection: bool = True, *, parent: QObject | None = None) -> QTimer

      Create and start a standard Anki timer. For an alternative see `single_shot()`.

      If the timer fires while a progress window is shown:
      - if it is a repeating timer, it will wait the same delay again
      - if it is non-repeating, it will try again in 100ms

      If requiresCollection is True, the timer will not fire if the
      collection has been unloaded. Setting it to False will allow the
      timer to fire even when there is no collection, but will still
      only fire when there is no current progress dialog.


      Issues and alternative
      ---
      The created timer will only be destroyed when `parent` is destroyed.
      This can cause memory leaks, because anything captured by `func` isn't freed either.
      If there is no QObject that will get destroyed reasonably soon, and you have to
      pass `mw`, you should call `deleteLater()` on the returned QTimer as soon as
      it's served its purpose, or use `single_shot()`.

      Also note that you may not be able to pass an adequate parent, if you want to
      make a callback after a widget closes. If you passed that widget, the timer
      would get destroyed before it could fire.



   .. py:method:: single_shot(ms: int, func: collections.abc.Callable[[], None], requires_collection: bool = True) -> None

      Create and start a one-off Anki timer. For an alternative and more
      documentation, see `timer()`.


      Issues and alternative
      ---
      `single_shot()` cleans itself up, so a passed closure won't leak any memory.
      However, if `func` references a QObject other than `mw`, which gets deleted before the
      timer fires, an Exception is raised. To avoid this, either use `timer()` passing
      that object as the parent, or check in `func` with `sip.isdeleted(object)` if
      it still exists.

      On the other hand, if a widget is supposed to make an external callback after it closes,
      you likely want to use `single_shot()`, which will fire even if the calling
      widget is already destroyed.



   .. py:method:: start(max: int = 0, min: int = 0, label: str | None = None, parent: QWidget | None = None, immediate: bool = False, title: str = 'Anki') -> ProgressDialog | None


   .. py:method:: start_with_backend_updates(progress_update: collections.abc.Callable[[anki.collection.Progress, ProgressUpdate], None], start_label: str | None = None, parent: QWidget | None = None) -> None


   .. py:method:: update(label: str | None = None, value: int | None = None, process: bool = True, maybeShow: bool = True, max: int | None = None) -> None


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


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

      Restore the interface after an error.



   .. py:method:: busy() -> int

      True if processing.



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


   .. py:method:: set_title(title: str) -> None


.. py:class:: ProgressDialog(parent: QWidget | None)

   Bases: :py:obj:`QDialog`


   .. py:attribute:: form


   .. py:attribute:: wantCancel
      :value: False



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


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


   .. py:method:: keyPressEvent(evt: QKeyEvent | None) -> None


.. py:class:: ProgressUpdate

   .. py:attribute:: label
      :type:  str | None
      :value: None



   .. py:attribute:: value
      :type:  int | None
      :value: None



   .. py:attribute:: max
      :type:  int | None
      :value: None



   .. py:attribute:: user_wants_abort
      :type:  bool
      :value: False



   .. py:attribute:: abort
      :type:  bool
      :value: False



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


