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 not install pygobject directly as a Python package because the handling of that package has hard dependencies system level packges such as Cairo. To avoid pip
build failures due to inconsistencies with different distributions we leave the installation of pygobject
to the system level package manager. For Debian, this means you woulc run the following:
$ sudo apt install python3-gi python3-gi-cairo gir1.2-gtk-3.0
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-2.0.0.tar.gz
.
File metadata
- Download URL: trio-gtk-2.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 | 8edf901f1d118d5414f71eb4495a4023aab827e22bf85df02a24398565d87e76 |
|
MD5 | 2ce5e1e983a85e784e7aae87bbbc6887 |
|
BLAKE2b-256 | 8889f693c770bb154871ec4f7f011db6613e2ff2e826827d708b9d1c9a985cda |
File details
Details for the file trio_gtk-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: trio_gtk-2.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 | cb448783bf3c11d7e7771a4e85618f4227e3e247df49dbabef5f0211d2a57561 |
|
MD5 | e8aa2035d6c5de06511bec1fec086554 |
|
BLAKE2b-256 | 98b430a32c16dadf9ea02c52b7878496d98b6d99151c5ebf2ea9a2d124a57073 |