-
Notifications
You must be signed in to change notification settings - Fork 3
/
App.py
87 lines (66 loc) · 1.93 KB
/
App.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
# coding=utf-8
import pygtk
pygtk.require('2.0')
import gtk
import gobject
import time
import threading
import os
from wordutil import wordutil
closing = False
def init_ddict():
vbox = gtk.VBox()
swindow = gtk.ScrolledWindow()
text = gtk.TextView()
text.set_editable(False)
textbuffer = text.get_buffer()
textbuffer.set_text("Welcome to DDict")
text.set_buffer(textbuffer)
swindow.add(text)
youdao_logo = gtk.Image()
youdao_logo.set_from_file(get_resource_path("images/youdao.gif"))
vbox.pack_start(youdao_logo)
vbox.pack_start(swindow)
wu = wordutil()
return text,textbuffer,wu,vbox
def run_tasks(mtext,mtextbuffer,mwordutil,isclose):
global closing
gobject.threads_init()
while(not closing):
gtk.threads_enter()
result = mwordutil.execfind()
#print result
#print "run"
if(result!=""):
mtextbuffer.set_text(result)
mtext.set_buffer(mtextbuffer)
gtk.threads_leave()
time.sleep(0.1)
def get_resource_path(rel_path):
dir_of_py_file = os.path.dirname(__file__)
rel_path_to_resource = os.path.join(dir_of_py_file,rel_path)
abs_path_to_resource = os.path.abspath(rel_path_to_resource)
return abs_path_to_resource
def main():
txt,txtb,wu,vb = init_ddict()
global closing
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.set_title("DDict")
window.set_default_size(300,200)
window.set_keep_above(True)
window.connect('destroy',main_quit)
#window.connect("destroy",lambda a:gtk.main_quit())
window.add(vb)
window.set_icon_from_file(get_resource_path("images/logo.png"))
window.show_all()
thread = threading.Thread(target=run_tasks,args=(txt,txtb,wu,closing))
#thread.deamon = True
thread.start()
gtk.main()
def main_quit():
global closing
closing = True
gtk.main_quit()
if __name__ == '__main__':
main()