-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
225 lines (180 loc) · 5.29 KB
/
gui.py
File metadata and controls
225 lines (180 loc) · 5.29 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
import tkinter as tk
from pathlib import Path
from tkinter import filedialog, ttk, messagebox
def askSingleVideoOrDirectory() -> str:
"""
Opens a modal dialog asking:
"Measure CRT on a single video or a directory?"
Returns
-------
str
Either "single video" or "directory".
"""
result: str | None = None
root = tk.Tk()
root.withdraw() # hide main window
dialog = tk.Toplevel(root)
dialog.title("Select input type")
dialog.resizable(False, False)
dialog.attributes("-topmost", True)
dialog.grab_set() # modal
ttk.Label(
dialog,
text="Measure CRT on a single video or a directory?",
padding=(20, 15),
).pack()
btn_frame = ttk.Frame(dialog, padding=(10, 10))
btn_frame.pack()
def choose(value: str) -> None:
nonlocal result
result = value
dialog.destroy()
ttk.Button(
btn_frame,
text="Single video",
command=lambda: choose("single video"),
width=18,
).grid(row=0, column=0, padx=5)
ttk.Button(
btn_frame,
text="Directory",
command=lambda: choose("directory"),
width=18,
).grid(row=0, column=1, padx=5)
dialog.protocol("WM_DELETE_WINDOW", lambda: None) # disable close
root.wait_window(dialog)
root.destroy()
if result is None:
raise RuntimeError("Dialog closed without a selection.")
return result
def askNextVideo(videoName: str) -> str:
# {{{
"""
Open a dialog asking whether to continue to the next video. By chatGPT
Parameters
----------
videoName : str
Name of the next video.
Returns
-------
str
One of: "yes", "skip", "select", "abort"
"""
result: str | None = None
def set_result(value: str) -> None:
nonlocal result
result = value
root.destroy()
root = tk.Tk()
root.title("Continue?")
root.resizable(False, False)
root.attributes("-topmost", True)
frame = ttk.Frame(root, padding=12)
frame.pack(fill="both", expand=True)
label = ttk.Label(
frame,
text=f"Continue to next video:\n{videoName}?",
justify="center",
)
label.pack(pady=(0, 12))
btn_frame = ttk.Frame(frame)
btn_frame.pack()
ttk.Button(btn_frame, text="Yes", command=lambda: set_result("yes")).grid(
row=0, column=0, padx=5
)
ttk.Button(
btn_frame, text="Skip", command=lambda: set_result("skip")
).grid(row=0, column=1, padx=5)
ttk.Button(
btn_frame, text="Select Video", command=lambda: set_result("select")
).grid(row=0, column=2, padx=5)
ttk.Button(
btn_frame, text="Abort", command=lambda: set_result("abort")
).grid(row=0, column=3, padx=5)
root.protocol("WM_DELETE_WINDOW", lambda: set_result("abort"))
root.mainloop()
assert result is not None
return result
# }}}
def selectFile() -> Path:
# {{{
root = tk.Tk()
root.withdraw() # hide main window
root.attributes("-topmost", True)
selection = filedialog.askopenfilename()
if not selection:
raise RuntimeError("No video selected. Aborting...")
filePath = Path(selection)
root.destroy()
return filePath
# }}}
def selectDirectory() -> Path:
# {{{
root = tk.Tk()
root.withdraw() # hide main window
root.attributes("-topmost", True)
selection = filedialog.askdirectory()
if not selection:
raise RuntimeError("No directory selected. Aborting...")
dirPath = Path(selection)
root.destroy()
return dirPath
# }}}
def showVideoSuccessMessage() -> None:
# {{{
root = tk.Tk()
root.withdraw() # hide main window
root.attributes("-topmost", True)
messagebox.showinfo(
title="Success",
message=(
"CRT measured successfully.\n\n"
"Check the console and/or the plots directory and the spreadsheet "
"for the results."
)
)
root.destroy()
# }}}
def showDirSuccessMessage(failedMeasurements) -> None:
# {{{
root = tk.Tk()
root.withdraw() # hide main window
root.attributes("-topmost", True)
if failedMeasurements > 0:
messagebox.showinfo(
title="Success",
message=(
"Finished processing directory.\n\n"
f"Measurement failed on {failedMeasurements} videos.\n"
"Check the console and/or logs, plots directory, "
"and spreadsheets for results"
),
)
else:
messagebox.showinfo(
title="Success",
message=(
"Finished processing directory.\n\n"
"Measurement successfull on all videos.\n"
"Check the console and/or logs, plots directory, "
"and spreadsheets for results"
),
)
root.destroy()
# }}}
def showVideoErrorMessage() -> None:
# {{{
root = tk.Tk()
root.withdraw() # hide main window
root.attributes("-topmost", True)
messagebox.showinfo(
title="Error",
message=(
"CRT measured failed.\n\n"
"Check the console for details.\n"
"Try changing the ROi, exclusionMethod, and/or exclusionCriteria "
"and try again."
)
)
root.destroy()
# }}}