Skip to main content

Trio guest mode wrapper for PyGTK

Project description

trio-gtk

Build Status

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. This function must accept a nursery argument which can spawn child tasks for the duration of the host loop.

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(nursery):
    Example(nursery)


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-0.1.1.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

trio_gtk-0.1.1-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file trio-gtk-0.1.1.tar.gz.

File metadata

  • Download URL: trio-gtk-0.1.1.tar.gz
  • Upload date:
  • Size: 15.1 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

Hashes for trio-gtk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0a1e7461ce57c5a6950f10133aea73c1ba013404c0717b11f17ea8a15c92fb5f
MD5 706f266c289920436fdb82c7c54b073e
BLAKE2b-256 792a615e30ac0ab238f4a2d95e96ac2e9617b12f1480fe30c3c479d506e9d061

See more details on using hashes here.

File details

Details for the file trio_gtk-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: trio_gtk-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.7 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

Hashes for trio_gtk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b0d37dd11e7b1368c4ae2c67ea6f7cde48f5bebb305edf35297ac0ef31d9656d
MD5 ca752a2aaf565be35f811c53c6032d96
BLAKE2b-256 dbd03a7d21333036d91c89885600cf71ad2e7579b88851982f9110ad4bf9347d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page