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

Uploaded Source

Built Distribution

trio_gtk-0.1.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: trio-gtk-0.1.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

Hashes for trio-gtk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7fc79cff577b1eccfa934b624cf2720e4aa817387d9d364d94e62907f9f49f6c
MD5 25d02b01bfb851250ee0414e726930b6
BLAKE2b-256 47c80ab2d013051705f94b8438c3bf2eaa935f607f8d188c9f3dad57541615ea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: trio_gtk-0.1.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

Hashes for trio_gtk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20f4ecc34aceab914bf63f7b92a3a1e1d63e3ea2c485e1021b2c7077d310f311
MD5 e781dbaaae3b1c2b45a6d55d7b466a9c
BLAKE2b-256 5f8e8db50d349d45665d5a0cca23b7c5ed3280c406870f293f0fc3ad55abec7e

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