aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/Twisted/py3/twisted/internet/pyuisupport.py
blob: 265fea2405576cf0985e5531abd70d2d8e12ed67 (plain) (blame)
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
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.


"""
This module integrates PyUI with twisted.internet's mainloop.

Maintainer: Jp Calderone

See doc/examples/pyuidemo.py for example usage.
"""

# System imports
import pyui  # type: ignore[import-not-found]


def _guiUpdate(reactor, delay):
    pyui.draw()
    if pyui.update() == 0:
        pyui.quit()
        reactor.stop()
    else:
        reactor.callLater(delay, _guiUpdate, reactor, delay)


def install(ms=10, reactor=None, args=(), kw={}):
    """
    Schedule PyUI's display to be updated approximately every C{ms}
    milliseconds, and initialize PyUI with the specified arguments.
    """
    d = pyui.init(*args, **kw)

    if reactor is None:
        from twisted.internet import reactor
    _guiUpdate(reactor, ms / 1000.0)
    return d


__all__ = ["install"]