1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
4 """Demo of wxPython integration with Twisted."""
8 from wx import Frame, DefaultPosition, Size, Menu, MenuBar, App
9 from wx import EVT_MENU, EVT_CLOSE
11 from twisted.python import log
12 from twisted.internet import wxreactor
15 # import t.i.reactor only after installing wxreactor:
16 from twisted.internet import reactor
22 def __init__(self, parent, ID, title):
23 Frame.__init__(self, parent, ID, title, DefaultPosition, Size(300, 200))
25 menu.Append(ID_EXIT, "E&xit", "Terminate the program")
27 menuBar.Append(menu, "&File")
28 self.SetMenuBar(menuBar)
29 EVT_MENU(self, ID_EXIT, self.DoExit)
31 # make sure reactor.stop() is used to stop event loop:
32 EVT_CLOSE(self, lambda evt: reactor.stop())
34 def DoExit(self, event):
40 def twoSecondsPassed(self):
41 print "two seconds passed"
44 frame = MyFrame(None, -1, "Hello, world")
46 self.SetTopWindow(frame)
47 # look, we can use twisted calls!
48 reactor.callLater(2, self.twoSecondsPassed)
53 log.startLogging(sys.stdout)
55 # register the App instance with Twisted:
57 reactor.registerWxApp(app)
59 # start the event loop:
63 if __name__ == '__main__':