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
Please note, trio-gtk
does install pygobject directly as a Python package. We use relaxed bounds to ensure that the hard dependency on system packages (see cairo integration documentation will not stop you having a successful installation. This may not always work out. If you see a build error during your Pip installation, please raise a ticket and we will see what we can do.
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
Built Distribution
File details
Details for the file trio-gtk-3.0.0.tar.gz
.
File metadata
- Download URL: trio-gtk-3.0.0.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.2 CPython/3.8.0 Linux/4.9.0-13-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e462512596b3d023b3f093497fc433f67957816284f7761bd6324930472ed4d3 |
|
MD5 | 0de004bac6a0fb17bdc374071fa5eee7 |
|
BLAKE2b-256 | c8df8c8bf5821c5d420fda571a9e301e8c8be2b21f3fa3afeea3e01e8d022323 |
File details
Details for the file trio_gtk-3.0.0-py3-none-any.whl
.
File metadata
- Download URL: trio_gtk-3.0.0-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.2 CPython/3.8.0 Linux/4.9.0-13-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc101157af1f4b60db580930c31b58dec6fcaa58c69e3b26ed5e3b01edac4926 |
|
MD5 | b198cdbd82ca9c930cc5522460e0667b |
|
BLAKE2b-256 | eb266252a04a51ac1974ae84e7074327abd4b2fe057f53fb8a4dd99be796a4e4 |