Start the qubesadmin.events.EventsDispatcher in Gtk Application

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

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?

1 Like

This is a legit developer question and you’d probably get a faster answer when posting to the qubes-devel mailing list or asking in the #qubes IRC channel.

Moved to User Support

Here is the link for the google groups email Google Group. If anyone is interested to follow with the question.

1 Like