~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

Viewing changes to twisted/internet/wxreactor.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-01-16 19:56:10 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060116195610-ykmxbia4mnnod9o2
Tags: 2.1.0-0ubuntu2
debian/copyright: Include copyright for python 2.3; some 2.3 files
are included in the upstream tarball, but not in the binary packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
from twisted.python.runtime import seconds
33
33
from twisted.python import log
34
 
from twisted.internet import selectreactor
35
 
 
36
 
from wxPython.wx import wxTimer, wxApp
37
 
 
38
 
 
39
 
class ReactorTimer(wxTimer):
40
 
    """Run reactor event loop every millisecond."""
41
 
 
42
 
    # The wx docs promise no better than 1ms and no worse than 1s (!) 
43
 
    # Experiments have shown that Linux, gets better than 50K timer 
44
 
    # calls per second --  however, Windows only gets around 100 
45
 
    # timer calls per second. Caveat coder.
46
 
    def __init__(self, reactor): 
47
 
        wxTimer.__init__(self) 
48
 
        self.reactor = reactor
49
 
        self.Start(1) 
50
 
 
51
 
    def Notify(self): 
52
 
        """Called every timer interval"""
53
 
        self.reactor.simulate()
 
34
from twisted.internet import threadedselectreactor
 
35
 
 
36
from wxPython.wx import wxApp, wxCallAfter, wxEventLoop, wxFrame, NULL
54
37
 
55
38
 
56
39
class DummyApp(wxApp):
59
42
        return True
60
43
 
61
44
 
62
 
class WxReactor(selectreactor.SelectReactor):
 
45
class WxReactor(threadedselectreactor.ThreadedSelectReactor):
63
46
    """wxPython reactor.
64
47
 
65
48
    wx drives the event loop, and calls Twisted every millisecond, and
69
52
    def registerWxApp(self, wxapp):
70
53
        """Register wxApp instance with the reactor."""
71
54
        self.wxapp = wxapp
 
55
        self.interleave(wxCallAfter)
72
56
    
73
57
    def crash(self):
74
 
        selectreactor.SelectReactor.crash(self)
75
 
        self.timer.Stop()
76
 
        del self.timer
77
 
        self.wxapp.ExitMainLoop()
78
 
 
 
58
        threadedselectreactor.ThreadedSelectReactor.crash(self)
 
59
        if hasattr(self, "wxapp"):
 
60
            self.wxapp.ExitMainLoop()
 
61
    
79
62
    def run(self, installSignalHandlers=1):
80
63
        if not hasattr(self, "wxapp"):
81
64
            log.msg("registerWxApp() was not called on reactor, this is probably an error.")
82
 
            self.wxapp = DummyApp(0)
 
65
            self.registerWxApp(DummyApp(0))
83
66
        self.startRunning(installSignalHandlers=installSignalHandlers)
84
 
        self.timer = ReactorTimer(self)
85
67
        self.wxapp.MainLoop()
86
 
    
87
 
    def simulate(self):
88
 
        """Run simulation loops and reschedule callbacks.
89
 
        """
90
 
        if self.running:
91
 
            t = 0.01
92
 
            start = seconds()
93
 
            while t > 0:
94
 
                self.iterate(t)
95
 
                t = 0.01 - (seconds() - start)
96
68
 
97
69
 
98
70
def install():