-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
189 lines (145 loc) · 6.63 KB
/
main.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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# This is a sample Python script.
# Press ⇧⌘F11 to execute it or replace it with your code.
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.
import tkinter as tk
import tkinter.filedialog
from typing import List
from conditionmanager import ConditionListWindow
from eventwindow import EventSelectWindow
from filterutils import filterFile, Condition, parseFile, StartLine
from realtimelogfilter import RealTimeLogFilter
from simulatesignalwindow import SimulateSignalWindow
from timelinewindow import TimeLineWindow
def openFileDialog():
global gl_condition_list, gl_start_list, gl_root
filename = tk.filedialog.askopenfilename(initialdir='/Users/jiangfeng/log/scene')
if filename is not None and filename != '':
gl_root.title(filename)
# filterFile(filename, condition_dict.values(), text)
gl_start_list = parseFile(filename)
TimeLineWindow(gl_root, gl_start_list).show(lambda startline, endline: filterFilePiece(startline, endline))
else:
gl_root.title(default_title)
global gl_file_name
gl_file_name = filename
def filterFilePiece(startline, endline):
global text_main, gl_condition_list, gl_start_line, gl_end_line, gl_file_name
gl_start_line = startline
gl_end_line = endline
if gl_file_name is None or gl_start_line is None:
return
text_main.delete(0.0, tk.END)
filterFile(gl_file_name, startline, endline, gl_condition_list,
lambda strline: text_main.insert(tk.INSERT, strline))
def onFilterClick():
global gl_file_name, gl_condition_list
if gl_file_name is not None and gl_file_name != '':
filterFile(gl_file_name, gl_condition_list, lambda strline: text_main.insert(tk.INSERT, strline))
def onConditionChangedCallback(condition_list):
global gl_condition_list, gl_start_line, gl_end_line, gl_real_time_log_filter
gl_condition_list = condition_list
filterFilePiece(gl_start_line, gl_end_line)
if gl_real_time_log_filter is not None:
gl_real_time_log_filter.setConditions(condition_list)
def openFilterDialog():
global gl_ConditionListWindow
if gl_ConditionListWindow is None:
gl_ConditionListWindow = ConditionListWindow(gl_root, onConditionChangedCallback)
gl_ConditionListWindow.show()
def openEventDialog():
global gl_EventSelectWindow
if gl_EventSelectWindow is None:
gl_EventSelectWindow = EventSelectWindow(gl_root, onConditionChangedCallback)
gl_EventSelectWindow.show()
def appendTextCallback(strline):
global text_main, gl_vbar
text_main.insert(tk.END, strline)
yview = text_main.yview()[1]
if yview > 0.999:
text_main.yview(tk.MOVETO, 1.0)
def startRealTimeLog():
global text_main, gl_condition_list, gl_real_time_log_filter, gl_btn_real_time_log
if gl_real_time_log_filter is None:
text_main.delete(0.0, tk.END)
realfilter = RealTimeLogFilter(lambda strline: appendTextCallback(strline))
realfilter.setConditions(gl_condition_list)
realfilter.start()
gl_real_time_log_filter = realfilter
gl_btn_real_time_log.config(text='停止log')
else:
gl_real_time_log_filter.stop()
gl_real_time_log_filter = None
gl_btn_real_time_log.config(text='实时log')
def openSimulateSignalWindow():
global gl_root, gl_SimulateSignalWindow
if gl_SimulateSignalWindow is None:
gl_SimulateSignalWindow = SimulateSignalWindow(gl_root)
gl_SimulateSignalWindow.show()
def closeWindowCallback():
global gl_root
gl_root.destroy()
# if messagebox.askokcancel("Quit", "Do you really wish to quit?"):
# gl_root.destroy()
def showTextPopupMenu(event):
global gl_root, text_main
menu = tk.Menu(gl_root, tearoff=False)
menu.add_command(label='clean', command=lambda: text_main.delete(0.0, tk.END))
menu.post(event.x_root, event.y_root)
if __name__ == '__main__':
default_title = '场景引擎log分析工具'
gl_start_list: List[StartLine] = []
gl_file_name: str = None
gl_condition_list: List[Condition] = []
gl_start_line: int = None
gl_end_line: int = None
gl_SimulateSignalWindow: SimulateSignalWindow = None
gl_EventSelectWindow: EventSelectWindow = None
gl_ConditionListWindow: ConditionListWindow = None
# 添加主窗口,获取屏幕尺寸以计算布局参数,使窗口居屏幕中央
gl_root = tk.Tk()
gl_root.title(default_title)
width = 1100
height = 700
screenwidth = gl_root.winfo_screenwidth()
screenheight = gl_root.winfo_screenheight()
size_geo = '%dx%d+%d+%d' % (width, height, 100, 100)
gl_root.geometry(size_geo)
# -------------- 第一层 工具栏 --------------
# 添加上部按钮容器
first_frame = tk.LabelFrame(gl_root, relief='raised')
first_frame.pack(side='top', fill='x')
# 打开文件按钮
btn_open_log_file = tk.Button(first_frame, text="log文件", command=openFileDialog)
btn_open_log_file.pack(side='left')
# 条件窗口 按钮
btn_filter_dialog = tk.Button(first_frame, text="条件窗口", command=openFilterDialog)
btn_filter_dialog.pack(side='left')
# 事件窗口 按钮
btn_event_dialog = tk.Button(first_frame, text="事件窗口", command=openEventDialog)
btn_event_dialog.pack(side='left')
# 实时log 按钮
gl_real_time_log_filter: RealTimeLogFilter = None
gl_btn_real_time_log = tk.Button(first_frame, text="实时log", command=startRealTimeLog)
gl_btn_real_time_log.pack(side='left')
# 模拟信号工具窗 按钮
gl_btn_simulate = tk.Button(first_frame, text="模拟信号", command=openSimulateSignalWindow)
gl_btn_simulate.pack(side='left')
# -------------- 第二层 工具栏 --------------
second_frame = tk.LabelFrame(gl_root)
second_frame.pack(side='top', fill='x')
# -------------- 文本显示区域 --------------
# 用于显示log文本的文本框和滚动条
hbar = tk.Scrollbar(gl_root, orient='horizontal')
hbar.pack(side='bottom', fill='x')
gl_vbar = tk.Scrollbar(gl_root, orient='vertical')
gl_vbar.pack(side='right', fill='y')
text_main = tk.Text(gl_root, width=1800, height=800, font=('Menlo Regular', 14), wrap='char', spacing1=5,
xscrollcommand=hbar.set, yscrollcommand=gl_vbar.set)
text_main.bind('<Button-2>', lambda event: showTextPopupMenu(event))
text_main.pack(side='left', fill='both')
gl_vbar.config(command=text_main.yview)
hbar.config(command=text_main.xview)
gl_root.wm_protocol("WM_DELETE_WINDOW", lambda: closeWindowCallback())
# 自动加载默认条件配置文件
openFilterDialog()
gl_root.mainloop()