Start the qubesadmin.events.EventsDispatcher in Gtk Application

10 views
Skip to first unread message

Mohammed Ameen

unread,
Feb 15, 2023, 9:31:41 AM2/15/23
to qubes...@googlegroups.com
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?

Marta Marczykowska-Górecka

unread,
Feb 15, 2023, 10:33:40 AM2/15/23
to Mohammed Ameen, qubes...@googlegroups.com
I'm doing it a bit differently, you can see it in e.g. qubes app menu (
https://github.com/QubesOS/qubes-desktop-linux-menu/blob/main/qubes_menu/appmenu.py#L310
) but both ways should work fine.


Best regards,

Marta Marczykowska-Górecka

Marta Marczykowska-Górecka

unread,
Feb 15, 2023, 10:33:54 AM2/15/23
to Mohammed Ameen, qubes...@googlegroups.com

On 2/15/23 15:17, Mohammed Ameen wrote:
OpenPGP_signature
Reply all
Reply to author
Forward
0 new messages