On 2/15/23 15:17, Mohammed Ameen wrote:
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?
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
--
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/57d75b47-e7b7-cc49-fd5f-7de14022fc07%40invisiblethingslab.com.