-
Notifications
You must be signed in to change notification settings - Fork 0
/
youdao.py
60 lines (54 loc) · 1.43 KB
/
youdao.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
54
55
56
57
58
59
60
#encoding=utf-8
import webkit, gtk
import thread
import record_xclip
import random
import os
import time
from time import sleep
from Queue import Queue
def lookup():
sleep(5)
pre_text=""
text=""
url=""
#监视history.txt变化
myfile=os.popen("tail -f history.txt")
while True:
text=myfile.readline()
if (pre_text != text):
if (text != ""):
pre_text = text
url="http://dict.youdao.com/search?q=" + text
browser.open(url)
def webshow():
global browser
global Alive
window = gtk.Window()
browser = webkit.WebView()
window.set_default_size(480,320)
window.set_resizable(True)
window.add(browser)
window.show_all()
browser.show()
browser.load_uri("http://dict.youdao.com/search?q=")
window.connect("delete-event", gtk.main_quit)
window.set_title("有道字典")
gtk.main()
Alive=0
def gettext():
record_xclip.record_dpy.record_enable_context(record_xclip.ctx, record_xclip.record_callback)
record_xclip.record_dpy.record_free_context(record_xclip.ctx)
# Main thread
def main():
thread.start_new_thread(gettext,())
thread.start_new_thread(lookup,())
thread.start_new_thread(webshow,())
#运行标志结束
global Alive
Alive=1
while Alive:
sleep(1)
print 'All threads have terminated.'
if __name__ == '__main__':
main()