-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
186 lines (147 loc) · 5.87 KB
/
Copy pathmain.py
File metadata and controls
186 lines (147 loc) · 5.87 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
import threading
import traceback
import matplotlib
from tkinter import ttk, messagebox
from core import BarcodeConfig, InputConfig, PreviewConfig, AggregationConfig
from gui import (
create_barcode_frame,
create_binarization_frame,
create_execution_frame,
create_flow_frame,
create_intensity_frame,
setup_log_window,
setup_main_window,
setup_scrollable_container,
)
from gui.config import (
BarcodeConfigGUI,
InputConfigGUI,
PreviewConfigGUI,
AggregationConfigGUI,
)
matplotlib.use("Agg")
def create_tabs(
parent,
config: BarcodeConfigGUI,
input_config: InputConfigGUI,
preview_config: PreviewConfigGUI,
aggregation_config: AggregationConfigGUI,
):
"""Create all tabs using our extracted components"""
notebook = ttk.Notebook(parent, takefocus=0)
notebook.pack(fill="both", expand=True)
# Create all tabs
execution_frame = create_execution_frame(notebook, config, input_config)
binarization_frame = create_binarization_frame(
notebook, config, preview_config, input_config
)
flow_frame = create_flow_frame(notebook, config)
intensity_frame = create_intensity_frame(notebook, config)
barcode_frame = create_barcode_frame(notebook, config, aggregation_config)
# Add tabs to notebook
notebook.add(execution_frame, text="Execution Settings")
notebook.add(binarization_frame, text="Binarization Settings")
notebook.add(flow_frame, text="Optical Flow Settings")
notebook.add(intensity_frame, text="Intensity Distribution Settings")
notebook.add(barcode_frame, text="Barcode Generator + CSV Aggregator")
return notebook
def create_processing_worker(
config: BarcodeConfig,
input_config: InputConfig,
aggregation_config: AggregationConfig,
):
"""Create the worker function for processing in background thread"""
if input_config.configuration_file:
try:
config = BarcodeConfig.load_from_yaml(input_config.configuration_file)
except Exception as e:
messagebox.showerror("Error reading config file", str(e))
return
def worker():
try:
mode = input_config.mode
if mode == "agg":
from utils.writer import generate_aggregate_csv
# Handle CSV aggregation
combined_location = aggregation_config.output_location
generate_agg_barcode = aggregation_config.generate_barcode
sort_param = aggregation_config.sort_parameter
csv_paths = aggregation_config.csv_paths_list
if not csv_paths:
messagebox.showerror(
"Error", "No CSV files selected for aggregation."
)
return
if not combined_location:
messagebox.showerror("Error", "No aggregate location specified.")
return
sort_choice = None if sort_param == "Default" else sort_param
generate_aggregate_csv(
csv_paths, combined_location, generate_agg_barcode, sort_choice
)
else:
from core.pipeline import run_analysis
# Handle file/directory processing
file_path = input_config.file_path
dir_path = input_config.dir_path
if not (dir_path or file_path):
messagebox.showerror(
"Error", "No file or directory has been selected."
)
return
channels = config.channels.parse_all_channels
channel_selection = config.channels.selected_channel
if not (channels or (channel_selection is not None)):
messagebox.showerror("Error", "No channel has been specified.")
return
dir_name = dir_path if dir_path else file_path
run_analysis(dir_name, config)
except Exception as e:
print(f"Error during processing: {e}")
print(traceback.format_exc())
messagebox.showerror("Error during processing", str(e))
finally:
messagebox.showinfo(
"Processing Complete", "Analysis has finished successfully."
)
return worker
def main():
"""Main application entry point"""
# Setup main window
root = setup_main_window()
scrollable_frame, canvas = setup_scrollable_container(root)
# Create configurations
gui_config = BarcodeConfigGUI()
gui_input_config = InputConfigGUI()
gui_preview_config = PreviewConfigGUI()
gui_aggregation_config = AggregationConfigGUI()
# Create tabs
create_tabs(
scrollable_frame,
gui_config,
gui_input_config,
gui_preview_config,
gui_aggregation_config,
)
# Run button
def on_run():
setup_log_window(root)
# Convert GUI configs to pure data configs
config = gui_config.config
input_config = gui_input_config.config
aggregation_config = gui_aggregation_config.config
worker = create_processing_worker(config, input_config, aggregation_config)
threading.Thread(target=worker, daemon=True).start()
run_button = ttk.Button(root, text="Run", command=on_run)
run_button.grid(row=1, column=0, pady=10, sticky="n")
# Configure canvas sizing
root.update_idletasks()
bbox = canvas.bbox("all")
if bbox:
content_width = bbox[2] - bbox[0]
content_height = bbox[3] - bbox[1]
canvas.config(width=content_width, height=content_height)
root.update_idletasks()
root.mainloop()
if __name__ == "__main__":
main()