root/projects/WinDictator/trunk/windictator/linux/pb.py

Revision 19, 3.0 kB (checked in by edsuom, 2 years ago)

Importing windictator into the global FOSS repo

Line 
1 # WinDictator:
2 # Dictate in Windows, have the text typed in Linux via X faked keystroke events
3 #
4 # Copyright (C) 2005-2006 by Edwin A. Suominen, http://www.eepatents.com
5 #
6 # This program is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
9 # version.
10 #
11 # This program is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 # FOR A PARTICULAR PURPOSE.  See the file COPYING for more details.
14 #
15 # You should have received a copy of the GNU General Public License along with
16 # this program; if not, write to the Free Software Foundation, Inc., 51
17 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18
19
20 """
21 Twisted Perspective Broker client that connects to a PB server running on
22 Windows and accepts text from the server for virtual typing.
23 """
24
25 from twisted.spread import pb
26 from twisted.internet import reactor
27
28 from typist import Typist
29
30
31 class ClientRoot(pb.Referenceable):
32     """
33     I provide a method for a local client to send its root object to its
34     server.
35     """
36     def __init__(self):
37         self.typist = Typist()
38
39     def remote_shutdown(self):
40         """
41         Server remote API for shutting down the client
42         """
43         print "SHUTDOWN BY SERVER"
44         d1 = self.typist.shutdown()
45         d2 = defer.Deferred()
46         d2.addCallback(reactor.stop)
47         d1.chainDeferred(d2)
48         return d1
49        
50     def remote_backspace(self, N):
51         """
52         Server remote API for having the client enter I{N} BackSpace key
53         events.
54         """
55         print "BACKSPACE %d" % N
56         return self.typist.backspace(N)
57
58     def remote_insert(self, text):
59         """
60         Server remote API for having the client type I{text} with key events.
61         """
62         print "INSERT '%s'" % text
63         return self.typist.insert(text)
64
65
66 class Client(object):
67     def __init__(self):
68         self.clientRoot = ClientRoot()
69        
70     def connect(self, host, port):
71         """
72         Connects to I{host:port} and stays here if successful
73         """
74         factory = pb.PBClientFactory()
75         reactor.connectTCP(host, port, factory)
76         factory.getRootObject().addCallbacks(self.started, self.oops)
77         reactor.run()
78
79     def started(self, object):
80         """
81         This method is called when the client has made a connection to the
82         server.
83         """
84         d = object.callRemote("greeter", self.clientRoot)
85         d.addCallbacks(self.greeted, self.oops)
86         return d
87
88     def greeted(self, status):
89         """
90         This method is called when the server has responded to the client's
91         offer of its root object.
92         """
93         print "CONNECTED: %s" % ("Busy", "Ready")[status]
94         return self.clientRoot.typist.startup()
95
96     def oops(self, failure):
97         print "CONNECTION FAILURE:", failure
Note: See TracBrowser for help on using the browser.