-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
6512 lines (5289 loc) · 303 KB
/
Copy pathgui.py
File metadata and controls
6512 lines (5289 loc) · 303 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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
昭通洪水可视化集成程序 - GUI模块
包含所有GUI界面相关的类和函数
"""
import sys
import os
# 添加当前目录到Python路径
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
print("Starting flood visualization application...")
print(f"Python version: {sys.version}")
print(f"Current directory: {os.getcwd()}")
print(f"Script directory: {os.path.dirname(os.path.abspath(__file__))}")
import tkinter as tk
from tkinter import ttk, filedialog, messagebox
import matplotlib
# 优化matplotlib后端
matplotlib.use('Agg') # 使用Agg后端,提高渲染性能
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
import numpy as np
import pandas as pd
from scipy.optimize import curve_fit
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from plotly.offline import plot_mpl
import threading
import queue
import time
# 图表绘制任务队列
plot_queue = queue.Queue()
# 图表绘制线程类
class PlotThread(threading.Thread):
"""异步图表绘制线程"""
def __init__(self, queue):
threading.Thread.__init__(self, daemon=True)
self.queue = queue
self.running = True
def run(self):
"""运行图表绘制线程"""
while self.running:
try:
# 从队列获取任务
task = self.queue.get(timeout=0.1)
if task is None:
break
# 执行图表绘制任务
func, args, kwargs = task
try:
func(*args, **kwargs)
except Exception as e:
print(f"图表绘制错误: {e}")
finally:
# 标记任务完成
self.queue.task_done()
except queue.Empty:
continue
except Exception as e:
print(f"图表绘制线程错误: {e}")
def stop(self):
"""停止图表绘制线程"""
self.running = False
# 发送终止信号
self.queue.put(None)
# 启动图表绘制线程
plot_thread = PlotThread(plot_queue)
plot_thread.start()
# 异步绘制装饰器
def async_plot(func):
"""异步绘制图表的装饰器"""
def wrapper(*args, **kwargs):
# 将绘制任务放入队列
plot_queue.put((func, args, kwargs))
return wrapper
# 导入配置文件
from config import (
FLOOD_TYPE_PARAMS,
DEFAULT_PARAMS,
CHART_CONFIG
)
# 导入计算模块
from calculations import (
get_eta_value,
calculate_pd0,
calculate_qm0,
calculate_w240,
calculate_qp,
calculate_w24p,
calculate_phi,
calculate_kp,
find_water_depth,
calculate_scour_coefficient,
calculate_bridge_average_velocity,
calculate_backwater_coefficient,
calculate_max_backwater_height,
calculate_backwater_curve_length,
calculate_bridge_cross_section_area,
calculate_soil_erosion_modulus,
calculate_unit_hydrograph_design_flood
)
# 导入工具模块
from utils import (
validate_numeric_input,
parse_float_list,
export_to_excel,
save_plot,
get_return_period_label,
format_number,
generate_flood_risk_map,
generate_flood_impact_map
)
# 导入业务逻辑模块
from business_logic import FloodCalculationService
# -------------------------- GUI界面类 --------------------------
class FloodVisualizationApp:
"""
昭通洪水可视化集成程序主界面类
"""
def __init__(self, root):
self.root = root
self.root.title("昭通洪水可视化集成程序")
# 调整窗口大小,使其更适合现代显示器
self.root.geometry("1400x900")
self.root.minsize(1280, 720)
# 添加窗口大小变化事件
self.root.bind("<Configure>", self.on_window_resize)
# 设置主题样式
self.style = ttk.Style()
self.style.theme_use('clam')
# 现代化洪水相关配色方案 - 更协调的蓝色系
# 主色调:蓝色系(代表水、河流),使用更专业的蓝色调
primary_color = '#0f766e' # 深青色(代表专业、可靠)
primary_hover = '#0d9488' # 亮青色(悬停效果)
secondary_color = '#3b82f6' # 蓝色(辅助色)
secondary_hover = '#60a5fa' # 亮蓝色(悬停效果)
accent_color = '#f59e0b' # 橙色(强调色,用于重要按钮)
accent_hover = '#fbbf24' # 亮橙色(悬停效果)
warning_color = '#f59e0b' # 警告黄色
warning_hover = '#fbbf24' # 警告黄色悬停
danger_color = '#ef4444' # 危险红色
danger_hover = '#f87171' # 危险红色悬停
background_color = '#f0f4f8' # 浅蓝色背景(更清爽)
card_color = '#ffffff' # 卡片白色
text_color = '#1e293b' # 深灰文字(提高可读性)
text_secondary = '#64748b' # 次要文字颜色
border_color = '#cbd5e1' # 边框颜色
focus_color = '#3b82f6' # 焦点颜色
# 配置颜色主题,确保使用支持中文的字体
self.style.configure('TLabel', font=('Microsoft YaHei', 10), foreground=text_color, background=background_color)
# 主按钮样式
self.style.configure('TButton', font=('Microsoft YaHei', 10, 'bold'), padding=8, foreground='white', background=primary_color, borderwidth=0, relief='flat', borderradius=4)
self.style.map('TButton',
background=[('active', primary_hover), ('disabled', '#cbd5e1'), ('hover', primary_hover)],
foreground=[('disabled', '#94a3b8')],
relief=[('pressed', 'flat'), ('!pressed', 'flat')],
padding=[('hover', 10)])
# 强调按钮样式
self.style.configure('Accent.TButton', font=('Microsoft YaHei', 10, 'bold'), padding=8, foreground='white', background=accent_color, borderwidth=0, relief='flat', borderradius=4)
self.style.map('Accent.TButton',
background=[('active', accent_hover), ('disabled', '#cbd5e1'), ('hover', accent_hover)],
foreground=[('disabled', '#94a3b8')],
relief=[('pressed', 'flat'), ('!pressed', 'flat')],
padding=[('hover', 10)])
# 次要按钮样式
self.style.configure('Secondary.TButton', font=('Microsoft YaHei', 10), padding=8, foreground=text_color, background='#e2e8f0', borderwidth=0, relief='flat', borderradius=4)
self.style.map('Secondary.TButton',
background=[('active', '#cbd5e1'), ('disabled', '#f1f5f9'), ('hover', '#cbd5e1')],
foreground=[('disabled', '#94a3b8')],
relief=[('pressed', 'flat'), ('!pressed', 'flat')],
padding=[('hover', 10)])
# 输入框样式
self.style.configure('TEntry', font=('Microsoft YaHei', 10), fieldbackground=card_color, bordercolor=border_color, relief='flat', borderwidth=1, padding=8)
self.style.map('TEntry',
fieldbackground=[('focus', card_color)],
bordercolor=[('focus', focus_color), ('!focus', border_color)],
relief=[('focus', 'solid'), ('!focus', 'flat')])
# 下拉框样式
self.style.configure('TCombobox', font=('Microsoft YaHei', 10), fieldbackground=card_color, bordercolor=border_color, relief='flat', borderwidth=1, padding=8)
self.style.map('TCombobox',
fieldbackground=[('focus', card_color)],
bordercolor=[('focus', focus_color), ('!focus', border_color)],
relief=[('focus', 'solid'), ('!focus', 'flat')])
# 复选框样式
self.style.configure('TCheckbutton', font=('Microsoft YaHei', 10), foreground=text_color, background=background_color, padding=5)
self.style.map('TCheckbutton',
foreground=[('active', primary_color), ('hover', primary_color)],
background=[('active', background_color), ('hover', background_color)])
# 单选按钮样式
self.style.configure('TRadiobutton', font=('Microsoft YaHei', 10), foreground=text_color, background=background_color, padding=5)
self.style.map('TRadiobutton',
foreground=[('active', primary_color), ('hover', primary_color)],
background=[('active', background_color), ('hover', background_color)])
self.style.configure('TLabelframe', font=('Microsoft YaHei', 11, 'bold'), padding=12, background=background_color, bordercolor=border_color, relief='flat', borderwidth=1)
self.style.configure('TLabelframe.Label', font=('Microsoft YaHei', 11, 'bold'), foreground=primary_color, background=background_color)
# 改进标签页样式
self.style.configure('TNotebook', background=background_color, bordercolor=border_color, relief='flat', padding=5)
self.style.configure('TNotebook.Tab', font=('Microsoft YaHei', 11, 'bold'), padding=[15, 8], background='#e2e8f0', foreground=text_color, relief='flat', borderwidth=0, borderradius=4)
self.style.map('TNotebook.Tab',
background=[('selected', primary_color), ('active', '#cbd5e1'), ('hover', '#cbd5e1')],
foreground=[('selected', 'white'), ('active', text_color), ('hover', text_color)],
relief=[('selected', 'flat'), ('!selected', 'flat')])
# 优化表格样式
self.style.configure('Treeview',
font=('Microsoft YaHei', 10),
background=card_color,
foreground=text_color,
fieldbackground=card_color,
relief='flat',
rowheight=28, # 增加行高,提高可读性
padding=8) # 增加内边距
self.style.configure('Treeview.Heading',
font=('Microsoft YaHei', 10, 'bold'),
background=primary_color,
foreground='white',
bordercolor=border_color,
relief='flat',
padding=12) # 增加表头内边距
self.style.map('Treeview',
background=[('selected', '#bfdbfe'), ('hover', '#f1f5f9')],
foreground=[('selected', text_color)],
fieldbackground=[('selected', '#bfdbfe'), ('hover', '#f1f5f9')])
self.style.configure('Horizontal.TScrollbar', background='#cbd5e1', troughcolor='#f1f5f9', relief='flat', borderwidth=1)
self.style.configure('Vertical.TScrollbar', background='#cbd5e1', troughcolor='#f1f5f9', relief='flat', borderwidth=1)
self.style.map('Horizontal.TScrollbar',
background=[('active', focus_color), ('hover', focus_color)],
troughcolor=[('hover', '#e2e8f0')])
self.style.map('Vertical.TScrollbar',
background=[('active', focus_color), ('hover', focus_color)],
troughcolor=[('hover', '#e2e8f0')])
# 设置Tkinter默认字体和样式
self.root.option_add('*Background', background_color)
self.root.option_add('*Foreground', text_color)
# 设置窗口背景色
self.root.configure(bg=background_color)
# 数据存储
self.flood_service = FloodCalculationService()
self.design_flood_data = {
'basic_params': {},
'intermediate_results': {},
'design_results': []
}
self.flood_level_data = {
'params': {},
'results': []
}
self.water_level_discharge_data = {
'discharges': [],
'water_levels': [],
'return_periods': [],
'bank_elevation': None,
'bridge_bottom_elevation': None,
'bridge_name': "桥梁"
}
# 历史洪水对比数据
self.compare_charts_data = []
self.backwater_analysis_data = {
'params': {},
'results': []
}
# 进度条相关变量
self.progress_window = None
self.progress_bar = None
self.progress_label = None
# 创建工具栏
self.create_toolbar()
# 绑定快捷键
self.bind_shortcuts()
# 创建主框架
self.main_frame = ttk.Frame(self.root, padding="10")
self.main_frame.pack(fill=tk.BOTH, expand=True)
# 配置主框架的网格布局,确保其能够正确响应窗口大小变化
self.main_frame.grid_rowconfigure(0, weight=1)
self.main_frame.grid_columnconfigure(0, weight=1)
# 添加洪水相关的视觉元素
self.add_flood_visual_elements()
# 创建功能选择标签页
self.create_tab_control()
# 创建状态栏
self.create_status_bar()
# 添加窗口关闭事件处理
self.root.protocol("WM_DELETE_WINDOW", self.on_closing)
def on_closing(self):
"""窗口关闭事件处理"""
try:
# 停止图表绘制线程
plot_thread.stop()
except Exception as e:
print(f"停止图表绘制线程错误: {e}")
# 关闭所有matplotlib图形
plt.close('all')
# 销毁主窗口
self.root.destroy()
# 退出程序
sys.exit(0)
def create_tab_control(self):
"""创建功能选择标签页"""
# 创建头部区域,包含标题和视觉元素
header_frame = ttk.Frame(self.main_frame, padding="20")
header_frame.pack(fill=tk.X, pady=5)
# 左侧:洪水相关视觉元素
visual_frame = ttk.Frame(header_frame)
visual_frame.pack(side=tk.LEFT, padx=10)
# 显示洪水相关的图标,使用文本图标避免依赖PIL库
ttk.Label(visual_frame, text="🌊", font=('Arial', 48)).pack()
# 右侧:应用标题和描述
title_frame = ttk.Frame(header_frame)
title_frame.pack(side=tk.LEFT, padx=20, fill=tk.BOTH, expand=True)
# 主标题 - 使用更现代的字体和颜色
main_title = ttk.Label(title_frame, text="昭通洪水可视化集成程序", font=('Microsoft YaHei', 20, 'bold'), foreground='#0f766e')
main_title.pack(anchor=tk.W)
# 副标题 - 使用次要文字颜色
sub_title = ttk.Label(title_frame, text="专业的洪水计算与可视化工具", font=('Microsoft YaHei', 12), foreground='#64748b')
sub_title.pack(anchor=tk.W, pady=5)
# 分隔线 - 更粗的分隔线,增强视觉层次感
separator = ttk.Separator(header_frame, orient=tk.HORIZONTAL)
separator.pack(fill=tk.X, pady=15)
# 创建标签控件
self.tab_control = ttk.Notebook(self.main_frame)
# 创建各个标签页
self.tab1 = ttk.Frame(self.tab_control)
self.tab2 = ttk.Frame(self.tab_control)
self.tab3 = ttk.Frame(self.tab_control)
self.tab4 = ttk.Frame(self.tab_control)
self.tab5 = ttk.Frame(self.tab_control)
self.tab6 = ttk.Frame(self.tab_control)
self.tab7 = ttk.Frame(self.tab_control) # 洪水风险图标签页
# 添加标签页到标签控件 - 使用图标增强视觉识别性
self.tab_control.add(self.tab1, text='📊 设计洪水计算')
self.tab_control.add(self.tab2, text='🌊 洪水位计算')
self.tab_control.add(self.tab3, text='📈 水位流量关系图')
self.tab_control.add(self.tab5, text='⚡ 壅水分析计算')
self.tab_control.add(self.tab6, text='📋 历史洪水对比')
self.tab_control.add(self.tab7, text='🗺️ 洪水风险图')
self.tab_control.add(self.tab4, text='📁 计算结果')
# 配置标签控件,使其能够正确响应窗口大小变化
self.tab_control.pack(fill=tk.BOTH, expand=True, pady=10)
# 添加标签页切换事件,用于更新状态栏信息
self.tab_control.bind("<<NotebookTabChanged>>", self.on_tab_changed)
# 初始化各个标签页内容
self.init_compare_charts_tab()
self.init_design_flood_tab()
self.init_flood_level_tab()
self.init_water_level_discharge_tab()
self.init_results_tab()
self.init_backwater_analysis_tab()
self.init_flood_risk_tab() # 初始化洪水风险图标签页
def init_design_flood_tab(self):
"""初始化设计洪水计算标签页"""
# 创建主布局框架
main_frame = ttk.Frame(self.tab1, padding="20")
main_frame.pack(fill=tk.BOTH, expand=True)
# 使用Grid布局替代Pack布局,提高响应式能力
main_frame.columnconfigure(0, minsize=380, weight=0) # 输入面板固定宽度,适当增加宽度
main_frame.columnconfigure(1, weight=1) # 结果面板自适应扩展
main_frame.rowconfigure(0, weight=1)
# 左侧输入面板容器(带滚动条)
input_container = ttk.Frame(main_frame, style='Card.TFrame')
input_container.grid(row=0, column=0, sticky="nsew", padx=10, pady=10)
# 创建Canvas和滚动条
canvas = tk.Canvas(input_container, width=380, bg=self.style.configure('.')['background'])
scrollbar = ttk.Scrollbar(input_container, orient="vertical", command=canvas.yview)
scrollable_frame = ttk.Frame(canvas)
# 配置Canvas
scrollable_frame.bind(
"<Configure>",
lambda e: canvas.configure(scrollregion=canvas.bbox("all"))
)
canvas.create_window((0, 0), window=scrollable_frame, anchor="nw", width=380)
canvas.configure(yscrollcommand=scrollbar.set)
# 布局Canvas和滚动条
canvas.pack(side="left", fill="both", expand=True)
scrollbar.pack(side="right", fill="y")
# 左侧输入面板 - 使用更现代的卡片式设计
input_frame = ttk.LabelFrame(scrollable_frame, text="输入参数", padding="20", style='Card.TLabelframe')
input_frame.pack(fill=tk.BOTH, expand=True, pady=10)
# 右侧结果面板容器
result_container = ttk.Frame(main_frame, style='Card.TFrame')
result_container.grid(row=0, column=1, sticky="nsew", padx=10, pady=10)
# 创建Canvas和滚动条
result_canvas = tk.Canvas(result_container, bg=self.style.configure('.')['background'])
result_scrollbar = ttk.Scrollbar(result_container, orient="vertical", command=result_canvas.yview)
result_scrollable_frame = ttk.Frame(result_canvas)
# 配置Canvas
result_scrollable_frame.bind(
"<Configure>",
lambda e: result_canvas.configure(scrollregion=result_canvas.bbox("all"))
)
result_canvas.create_window((0, 0), window=result_scrollable_frame, anchor="nw")
result_canvas.configure(yscrollcommand=result_scrollbar.set)
# 布局Canvas和滚动条
result_canvas.pack(side="left", fill="both", expand=True)
result_scrollbar.pack(side="right", fill="y")
# 右侧结果面板 - 使用卡片式设计
result_frame = ttk.LabelFrame(result_scrollable_frame, text="计算结果", padding="20", style='Card.TLabelframe')
result_frame.pack(fill=tk.BOTH, expand=True)
# 输入面板内容
self.create_design_flood_input(input_frame)
# 结果面板内容
self.create_design_flood_result(result_frame)
def create_design_flood_input(self, parent):
"""创建设计洪水计算输入表单"""
# 创建验证变量和函数
vcmd_float = (self.root.register(self.validate_float), '%P', '%W')
vcmd_float_positive = (self.root.register(self.validate_float_positive), '%P', '%W')
vcmd_float_non_negative = (self.root.register(self.validate_float_non_negative), '%P', '%W')
vcmd_list = (self.root.register(self.validate_float_list), '%P', '%W')
invcmd = (self.root.register(self.invalid_input), '%W')
# 计算方法选择卡片
method_card = ttk.LabelFrame(parent, text="计算方法选择", padding="15")
method_card.pack(fill=tk.X, expand=True, pady=10)
# 创建方法选择框架,使用并列的复选框
ttk.Label(method_card, text="请选择计算方法(可多选):", font=('Microsoft YaHei', 10, 'bold')).pack(anchor=tk.W, pady=(0, 10))
method_frame = ttk.Frame(method_card)
method_frame.pack(fill=tk.X, pady=5)
# 创建复选框变量
self.traditional_method_var = tk.BooleanVar(value=True)
self.unit_hydrograph_method_var = tk.BooleanVar(value=False)
ttk.Checkbutton(method_frame, text="📊 地区综合法", variable=self.traditional_method_var, command=self.toggle_method_frames).pack(anchor=tk.W, pady=5, side=tk.LEFT, padx=10)
ttk.Checkbutton(method_frame, text="📈 单位线法", variable=self.unit_hydrograph_method_var, command=self.toggle_method_frames).pack(anchor=tk.W, pady=5, side=tk.LEFT, padx=20)
# 传统方法输入卡片
self.traditional_method_frame = ttk.LabelFrame(parent, text="地区综合法参数", padding="15")
self.traditional_method_frame.pack(fill=tk.X, expand=True, pady=10)
self.create_traditional_method_input(self.traditional_method_frame, vcmd_float, vcmd_float_positive, vcmd_float_non_negative, vcmd_list, invcmd)
# 单位线法输入卡片
self.unit_hydrograph_method_frame = ttk.LabelFrame(parent, text="单位线法参数", padding="15")
self.unit_hydrograph_method_frame.pack(fill=tk.X, expand=True, pady=10)
self.create_unit_hydrograph_method_input(self.unit_hydrograph_method_frame, vcmd_float, vcmd_float_positive, vcmd_float_non_negative, vcmd_list, invcmd)
# 按钮框架 - 使用更现代的布局
button_frame = ttk.Frame(parent, padding=10)
button_frame.pack(fill=tk.X, pady=15)
# 按钮网格布局
button_frame.columnconfigure(0, weight=1)
button_frame.columnconfigure(1, weight=1)
# 保存参数按钮
ttk.Button(button_frame, text="💾 保存参数", command=lambda: self.save_params("design_flood"), style='Secondary.TButton').grid(row=0, column=0, padx=5, pady=5, sticky="ew")
# 加载参数按钮
ttk.Button(button_frame, text="📂 加载参数", command=lambda: self.load_params("design_flood"), style='Secondary.TButton').grid(row=0, column=1, padx=5, pady=5, sticky="ew")
# 计算按钮
ttk.Button(button_frame, text="🚀 开始计算", command=self.calculate_design_flood, style='Accent.TButton').grid(row=1, column=0, padx=5, pady=5, sticky="ew")
# 批量计算按钮
ttk.Button(button_frame, text="📋 批量计算", command=self.batch_calculate_design_flood, style='TButton').grid(row=1, column=1, padx=5, pady=5, sticky="ew")
# 重置按钮
ttk.Button(button_frame, text="🔄 重置", command=self.reset_design_flood_input, style='Secondary.TButton').grid(row=2, column=0, columnspan=2, padx=5, pady=5, sticky="ew")
def create_traditional_method_input(self, parent, vcmd_float, vcmd_float_positive, vcmd_float_non_negative, vcmd_list, invcmd):
"""创建传统方法输入表单"""
# 洪水类型选择
ttk.Label(parent, text="洪水类型:").pack(anchor=tk.W, pady=(10, 5))
self.flood_type_var = tk.StringVar()
flood_type_options = list(FLOOD_TYPE_PARAMS.keys())
flood_type_combobox = ttk.Combobox(parent, textvariable=self.flood_type_var, values=flood_type_options, width=30)
flood_type_combobox.pack(fill=tk.X, pady=2)
flood_type_combobox.current(1) # 默认选择泼机河型
# 流域面积
ttk.Label(parent, text="流域面积(km²):").pack(anchor=tk.W, pady=(15, 5))
self.area_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float_positive, invalidcommand=invcmd)
self.area_entry.pack(fill=tk.X, pady=2)
self.area_entry.insert(0, str(DEFAULT_PARAMS['design_flood']['area']))
# 24h点暴雨均值
ttk.Label(parent, text="24h点暴雨均值(mm):").pack(anchor=tk.W, pady=(15, 5))
self.pd24_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float_positive, invalidcommand=invcmd)
self.pd24_entry.pack(fill=tk.X, pady=2)
self.pd24_entry.insert(0, str(DEFAULT_PARAMS['design_flood']['pd24']))
# 点面折减系数η
ttk.Label(parent, text="点面折减系数η:").pack(anchor=tk.W, pady=(15, 5))
self.eta_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float_non_negative, invalidcommand=invcmd)
self.eta_entry.pack(fill=tk.X, pady=2)
self.eta_entry.insert(0, str(DEFAULT_PARAMS['design_flood']['eta']))
# 地理参数C
ttk.Label(parent, text="地理参数C:").pack(anchor=tk.W, pady=(15, 5))
self.c_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float_non_negative, invalidcommand=invcmd)
self.c_entry.pack(fill=tk.X, pady=2)
self.c_entry.insert(0, str(DEFAULT_PARAMS['design_flood']['c']))
# 指数n
ttk.Label(parent, text="指数n:").pack(anchor=tk.W, pady=(15, 5))
self.n_exp_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float_positive, invalidcommand=invcmd)
self.n_exp_entry.pack(fill=tk.X, pady=2)
self.n_exp_entry.insert(0, str(DEFAULT_PARAMS['design_flood']['n_exp']))
# 洪峰流量变差系数Cv_q
ttk.Label(parent, text="洪峰流量变差系数Cv_q:").pack(anchor=tk.W, pady=(15, 5))
self.cv_q_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float_non_negative, invalidcommand=invcmd)
self.cv_q_entry.pack(fill=tk.X, pady=2)
self.cv_q_entry.insert(0, str(DEFAULT_PARAMS['design_flood']['cv_q']))
# 24小时洪量变差系数Cv_w24
ttk.Label(parent, text="24小时洪量变差系数Cv_w24:").pack(anchor=tk.W, pady=(15, 5))
self.cv_w24_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float_non_negative, invalidcommand=invcmd)
self.cv_w24_entry.pack(fill=tk.X, pady=2)
self.cv_w24_entry.insert(0, str(DEFAULT_PARAMS['design_flood']['cv_w24']))
# 设计频率
ttk.Label(parent, text="设计频率(%,空格分隔,1%对应100年一遇):").pack(anchor=tk.W, pady=(15, 5))
self.frequencies_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_list, invalidcommand=invcmd)
self.frequencies_entry.pack(fill=tk.X, pady=2)
self.frequencies_entry.insert(0, DEFAULT_PARAMS['design_flood']['frequencies'])
def create_unit_hydrograph_method_input(self, parent, vcmd_float, vcmd_float_positive, vcmd_float_non_negative, vcmd_list, invcmd):
"""创建单位线法输入表单"""
# 流域面积
ttk.Label(parent, text="流域面积(km²):").pack(anchor=tk.W, pady=(10, 5))
self.unit_area_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float_positive, invalidcommand=invcmd)
self.unit_area_entry.pack(fill=tk.X, pady=2)
self.unit_area_entry.insert(0, str(DEFAULT_PARAMS['design_flood']['area']))
# 主河道长度
ttk.Label(parent, text="主河道长度(km):").pack(anchor=tk.W, pady=(15, 5))
self.unit_L_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float_positive, invalidcommand=invcmd)
self.unit_L_entry.pack(fill=tk.X, pady=2)
self.unit_L_entry.insert(0, "10.0")
# 主河道平均比降
ttk.Label(parent, text="主河道平均比降(‰):").pack(anchor=tk.W, pady=(15, 5))
self.unit_J_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float_positive, invalidcommand=invcmd)
self.unit_J_entry.pack(fill=tk.X, pady=2)
self.unit_J_entry.insert(0, "10.0")
# 24h暴雨均值
ttk.Label(parent, text="24h暴雨均值(mm):").pack(anchor=tk.W, pady=(15, 5))
self.unit_H24_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float_positive, invalidcommand=invcmd)
self.unit_H24_entry.pack(fill=tk.X, pady=2)
self.unit_H24_entry.insert(0, str(DEFAULT_PARAMS['design_flood']['pd24']))
# 暴雨变差系数
ttk.Label(parent, text="暴雨变差系数Cv:").pack(anchor=tk.W, pady=(15, 5))
self.unit_Cv_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float_non_negative, invalidcommand=invcmd)
self.unit_Cv_entry.pack(fill=tk.X, pady=2)
self.unit_Cv_entry.insert(0, "0.35")
# 暴雨偏态系数
ttk.Label(parent, text="暴雨偏态系数Cs:").pack(anchor=tk.W, pady=(15, 5))
self.unit_Cs_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float_non_negative, invalidcommand=invcmd)
self.unit_Cs_entry.pack(fill=tk.X, pady=2)
self.unit_Cs_entry.insert(0, "3.5")
# 设计频率
ttk.Label(parent, text="设计频率(%,空格分隔,1%对应100年一遇):").pack(anchor=tk.W, pady=(15, 5))
self.unit_frequencies_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_list, invalidcommand=invcmd)
self.unit_frequencies_entry.pack(fill=tk.X, pady=2)
self.unit_frequencies_entry.insert(0, DEFAULT_PARAMS['design_flood']['frequencies'])
def init_flood_level_tab(self):
"""初始化洪水位计算标签页"""
# 创建主布局框架
main_frame = ttk.Frame(self.tab2, padding="10")
main_frame.pack(fill=tk.BOTH, expand=True)
# 使用Grid布局替代Pack布局,提高响应式能力
main_frame.columnconfigure(0, minsize=300, weight=0) # 输入面板固定宽度
main_frame.columnconfigure(1, weight=1) # 结果面板自适应扩展
main_frame.rowconfigure(0, weight=1)
# 左侧输入面板容器(带滚动条)
input_container = ttk.Frame(main_frame)
input_container.grid(row=0, column=0, sticky="nsew", padx=5, pady=5)
# 创建Canvas和滚动条
canvas = tk.Canvas(input_container, width=300)
scrollbar = ttk.Scrollbar(input_container, orient="vertical", command=canvas.yview)
scrollable_frame = ttk.Frame(canvas)
# 配置Canvas
scrollable_frame.bind(
"<Configure>",
lambda e: canvas.configure(scrollregion=canvas.bbox("all"))
)
canvas.create_window((0, 0), window=scrollable_frame, anchor="nw", width=300)
canvas.configure(yscrollcommand=scrollbar.set)
# 布局Canvas和滚动条
canvas.pack(side="left", fill="both", expand=True)
scrollbar.pack(side="right", fill="y")
# 左侧输入面板
input_frame = ttk.LabelFrame(scrollable_frame, text="输入参数", padding="10")
input_frame.pack(fill=tk.BOTH, expand=True)
# 右侧结果面板容器
result_container = ttk.Frame(main_frame)
result_container.grid(row=0, column=1, sticky="nsew", padx=5, pady=5)
# 创建Canvas和滚动条
result_canvas = tk.Canvas(result_container)
result_scrollbar = ttk.Scrollbar(result_container, orient="vertical", command=result_canvas.yview)
result_scrollable_frame = ttk.Frame(result_canvas)
# 配置Canvas
result_scrollable_frame.bind(
"<Configure>",
lambda e: result_canvas.configure(scrollregion=result_canvas.bbox("all"))
)
result_canvas.create_window((0, 0), window=result_scrollable_frame, anchor="nw")
result_canvas.configure(yscrollcommand=result_scrollbar.set)
# 布局Canvas和滚动条
result_canvas.pack(side="left", fill="both", expand=True)
result_scrollbar.pack(side="right", fill="y")
# 右侧结果面板
result_frame = ttk.LabelFrame(result_scrollable_frame, text="计算结果", padding="10")
result_frame.pack(fill=tk.BOTH, expand=True)
# 输入面板内容
self.create_flood_level_input(input_frame)
# 结果面板内容
self.create_flood_level_result(result_frame)
def create_flood_level_input(self, parent):
"""创建洪水位计算输入表单"""
# 创建验证变量和函数
vcmd_float = (self.root.register(self.validate_float), '%P', '%W')
vcmd_float_positive = (self.root.register(self.validate_float_positive), '%P', '%W')
vcmd_float_non_negative = (self.root.register(self.validate_float_non_negative), '%P', '%W')
vcmd_list = (self.root.register(self.validate_float_list), '%P', '%W')
invcmd = (self.root.register(self.invalid_input), '%W')
# 断面类型选择
ttk.Label(parent, text="断面类型:").pack(anchor=tk.W, pady=(10, 5))
self.section_type_var = tk.StringVar(value="trapezoid")
section_frame = ttk.Frame(parent)
section_frame.pack(fill=tk.X, pady=2)
ttk.Radiobutton(section_frame, text="矩形断面", variable=self.section_type_var, value="rectangle", command=self.toggle_section_type).pack(anchor=tk.W, pady=2)
ttk.Radiobutton(section_frame, text="梯形断面", variable=self.section_type_var, value="trapezoid", command=self.toggle_section_type).pack(anchor=tk.W, pady=2)
# 河道宽度
ttk.Label(parent, text="河道宽度(m):").pack(anchor=tk.W, pady=(15, 5))
self.b_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float_positive, invalidcommand=invcmd)
self.b_entry.pack(fill=tk.X, pady=2)
self.b_entry.insert(0, str(DEFAULT_PARAMS['flood_level']['b']))
# 边坡系数(梯形断面)
self.m_frame = ttk.Frame(parent)
self.m_frame.pack(fill=tk.X, pady=2)
ttk.Label(self.m_frame, text="边坡系数m:").pack(anchor=tk.W, pady=(15, 5))
self.m_entry = ttk.Entry(self.m_frame, width=30, validate="key", validatecommand=vcmd_float_positive, invalidcommand=invcmd)
self.m_entry.pack(fill=tk.X, pady=2)
self.m_entry.insert(0, str(DEFAULT_PARAMS['flood_level']['m']))
# 河床高程
ttk.Label(parent, text="河床高程(m):").pack(anchor=tk.W, pady=(15, 5))
self.bed_elevation_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float, invalidcommand=invcmd)
self.bed_elevation_entry.pack(fill=tk.X, pady=2)
self.bed_elevation_entry.insert(0, str(DEFAULT_PARAMS['flood_level']['bed_elevation']))
# 河岸高程
ttk.Label(parent, text="河岸高程(m):").pack(anchor=tk.W, pady=(15, 5))
self.bank_elevation_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float, invalidcommand=invcmd)
self.bank_elevation_entry.pack(fill=tk.X, pady=2)
self.bank_elevation_entry.insert(0, str(DEFAULT_PARAMS['flood_level']['bank_elevation']))
# 曼宁糙率n
ttk.Label(parent, text="曼宁糙率n:").pack(anchor=tk.W, pady=(15, 5))
self.n_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float_positive, invalidcommand=invcmd)
self.n_entry.pack(fill=tk.X, pady=2)
self.n_entry.insert(0, str(DEFAULT_PARAMS['flood_level']['n']))
# 水面比降S
ttk.Label(parent, text="水面比降S:").pack(anchor=tk.W, pady=(15, 5))
self.s_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float_positive, invalidcommand=invcmd)
self.s_entry.pack(fill=tk.X, pady=2)
self.s_entry.insert(0, str(DEFAULT_PARAMS['flood_level']['s']))
# 设计流量
ttk.Label(parent, text="设计洪峰流量(m³/s,空格分隔):").pack(anchor=tk.W, pady=(15, 5))
self.q_list_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_list, invalidcommand=invcmd)
self.q_list_entry.pack(fill=tk.X, pady=2)
self.q_list_entry.insert(0, DEFAULT_PARAMS['flood_level']['q_list'])
# 导入设计洪水结果按钮
ttk.Button(parent, text="导入设计洪水计算结果", command=self.import_design_flood_to_flood_level, style='TButton').pack(fill=tk.X, pady=10)
# 按钮框架
button_frame = ttk.Frame(parent)
button_frame.pack(fill=tk.X, pady=10)
# 保存参数按钮
ttk.Button(button_frame, text="保存参数", command=lambda: self.save_params("flood_level"), style='TButton').pack(fill=tk.X, pady=5)
# 加载参数按钮
ttk.Button(button_frame, text="加载参数", command=lambda: self.load_params("flood_level"), style='TButton').pack(fill=tk.X, pady=5)
# 计算按钮
ttk.Button(button_frame, text="开始计算", command=self.calculate_flood_level, style='TButton').pack(fill=tk.X, pady=5)
# 重置按钮
ttk.Button(button_frame, text="重置", command=self.reset_flood_level_input, style='TButton').pack(fill=tk.X, pady=5)
def init_water_level_discharge_tab(self):
"""初始化水位流量关系图标签页"""
# 创建主布局框架
main_frame = ttk.Frame(self.tab3, padding="10")
main_frame.pack(fill=tk.BOTH, expand=True)
# 使用Grid布局替代Pack布局,提高响应式能力
main_frame.columnconfigure(0, minsize=300, weight=0) # 输入面板固定宽度
main_frame.columnconfigure(1, weight=1) # 绘图区域自适应扩展
main_frame.rowconfigure(0, weight=1)
# 左侧输入面板容器(带滚动条)
input_container = ttk.Frame(main_frame)
input_container.grid(row=0, column=0, sticky="nsew", padx=5, pady=5)
# 创建Canvas和滚动条
canvas = tk.Canvas(input_container, width=300)
scrollbar = ttk.Scrollbar(input_container, orient="vertical", command=canvas.yview)
scrollable_frame = ttk.Frame(canvas)
# 配置Canvas
scrollable_frame.bind(
"<Configure>",
lambda e: canvas.configure(scrollregion=canvas.bbox("all"))
)
canvas.create_window((0, 0), window=scrollable_frame, anchor="nw", width=300)
canvas.configure(yscrollcommand=scrollbar.set)
# 布局Canvas和滚动条
canvas.pack(side="left", fill="both", expand=True)
scrollbar.pack(side="right", fill="y")
# 左侧输入面板
input_frame = ttk.LabelFrame(scrollable_frame, text="绘图参数", padding="10")
input_frame.pack(fill=tk.BOTH, expand=True)
# 右侧绘图区域
plot_frame = ttk.LabelFrame(main_frame, text="水位流量关系图", padding="10")
plot_frame.grid(row=0, column=1, sticky="nsew", padx=5, pady=5)
# 输入面板内容
self.create_water_level_discharge_input(input_frame)
# 为绘图区域添加垂直滚动条
plot_canvas = tk.Canvas(plot_frame)
plot_scrollbar = ttk.Scrollbar(plot_frame, orient="vertical", command=plot_canvas.yview)
plot_scrollable_frame = ttk.Frame(plot_canvas)
# 配置Canvas
plot_scrollable_frame.bind(
"<Configure>",
lambda e: plot_canvas.configure(scrollregion=plot_canvas.bbox("all"))
)
plot_canvas.create_window((0, 0), window=plot_scrollable_frame, anchor="nw")
plot_canvas.configure(yscrollcommand=plot_scrollbar.set)
# 布局Canvas和滚动条
plot_canvas.pack(side="left", fill="both", expand=True)
plot_scrollbar.pack(side="right", fill="y")
# 绘图区域
self.create_water_level_discharge_plot(plot_scrollable_frame)
def create_water_level_discharge_input(self, parent):
"""创建水位流量关系图输入表单"""
# 创建验证变量和函数
vcmd_float = (self.root.register(self.validate_float), '%P', '%W')
vcmd_float_positive = (self.root.register(self.validate_float_positive), '%P', '%W')
vcmd_float_non_negative = (self.root.register(self.validate_float_non_negative), '%P', '%W')
vcmd_list = (self.root.register(self.validate_float_list), '%P', '%W')
invcmd = (self.root.register(self.invalid_input), '%W')
# 桥梁名称
ttk.Label(parent, text="桥梁名称:").pack(anchor=tk.W, pady=(10, 5))
self.bridge_name_entry = ttk.Entry(parent, width=30)
self.bridge_name_entry.pack(fill=tk.X, pady=2)
self.bridge_name_entry.insert(0, DEFAULT_PARAMS['water_level_discharge']['bridge_name'])
# 河岸高程
ttk.Label(parent, text="河岸高程(m):").pack(anchor=tk.W, pady=(15, 5))
self.wld_bank_elevation_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float, invalidcommand=invcmd)
self.wld_bank_elevation_entry.pack(fill=tk.X, pady=2)
self.wld_bank_elevation_entry.insert(0, str(DEFAULT_PARAMS['water_level_discharge']['bank_elevation']))
# 桥底设计高程
ttk.Label(parent, text="桥底设计高程(m):").pack(anchor=tk.W, pady=(15, 5))
self.wld_bridge_bottom_elevation_entry = ttk.Entry(parent, width=30, validate="key", validatecommand=vcmd_float, invalidcommand=invcmd)
self.wld_bridge_bottom_elevation_entry.pack(fill=tk.X, pady=2)
self.wld_bridge_bottom_elevation_entry.insert(0, str(DEFAULT_PARAMS['water_level_discharge']['bridge_bottom_elevation']))
# 数据来源选择
ttk.Label(parent, text="数据来源:").pack(anchor=tk.W, pady=(15, 5))
self.data_source_var = tk.StringVar(value="manual")
source_frame = ttk.Frame(parent)
source_frame.pack(fill=tk.X, pady=2)
ttk.Radiobutton(source_frame, text="使用计算结果数据", variable=self.data_source_var, value="calculated").pack(anchor=tk.W, pady=2)
ttk.Radiobutton(source_frame, text="手动输入数据", variable=self.data_source_var, value="manual").pack(anchor=tk.W, pady=2)
# 手动输入数据区域
self.manual_data_frame = ttk.Frame(parent)
self.manual_data_frame.pack(fill=tk.X, pady=2)
ttk.Label(self.manual_data_frame, text="洪峰流量(m³/s,空格分隔):").pack(anchor=tk.W, pady=(15, 5))
self.wld_discharges_entry = ttk.Entry(self.manual_data_frame, width=30, validate="key", validatecommand=vcmd_list, invalidcommand=invcmd)
self.wld_discharges_entry.pack(fill=tk.X, pady=2)
self.wld_discharges_entry.insert(0, DEFAULT_PARAMS['water_level_discharge']['discharges'])
ttk.Label(self.manual_data_frame, text="水位高程(m,空格分隔):").pack(anchor=tk.W, pady=(15, 5))
self.wld_water_levels_entry = ttk.Entry(self.manual_data_frame, width=30, validate="key", validatecommand=vcmd_list, invalidcommand=invcmd)
self.wld_water_levels_entry.pack(fill=tk.X, pady=2)
self.wld_water_levels_entry.insert(0, DEFAULT_PARAMS['water_level_discharge']['water_levels'])
ttk.Label(self.manual_data_frame, text="重现期(年,空格分隔):").pack(anchor=tk.W, pady=(15, 5))
self.wld_return_periods_entry = ttk.Entry(self.manual_data_frame, width=30, validate="key", validatecommand=vcmd_list, invalidcommand=invcmd)
self.wld_return_periods_entry.pack(fill=tk.X, pady=2)
self.wld_return_periods_entry.insert(0, DEFAULT_PARAMS['water_level_discharge']['return_periods'])
# 导入洪水位计算结果按钮
ttk.Button(parent, text="导入洪水位计算结果", command=self.import_flood_level_to_wld, style='TButton').pack(fill=tk.X, pady=10)
# 按钮框架
button_frame = ttk.Frame(parent)
button_frame.pack(fill=tk.X, pady=10)
# 保存参数按钮
ttk.Button(button_frame, text="保存参数", command=lambda: self.save_params("water_level_discharge"), style='TButton').pack(fill=tk.X, pady=5)
# 加载参数按钮
ttk.Button(button_frame, text="加载参数", command=lambda: self.load_params("water_level_discharge"), style='TButton').pack(fill=tk.X, pady=5)
# 绘图按钮
ttk.Button(button_frame, text="绘制图表", command=self.plot_water_level_discharge, style='TButton').pack(fill=tk.X, pady=5)
# 重置按钮
ttk.Button(button_frame, text="重置", command=self.reset_water_level_discharge_input, style='TButton').pack(fill=tk.X, pady=5)
# 导出按钮
ttk.Button(parent, text="导出图表", command=self.export_water_level_discharge_plot, style='TButton').pack(fill=tk.X, pady=5)
def init_results_tab(self):
"""初始化计算结果标签页"""
# 创建主布局框架
main_frame = ttk.Frame(self.tab4, padding="10")
main_frame.pack(fill=tk.BOTH, expand=True)
# 结果选择框架
result_select_frame = ttk.Frame(main_frame)
result_select_frame.pack(fill=tk.X, pady=5)
ttk.Label(result_select_frame, text="选择结果类型:").pack(side=tk.LEFT, padx=5)
self.result_type_var = tk.StringVar(value="design_flood")
result_types = [
("设计洪水计算结果", "design_flood"),
("洪水位计算结果", "flood_level"),
("壅水分析计算结果", "backwater_analysis")
]
for text, value in result_types:
ttk.Radiobutton(result_select_frame, text=text, variable=self.result_type_var, value=value, command=self.update_results_display).pack(side=tk.LEFT, padx=10)
# 导出按钮框架
export_frame = ttk.Frame(result_select_frame)
export_frame.pack(side=tk.RIGHT, padx=5)
ttk.Button(export_frame, text="导出为Excel", command=self.export_results, style='TButton').pack(side=tk.LEFT, padx=5)
ttk.Button(export_frame, text="导出为Word", command=self.export_results_as_word, style='TButton').pack(side=tk.LEFT, padx=5)
# 结果表格框架
result_table_frame = ttk.LabelFrame(main_frame, text="计算结果表格", padding="10")
result_table_frame.pack(fill=tk.BOTH, expand=True, pady=5)
# 创建结果表格
self.create_results_table(result_table_frame)
# 结果叙述框架
result_narrative_frame = ttk.LabelFrame(main_frame, text="计算结果详细叙述", padding="10")
result_narrative_frame.pack(fill=tk.BOTH, expand=True, pady=5)
# 创建滚动文本框用于显示详细叙述
narrative_scrollbar = ttk.Scrollbar(result_narrative_frame)
self.results_narrative = tk.Text(result_narrative_frame, wrap=tk.WORD, yscrollcommand=narrative_scrollbar.set, font=('SimHei', 10))
narrative_scrollbar.config(command=self.results_narrative.yview)
# 布局文本框和滚动条
self.results_narrative.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
narrative_scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
# 初始显示提示信息
self.results_narrative.insert(tk.END, "请选择结果类型查看详细计算结果叙述...")