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

« back to all changes in this revision

Viewing changes to doc/examples/wxdemo.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-02-22 22:52:47 UTC
  • Revision ID: james.westby@ubuntu.com-20060222225247-0mjb8ij9473m5zse
Tags: 2.2.0-1ubuntu1
Synchronize with Debian unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2
2
# See LICENSE for details.
3
3
 
4
 
 
 
4
import sys, random
5
5
from wxPython.wx import *
6
6
 
 
7
from twisted.python import log
7
8
from twisted.internet import wxreactor
8
9
wxreactor.install()
9
 
from twisted.internet import reactor
 
10
from twisted.internet import reactor, defer
10
11
 
11
12
 
12
13
# set up so that "hello, world" is printed once a second
 
14
dc = None
13
15
def helloWorld():
14
 
    print "hello, world"
15
 
    reactor.callLater(1, helloWorld)
16
 
reactor.callLater(1, helloWorld)
 
16
    global dc
 
17
    print "hello, world (%s)" % (random.randint(0, 9),)
 
18
    dc = reactor.callLater(0.1, helloWorld)
 
19
dc = reactor.callLater(0.1, helloWorld)
17
20
 
18
21
def twoSecondsPassed():
19
22
    print "two seconds passed"
20
23
 
 
24
def printer(s):
 
25
    print s
 
26
 
 
27
def shutdown():
 
28
    print "shutting down in 0.3 seconds"
 
29
    if dc.active():
 
30
        dc.cancel()
 
31
    reactor.callLater(0.1, printer, "2...")
 
32
    reactor.callLater(0.2, printer, "1...")
 
33
    reactor.callLater(0.3, printer, "0...")
 
34
    d = defer.Deferred()
 
35
    reactor.callLater(0.3, d.callback, 1)
 
36
    return d
 
37
 
21
38
reactor.callLater(2, twoSecondsPassed)
 
39
reactor.addSystemEventTrigger("before", "shutdown", shutdown)
 
40
 
22
41
 
23
42
ID_EXIT  = 101
24
43
ID_DIALOG = 102
34
53
        self.SetMenuBar(menuBar)
35
54
        EVT_MENU(self, ID_EXIT,  self.DoExit)
36
55
        EVT_MENU(self, ID_DIALOG,  self.DoDialog)
 
56
        # you really ought to do this instead of reactor.stop() in
 
57
        # DoExit, but for the sake of testing we'll let closing the
 
58
        # window shutdown wx without reactor.stop(), to make sure that
 
59
        # still does the right thing.
 
60
        #EVT_CLOSE(self, lambda evt: reactor.stop())
37
61
    
38
62
    def DoDialog(self, event):
39
63
        dl = wxMessageDialog(self, "Check terminal to see if messages are still being "
40
64
                             "printed by Twisted.")
41
65
        dl.ShowModal()
42
66
        dl.Destroy()
43
 
    
 
67
 
44
68
    def DoExit(self, event):
45
 
        self.Close(true)
46
69
        reactor.stop()
47
70
 
48
71
 
56
79
 
57
80
 
58
81
def demo():
 
82
    log.startLogging(sys.stdout)
59
83
    app = MyApp(0)
60
84
    reactor.registerWxApp(app)
61
 
    reactor.run(0)
 
85
    reactor.run()
62
86
 
63
87
 
64
88
if __name__ == '__main__':