-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDragonCorrectionDialog.py
53 lines (46 loc) · 1.71 KB
/
DragonCorrectionDialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
print "importing " + __file__
import SimpleXMLRPCServer
import sys
import signal
import os
import wx
from threading import Timer
LISTENING_PORT = 1338
DIALOG_TITLE = "Correction Dialog"
def communicate():
return SimpleXMLRPCServer.xmlrpclib.ServerProxy("http://127.0.0.1:" + str(LISTENING_PORT))
class DragonCorrectionDialog():
def __init__(self, heard):
self.completed = False
self.setup_XMLRPC_server()
dlg = wx.TextEntryDialog(None, "Correct with...", caption="Correction Dialog", defaultValue=heard)
dlg.ShowModal()
self.correction = dlg.GetValue()
self.completed = True
# start server, tk main loop
def start_server():
while not self.server_quit:
self.server.handle_request()
Timer(1, start_server).start()
# backup plan in case for whatever reason Dragon doesn't shut it down:
Timer(60, self.xmlrpc_kill).start()
def setup_XMLRPC_server(self):
self.server_quit = 0
self.server = SimpleXMLRPCServer.SimpleXMLRPCServer(("127.0.0.1", LISTENING_PORT), allow_none=True)
self.server.register_function(self.xmlrpc_get_message, "get_message")
self.server.register_function(self.xmlrpc_kill, "kill")
def xmlrpc_kill(self):
self.server_quit = 1
os.kill(os.getpid(), signal.SIGTERM)
def xmlrpc_get_message(self):
print "get message called"
if self.completed:
Timer(1, self.xmlrpc_kill).start()
return self.correction
else:
return None
if __name__ == "__main__":
heard = sys.argv[1]
app = wx.App()
app.MainLoop()
DragonCorrectionDialog(heard)