Skip to content

Commit 5bee11d

Browse files
committed
refactor app to use display msg function
1 parent 6ed4b61 commit 5bee11d

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

visual_comparison/visual_comparison_app.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ def __init__(self, root=None, preview_folder=None, config_path="visual_compariso
120120

121121
self.bind_methods_to_keys()
122122

123+
def display_msg_popup(self, message):
124+
msg_popup = widgets.MessageBoxPopup(message, self.configurations["Display"]["ctk_corner_radius"])
125+
msg_popup.wait()
126+
123127
def load_content(self):
124128
popup = widgets.RootSelectionPopup(self.root, self.preview_folder, self.configurations["Display"]["ctk_corner_radius"])
125129
cancelled, ret_vals = popup.get_input()
@@ -130,12 +134,10 @@ def load_content(self):
130134
content_handler = managers.ContentManager(root=root_folder, preview_folder=preview_folder)
131135

132136
if len(content_handler.methods) <= 1:
133-
msg_popup = widgets.MessageBoxPopup("Root folder must contain more than 1 sub folder", self.configurations["Display"]["ctk_corner_radius"])
134-
msg_popup.wait()
137+
self.display_msg_popup("Root folder must contain more than 1 sub folder")
135138
return False
136139
if len(content_handler.files) == 0:
137-
msg_popup = widgets.MessageBoxPopup("There are no common files in all sub folders", self.configurations["Display"]["ctk_corner_radius"])
138-
msg_popup.wait()
140+
self.display_msg_popup("There are no common files in all sub folders")
139141
return False
140142

141143
self.content_handler = content_handler
@@ -256,8 +258,7 @@ def on_select_methods(self):
256258
return
257259

258260
if len(new_methods) < 2:
259-
msg_popup = widgets.MessageBoxPopup("Please select more than 2 methods", self.configurations["Display"]["ctk_corner_radius"])
260-
msg_popup.wait()
261+
self.display_msg_popup("Please select more than 2 methods")
261262
return
262263
self.content_handler.current_methods = new_methods
263264
self.cb_widget.set_mode(VCModes.Compare)
@@ -286,8 +287,7 @@ def on_filter_files(self):
286287
# Filter action
287288
rows = data
288289
if len(rows) == 0:
289-
msg_popup = widgets.MessageBoxPopup("No items selected. Ignoring selection", self.configurations["Display"]["ctk_corner_radius"])
290-
msg_popup.wait()
290+
self.display_msg_popup("No items selected. Ignoring selection")
291291
return
292292

293293
# Setting app states and files
@@ -369,9 +369,7 @@ def on_specify_index(self, index=None):
369369
# Need to verify when on_specify_index is called with not None index
370370
ret = self.content_handler.on_specify_index(value=index)
371371
if not ret:
372-
message = f"Index {index} not in range [0, {upper_bound}]"
373-
msg_popup = widgets.MessageBoxPopup(message, self.configurations["Display"]["ctk_corner_radius"])
374-
msg_popup.wait()
372+
self.display_msg_popup(f"Index {index} not in range [0, {upper_bound}]")
375373
return
376374

377375
self.preview_widget.highlight_selected(self.content_handler.current_index)
@@ -420,8 +418,7 @@ def on_export(self, event: Optional[tkinter.Event] = None) -> None:
420418
:return: None
421419
"""
422420
if not hasattr(self, "display_image"):
423-
msg_popup = widgets.MessageBoxPopup("self.display_image does not exist", self.configurations["Display"]["ctk_corner_radius"])
424-
msg_popup.wait()
421+
self.display_msg_popup("self.display_image does not exist")
425422
return
426423

427424
# When stop is clicked. Export Button changes to a stop button when writing to video.
@@ -463,8 +460,7 @@ def on_export(self, event: Optional[tkinter.Event] = None) -> None:
463460
export_path = video_export_options["export_path"]
464461
if export_type == "Fixed (Concatenated)":
465462
if not self.content_handler.has_video():
466-
msg_popup = widgets.MessageBoxPopup("Current file is not a video, can't export in Concatenate mode", self.configurations["Display"]["ctk_corner_radius"])
467-
msg_popup.wait()
463+
self.display_msg_popup("Current file is not a video, can't export in Concatenate mode")
468464
self.focus_get()
469465
return
470466
Thread(target=lambda: self.export_fixed_video(export_path)).start()
@@ -485,15 +481,13 @@ def export_image(self):
485481
try:
486482
cv2.imwrite(dialog_result.name, self.display_image)
487483
except cv2.error as e:
488-
msg_popup = widgets.MessageBoxPopup(e, self.configurations["Display"]["ctk_corner_radius"])
489-
msg_popup.wait()
484+
self.display_msg_popup(e)
490485

491486
def export_fixed_video(self, file_path):
492487
# Check video extension
493488
file_extension = os.path.splitext(file_path)[-1]
494489
if file_extension != ".mp4":
495-
msg_popup = widgets.MessageBoxPopup(f"Unsupported file extension: {file_extension}", self.configurations["Display"]["ctk_corner_radius"])
496-
msg_popup.wait()
490+
self.display_msg_popup(f"Unsupported file extension: {file_extension}")
497491
return
498492

499493
# Get video information
@@ -669,8 +663,7 @@ def handle_custom_video_writing(self, img_to_write):
669663
ret = self.video_writer.write_image(img_to_write)
670664
if not ret:
671665
self.reset_video_writer()
672-
msg_popup = widgets.MessageBoxPopup("Video writing stopped because image size has changed", self.configurations["Display"]["ctk_corner_radius"])
673-
msg_popup.wait()
666+
self.display_msg_popup("Video writing stopped because image size has changed")
674667

675668
# Inform user that it is still recording
676669
utils.image_utils.put_text(img_to_write, "Recording", utils.image_utils.TextPosition.TOP_CENTER, fg_color=(0, 0, 255))

0 commit comments

Comments
 (0)