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.

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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: trio-gtk-1.0.1.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-1.0.1.tar.gz
Algorithm Hash digest
SHA256 603b18d5dd2232f9211885e9bd1edcbcb1119865e41df5daa00803bdfa9960fb
MD5 1994cec0307d1517c38297fcc0a71f21
BLAKE2b-256 aed4144d0ca97490a3f71f45e1e96afae46f6501d1d5c3294d6c1366307ba2af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: trio_gtk-1.0.1-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-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1bccd5f7e29bd599394467f291deee3ddaac10a2ffa72ec1ae8d38eef3d104a9
MD5 c9af7d91cdd725fa8e5ae9521c39fde2
BLAKE2b-256 618b742f7847de419d82e260e4cdfbf90543bf762e973fd5c3b17a545d79b70a

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