# How to open a dialog that shows messages asynchronously?

**URL:** <https://forums.ankiweb.net/t/how-to-open-a-dialog-that-shows-messages-asynchronously/33472>\
**Category:** Help\
**Created:** [August 21, 2023, 11:28pm UTC](https://forums.ankiweb.net/t/how-to-open-a-dialog-that-shows-messages-asynchronously/33472 "2023-08-21T23:28:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![regularuser123](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@regularuser123](https://forums.ankiweb.net/u/regularuser123)\
**Post date:** [August 21, 2023, 11:28pm UTC](https://forums.ankiweb.net/t/how-to-open-a-dialog-that-shows-messages-asynchronously/33472/1 "2023-08-21T23:28:08Z")

</div>

I’m creating an add-on that runs Python code that requires some few minutes. I would like to let the user know of the progress of execution, so I’m planning to print some informative messages.

I want to do something like the Ubuntu installer where messages are printed (see images below) (I don’t need to show complex things like a progress bar or remaining time, as the Ubuntu installer does, I just want to print simple messages)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/2X/1/1ef3436d57064b8e429286e07bbcf172a05c4544.jpeg)

Does anyone know an open-source add-on that does something like this so that I can inspect the source code and edit it to my needs? If not, do you know how to do this? Could you point me to the right direction?

# Update

I just learned that when importing cards, Anki uses `showText` to display the information of all the cards that were imported. This message isn’t asynchronous, but it does the job of showing information to the user. I’m going to share some relevant information as I’m going to use for the moment as I’m not very familiar with multithreading (I hope I can learn it in the future).

The following code block contains a minimal working example of using `showText` (just in case anyone is curious).

```auto
import aqt

def my_function():
  very_long_message = ""
  for i in range(1, 100):
    very_long_message = very_long_message + f"{i}\n"
  aqt.utils.showText(very_long_message)

my_action = aqt.qt.QAction("My new action", aqt.mw)
my_action.triggered.connect(my_function)
aqt.mw.form.menuTools.addAction(my_action)

```

Anki defines the class `Importer` and that class has an attribute called `log` which is a list (see [code](https://github.com/ankitects/anki/blob/1aaf6dbf18ba444996dc2ff81f4371ec0c3efe39/pylib/anki/importing/base.py#L22)) and information is appended to that list (see [code](https://github.com/ankitects/anki/blob/1aaf6dbf18ba444996dc2ff81f4371ec0c3efe39/pylib/anki/importing/anki2.py#L149-L168)).

---

<div class="post-metadata">

**Author:** ![abdo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/abdo/32/654_2.png) [@abdo](https://forums.ankiweb.net/u/abdo)\
**Post date:** [August 22, 2023, 12:37am UTC](https://forums.ankiweb.net/t/how-to-open-a-dialog-that-shows-messages-asynchronously/33472/2 "2023-08-22T00:37:39Z")

</div>

One way you can do this is to move long-running tasks to a separate thread, then report progress to the main thread, which will take care of updating the UI.

See [Background Operations - Writing Anki Add-ons](https://addon-docs.ankiweb.net/background-ops.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [September 21, 2023, 12:38am UTC](https://forums.ankiweb.net/t/how-to-open-a-dialog-that-shows-messages-asynchronously/33472/3 "2023-09-21T00:38:31Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
