root/trunk/twisted/internet/tksupport.py

Revision 24441, 1.7 KB (checked in by thijs, 2 years ago)

Merge maintainer-email-2438: Get rid of references to maintainer email addresses from code.

Author: thijs
Reviewer: exarkun
Fixes: #2438

Line 
1# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2# See LICENSE for details.
3
4
5"""
6This module integrates Tkinter with twisted.internet's mainloop.
7
8Maintainer: Itamar Shtull-Trauring
9
10To use, do::
11
12    | tksupport.install(rootWidget)
13
14and then run your reactor as usual - do *not* call Tk's mainloop(),
15use Twisted's regular mechanism for running the event loop.
16
17Likewise, to stop your program you will need to stop Twisted's
18event loop. For example, if you want closing your root widget to
19stop Twisted::
20
21    | root.protocol('WM_DELETE_WINDOW', reactor.stop)
22
23"""
24
25# system imports
26import Tkinter, tkSimpleDialog, tkMessageBox
27
28# twisted imports
29from twisted.python import log
30from twisted.internet import task
31
32
33_task = None
34
35def install(widget, ms=10, reactor=None):
36    """Install a Tkinter.Tk() object into the reactor."""
37    installTkFunctions()
38    global _task
39    _task = task.LoopingCall(widget.update)
40    _task.start(ms / 1000.0, False)
41
42def uninstall():
43    """Remove the root Tk widget from the reactor.
44
45    Call this before destroy()ing the root widget.
46    """
47    global _task
48    _task.stop()
49    _task = None
50
51
52def installTkFunctions():
53    import twisted.python.util
54    twisted.python.util.getPassword = getPassword
55
56
57def getPassword(prompt = '', confirm = 0):
58    while 1:
59        try1 = tkSimpleDialog.askstring('Password Dialog', prompt, show='*')
60        if not confirm:
61            return try1
62        try2 = tkSimpleDialog.askstring('Password Dialog', 'Confirm Password', show='*')
63        if try1 == try2:
64            return try1
65        else:
66            tkMessageBox.showerror('Password Mismatch', 'Passwords did not match, starting over')
67
68__all__ = ["install", "uninstall"]
Note: See TracBrowser for help on using the browser.