Trio guest mode wrapper for PyGTK
Project description
trio-gtk
Trio guest mode wrapper for PyGTK
Using the Trio guest mode feature, we can run both the Trio and PyGTK event loops alongside each other in a single program. This allows us to make use of the Trio library and the usual async
/await
syntax and not have to directly manage thread pools. This library provides a thin wrapper for initialising the guest mode and exposes a single public API function, trio_gtk.run
into which you can pass your Trio main function.
Install
$ pip install trio-gtk
Example
import gi
import trio
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk as gtk
import trio_gtk
class Example(gtk.Window):
def __init__(self, nursery):
gtk.Window.__init__(self, title="Example")
self.button = gtk.Button(label="Create a task")
self.button.connect("clicked", self.on_click)
self.add(self.button)
self.counter = 0
self.nursery = nursery
self.connect("destroy", gtk.main_quit)
self.show_all()
def on_click(self, widget):
self.counter += 1
self.nursery.start_soon(self.say_hi, self.counter)
async def say_hi(self, count):
while True:
await trio.sleep(1)
print(f"hi from task {count}")
async def main():
async with trio.open_nursery() as nursery:
Example(nursery)
await trio.sleep_forever()
trio_gtk.run(main)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
trio-gtk-1.0.0.tar.gz
(15.0 kB
view details)
Built Distribution
trio_gtk-1.0.0-py3-none-any.whl
(14.6 kB
view details)
File details
Details for the file trio-gtk-1.0.0.tar.gz
.
File metadata
- Download URL: trio-gtk-1.0.0.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.8.0 Linux/4.9.0-13-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0b58812ca1276ff84d741967b6752ca35f894ed8627414debc1db9c94e757ce |
|
MD5 | 1ac22ba35b9c0d8f673e1addda9e661a |
|
BLAKE2b-256 | 7c8fbe5cf01446d12967f66849913b22fe5425a723af92b6a80c7ec74a512547 |
File details
Details for the file trio_gtk-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: trio_gtk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.9 CPython/3.8.0 Linux/4.9.0-13-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b98d24a44076ae25201179d70f657a1d5fab433576c3acad63eaca46d6cb315c |
|
MD5 | 42f3094ae8ca24b3f609c559aaba3327 |
|
BLAKE2b-256 | 0c2ac8c1581fd3f450ad8ef310ef8187062e12e833d4c8e513319070485ea7ac |