Repository navigation
Expand file tree
/
Copy pathmain_gui_rcfd_process.py
More file actions
executable file
·152 lines (122 loc) · 5.04 KB
/
Copy pathmain_gui_rcfd_process.py
File metadata and controls
executable file
·152 lines (122 loc) · 5.04 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import tkinter as tk
from tkinter import ttk, filedialog, scrolledtext
import watchrcfd_class
# , test_files_h5
#from common_methods import Common
#import queue as Queue
import threading
import time
import os
def main():
root = tk.Tk()
GUIrcfd(root)
root.mainloop()
class GUIrcfd:
def __init__(self, root):
self.root = root
self.default_source_path = "D://test source folder"
self.default_goal_path = "D://test goal folder"
self.root.title('Orignal Data Processing Panel')
self.root.geometry("1040x680+30+30")
bsource = ttk.Button(self.root, text="Watch folder",
command=self.get_source_path)
bsource.place(x=20, y=40, width=90, height=25)
self.lsource = ttk.Label(
self.root, text=self.default_source_path, background="yellow")
self.lsource.place(x=120, y=40, width=360, height=25)
bgoal = ttk.Button(self.root, text="Result folder",
command=self.get_goal_path)
bgoal.place(x=20, y=90, width=90, height=25)
self.lgoal = ttk.Label(
self.root, text=self.default_goal_path, background="yellow")
self.lgoal.place(x=120, y=90, width=360, height=25)
self.bstart = ttk.Button(
self.root, text="Start", command=self.c_bstart)
self.bstart.place(x=150, y=150, width=50, height=25)
bstop = ttk.Button(self.root, text="Stop", command=self.c_bstop)
bstop.place(x=250, y=150, width=50, height=25)
ttk.Label(self.root, text="Scan rcdf files:").place(
x=20, y=200, width=460, height=25)
self.cdisplay = tk.scrolledtext.ScrolledText(
master=self.root, wrap=tk.WORD, font=("Helvetica", 8))
self.cdisplay.place(x=20, y=230, width=460, height=420)
ttk.Label(self.root, text="Log info:").place(
x=520, y=40, width=500, height=25)
self.result_display = tk.scrolledtext.ScrolledText(
master=self.root, wrap=tk.WORD, font=("Helvetica", 8))
self.result_display.place(x=520, y=70, width=500, height=580)
def get_source_path(self):
root = tk.Tk()
root.withdraw()
self.default_source_path = filedialog.askdirectory()
print(self.default_source_path)
self.lsource['text'] = self.default_source_path
def get_goal_path(self):
root = tk.Tk()
root.withdraw()
self.default_goal_path = filedialog.askdirectory()
self.lgoal['text'] = self.default_goal_path
def c_bstart(self):
self.bstart.config(state="disabled")
# run rcfd process
def callback():
self.w = watchrcfd_class.Watcher(
self.default_source_path, self.default_goal_path)
self.w.run()
# run button blick process
def callback2():
try:
while True:
self.bstart.config(text="scan")
time.sleep(0.5)
self.bstart.config(text="scan.")
time.sleep(0.5)
self.bstart.config(text="scan..")
time.sleep(0.5)
self.bstart.config(text="scan...")
time.sleep(0.5)
except:
print("Error1")
# update
def update_log(self):
msg1 = self.w.get_msg()
if msg1 != "":
self.cdisplay.insert("end", msg1 + "\n")
logfile = os.path.join(self.default_goal_path, "log.txt")
# 1. establish a new log.txt
wr = open(logfile, 'w')
wr.write("")
wr.close()
# 2. old log = emtpy
log1, log2, add = "", "", ""
try:
while True:
time.sleep(2)
if os.path.isfile(logfile):
with open(logfile) as log:
log2 = log.read()
if log2 != log1:
add = log2.replace(log1, "")
if add != "":
self.result_display.insert("end", add)
self.result_display.yview_pickplace("end")
log1 = log2
msg2 = self.w.get_msg()
if msg2 != msg1:
self.cdisplay.insert("end", msg2 + "\n")
msg1 = msg2
except:
print("Error2")
self.t = threading.Thread(target=callback)
self.t.daemon = True
self.t.start()
self.t2 = threading.Thread(target=callback2)
self.t2.daemon = True
self.t2.start()
self.t3 = threading.Thread(target=lambda: update_log(self))
self.t3.daemon = True
self.t3.start()
def c_bstop(self):
self.t._stop()
if __name__ == "__main__":
main()