aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/Twisted-12.2.0-py2.7-linux-x86_64.egg/twisted/internet/wxsupport.py
blob: d17c6663046fa621133e0e1dcbf99922e893f78a (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

# 
"""Old method of wxPython support for Twisted.

twisted.internet.wxreactor is probably a better choice.

To use::

    | # given a wxApp instance called myWxAppInstance:
    | from twisted.internet import wxsupport
    | wxsupport.install(myWxAppInstance)
    
Use Twisted's APIs for running and stopping the event loop, don't use
wxPython's methods.

On Windows the Twisted event loop might block when dialogs are open
or menus are selected.

Maintainer: Itamar Shtull-Trauring
"""

import warnings
warnings.warn("wxsupport is not fully functional on Windows, wxreactor is better.")

# wxPython imports
from wxPython.wx import wxApp

# twisted imports
from twisted.internet import reactor
from twisted.python.runtime import platformType


class wxRunner:
    """Make sure GUI events are handled."""
    
    def __init__(self, app):
        self.app = app
        
    def run(self):
        """
        Execute pending WX events followed by WX idle events and
        reschedule.
        """
        # run wx events
        while self.app.Pending():
            self.app.Dispatch()
        
        # run wx idle events
        self.app.ProcessIdle()
        reactor.callLater(0.02, self.run)


def install(app):
    """Install the wxPython support, given a wxApp instance"""
    runner = wxRunner(app)
    reactor.callLater(0.02, runner.run)


__all__ = ["install"]