-
Notifications
You must be signed in to change notification settings - Fork 0
/
mike_gui.py
225 lines (185 loc) · 8.26 KB
/
mike_gui.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import sys
import glob
from PyQt5.QtWidgets import QApplication, QPushButton, QVBoxLayout, QWidget, QMessageBox, QTextEdit
from PyQt5.QtGui import QIcon
import os
import xlsx2csv_all # 导入你的 xlsx 转换脚本
import csv_rn_cap # 导入你的 csv 重命名脚本
import mks2chainage # 导入你的 mks2chainage 脚本
import chg_split # 导入你的 chg_split 脚本
import chg_insert # 导入你的 chg_insert 脚本
import clean_csv # 导入你的 clean_csv 脚本
import get_virtual_end # 导入你的 get_virtual_end 脚本
import virtual_start
import mkcc
import virtual_end
import virtual_end_update
BASE_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
def combine_files():
if os.path.isfile('./processed_data/combined.txt'):
os.remove('./processed_data/combined.txt')
with open('./combined.txt', 'w') as outfile:
for filename in glob.glob('./processed_data/txt_updated_files/*.txt'):
with open(filename, 'r') as readfile:
outfile.write(readfile.read())
class EmittingStream:
def __init__(self, text_widget):
self.text_widget = text_widget
def write(self, message):
self.text_widget.append(message)
def flush(self):
pass
def run_xlsx_to_csv_script():
xlsx2csv_all.BASE_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
sys.stdout = EmittingStream(output_area)
try:
xlsx2csv_all.main()
QMessageBox.information(window, "完成", "XLSX 到 CSV 转换完成!")
except Exception as e:
QMessageBox.critical(window, "错误", f"转换过程中出现错误:{e}")
sys.stdout = sys.__stdout__
def run_csv_rename_script():
sys.stdout = EmittingStream(output_area) # 重定向输出到 QTextEdit
try:
csv_rn_cap.main() # 直接运行 csv 重命名脚本的 main 函数
QMessageBox.information(window, "完成", "CSV 文件重命名完成!")
except Exception as e:
QMessageBox.critical(window, "错误", f"重命名过程中出现错误:{e}")
sys.stdout = sys.__stdout__ # 恢复标准输出
def run_mks2chainage_script():
input_file_path = os.path.join(BASE_DIR, 'secss.txt') # 定义输入文件路径
sys.stdout = EmittingStream(output_area)
try:
mks2chainage.main(input_file_path)
QMessageBox.information(
window, "完成", "MIKE 断面文件转为里程csv文件完成,保存为chainage.csv!")
except Exception as e:
QMessageBox.critical(window, "错误", f"mks2chainage 脚本执行过程中出现错误:{e}")
sys.stdout = sys.__stdout__
def run_chg_split():
sys.stdout = EmittingStream(output_area)
try:
chg_split.main()
QMessageBox.information(
window, "完成", "根据chainage.csv文件分割断面完成!保存在chg_files文件夹中!")
except Exception as e:
QMessageBox.critical(window, "错误", f"chg_split 脚本执行过程中出现错误:{e}")
sys.stdout = sys.__stdout__
def run_chg_insert():
sys.stdout = EmittingStream(output_area)
try:
chg_insert.main()
QMessageBox.information(
window, "完成", "根据chainage files in chg_files 插入相关断面信息到对应文件 保存在 inserted_files 文件夹中!")
except Exception as e:
QMessageBox.critical(window, "错误", f"chg_split 脚本执行过程中出现错误:{e}")
sys.stdout = sys.__stdout__
def run_clean_csv():
sys.stdout = EmittingStream(output_area)
try:
clean_csv.main()
QMessageBox.information(
window, "完成", "根据chainage files in chg_files 插入相关断面信息到对应文件 保存在 inserted_files 文件夹中!")
except Exception as e:
QMessageBox.critical(window, "错误", f"run_clean_csv 脚本执行过程中出现错误:{e}")
sys.stdout = sys.__stdout__
def run_mkcc():
sys.stdout = EmittingStream(output_area)
try:
mkcc.main()
QMessageBox.information(
window, "完成", "根据chainage files in chg_files 插入相关断面信息到对应文件 保存在 inserted_files 文件夹中!")
except Exception as e:
QMessageBox.critical(window, "错误", f"run_mkcc 脚本执行过程中出现错误:{e}")
sys.stdout = sys.__stdout__
def run_get_virtual_end():
sys.stdout = EmittingStream(output_area)
try:
get_virtual_end.main()
QMessageBox.information(
window, "完成", "虚拟断面里程提取完成!保存在 processed_data 文件夹中 !")
except Exception as e:
QMessageBox.critical(window, "错误", f"run_get_virtual_end 脚本执行过程中出现错误:{e}")
sys.stdout = sys.__stdout__
def run_virtual_start():
sys.stdout = EmittingStream(output_area)
try:
virtual_start.main()
QMessageBox.information(
window, "完成", "虚拟断面里程提取完成!保存在 processed_data 文件夹中!")
except Exception as e:
QMessageBox.critical(window, "错误", f"run_get_virtual_end 脚本执行过程中出现错误:{e}")
sys.stdout = sys.__stdout__
def run_virtual_end():
sys.stdout = EmittingStream(output_area)
try:
virtual_end.main()
QMessageBox.information(
window, "完成", "虚拟断面里程提取完成!保存在 processed_data 文件夹中!")
except Exception as e:
QMessageBox.critical(window, "错误", f"run_get_virtual_end 脚本执行过程中出现错误:{e}")
sys.stdout = sys.__stdout__
def run_virtual_end_update():
sys.stdout = EmittingStream(output_area)
try:
virtual_end_update.main()
QMessageBox.information(
window, "完成", "虚拟断面里程提取完成!保存在 processed_data 文件夹中!")
except Exception as e:
QMessageBox.critical(window, "错误", f"run_get_virtual_end 脚本执行过程中出现错误:{e}")
sys.stdout = sys.__stdout__
def run_combine_files():
sys.stdout = EmittingStream(output_area)
try:
combine_files()
QMessageBox.information(
window, "完成", "虚拟断面里程提取完成!保存在 processed_data 文件夹中!")
except Exception as e:
QMessageBox.critical(window, "错误", f"run_get_virtual_end 脚本执行过程中出现错误:{e}")
sys.stdout = sys.__stdout__
app = QApplication(sys.argv)
window = QWidget()
window.setWindowTitle('XLSX to CSV Converter')
layout = QVBoxLayout()
output_area = QTextEdit()
output_area.setReadOnly(True)
layout.addWidget(output_area)
xlsx_to_csv_button = QPushButton('Convert XLSX to CSV')
xlsx_to_csv_button.clicked.connect(run_xlsx_to_csv_script)
layout.addWidget(xlsx_to_csv_button)
csv_rename_button = QPushButton('Rename CSV Files')
csv_rename_button.clicked.connect(run_csv_rename_script)
layout.addWidget(csv_rename_button)
mks2chainage_button = QPushButton('Convert MIKE txt to chainage.csv')
mks2chainage_button.clicked.connect(run_mks2chainage_script)
layout.addWidget(mks2chainage_button)
chg_split_button = QPushButton('Split chainage.csv to sections')
chg_split_button.clicked.connect(run_chg_split)
layout.addWidget(chg_split_button)
chg_insert_button = QPushButton('insert')
chg_insert_button.clicked.connect(run_chg_insert)
layout.addWidget(chg_insert_button)
clean_csv_button = QPushButton('clean csv')
clean_csv_button.clicked.connect(run_clean_csv)
layout.addWidget(clean_csv_button)
mkcc_button = QPushButton('mkcc')
mkcc_button.clicked.connect(run_mkcc)
layout.addWidget(mkcc_button)
get_virtual_end_button = QPushButton('get virtual end')
get_virtual_end_button.clicked.connect(run_get_virtual_end)
layout.addWidget(get_virtual_end_button)
virtual_start_button = QPushButton('virtual start')
virtual_start_button.clicked.connect(run_virtual_start)
layout.addWidget(virtual_start_button)
virtual_end_button = QPushButton('virtual end')
virtual_end_button.clicked.connect(run_virtual_end)
layout.addWidget(virtual_end_button)
virtual_end_update_button = QPushButton('virtual end update')
virtual_end_update_button.clicked.connect(run_virtual_end_update)
layout.addWidget(virtual_end_update_button)
combine_files_button = QPushButton('combine files')
combine_files_button.clicked.connect(run_combine_files)
layout.addWidget(combine_files_button)
window.setLayout(layout)
window.show()
sys.exit(app.exec_())