I would like to use the `qubesadmin.events.EventsDispatcher` in my Gtk
Application. What is the best way to start listening for the dispatcher
events without causing any Gtk thread issues.

Currently, I use the `qubesadmin.events.EventsDispatcher` is follow:

**main.py**
```python
import asyncio
import qubesadmin
import qubesadmin.events

import gbulb
gbulb.install()

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk


def start_qubes_dispatcher(qubes, dispatcher):
    loop = asyncio.get_event_loop()
    tasks = [
        asyncio.ensure_future(
            dispatcher.listen_for_events()
        )
    ]

    loop.run_until_complete(
        asyncio.wait(
            tasks, return_when=asyncio.FIRST_EXCEPTION
        )
    )

global label
def update_label(*args, **kwargs):
    label.set_text(f'The current event is {args[1]}')
    label.show_all()

qubes = qubesadmin.Qubes()
dispatcher = qubesadmin.events.EventsDispatcher(qubes)
dispatcher.add_handler('*', update_label)

window = Gtk.Window()

label = Gtk.Label()

window.add(label)

window.show_all()

start_qubes_dispatcher(qubes, dispatcher)
Gtk.main()
```

Is this the best way and thread safest to use the
`qubesadmin.events.EventsDispatcher` with Gtk applications?

-- 
You received this message because you are subscribed to the Google Groups 
"qubes-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to qubes-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/qubes-devel/CAA-3NOA1LvEAVreY1G17r3qdUbzJn_ofZAGLfP8uYOAsg4SWaQ%40mail.gmail.com.

Reply via email to