File: wait_signal.py

package info (click to toggle)
python-gbulb 0.6.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 244 kB
  • sloc: python: 1,851; makefile: 3
file content (45 lines) | stat: -rw-r--r-- 845 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import asyncio

from gi.repository import Gtk

import gbulb


@asyncio.coroutine
def counter(label):
    i = 0
    while True:
        label.set_text(str(i))
        yield from asyncio.sleep(1)
        i += 1


@asyncio.coroutine
def text_watcher(label):
    while True:
        yield from gbulb.wait_signal(label, "changed")
        print("label changed", label.get_text())


def main():
    gbulb.install(gtk=True)
    loop = gbulb.get_event_loop()

    display = Gtk.Entry()
    vbox = Gtk.VBox()

    vbox.pack_start(display, True, True, 0)

    win = Gtk.Window(title="Counter window")
    win.connect("delete-event", lambda *args: loop.stop())
    win.add(vbox)

    win.show_all()

    asyncio.ensure_future(text_watcher(display))
    asyncio.ensure_future(counter(display))
    loop.run_forever()


if __name__ == "__main__":
    main()