-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Testing #1523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Testing #1523
Conversation
Reviewer's GuideRefactor create_root to use a tkdnd.TkinterDnD root with dark mode and a main_frame layout, reparent all widgets under this container, integrate drag-and-drop support with new handlers, and remove unused NSFW filter code. Class diagram for updated UI root and drag-and-drop handlersclassDiagram
class TkinterDnD_Tk {
+minsize()
+title()
+configure(bg)
+protocol()
}
class CTkFrame {
+pack()
}
class CTkLabel {
+place()
+drop_target_register()
+dnd_bind()
+configure(image)
}
class CTkButton {
+place()
+drop_target_register()
+dnd_bind()
}
class handle_drop_source {
+__call__(event)
}
class handle_drop_target {
+__call__(event)
}
TkinterDnD_Tk <|-- CTkFrame
CTkFrame <|-- CTkLabel
CTkFrame <|-- CTkButton
CTkLabel <.. handle_drop_source : dnd_bind
CTkButton <.. handle_drop_source : dnd_bind
CTkLabel <.. handle_drop_target : dnd_bind
CTkButton <.. handle_drop_target : dnd_bind
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- create_root has become very long and mixes UI layout with event binding—consider splitting it into smaller helper functions for better readability and maintainability.
- There’s a lot of repeated drop_target_register and dnd_bind code—extracting a helper to register DnD handlers would reduce duplication.
- The create_root return annotation still mentions ctk.CTk but the function now returns tkdnd.TkinterDnD.Tk; please update the type hint to match.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- create_root has become very long and mixes UI layout with event binding—consider splitting it into smaller helper functions for better readability and maintainability.
- There’s a lot of repeated drop_target_register and dnd_bind code—extracting a helper to register DnD handlers would reduce duplication.
- The create_root return annotation still mentions ctk.CTk but the function now returns tkdnd.TkinterDnD.Tk; please update the type hint to match.
## Individual Comments
### Comment 1
<location> `modules/ui.py:1220-1234` </location>
<code_context>
+
+
+# New drop handler functions
+def handle_drop_source(event):
+ """Handle files dropped on source button or label"""
+ file_path = event.data
+ # On Windows, file paths may be enclosed in {}
+ if file_path.startswith("{") and file_path.endswith("}"):
+ file_path = file_path[1:-1]
+
+ if is_image(file_path):
+ modules.globals.source_path = file_path
+ global RECENT_DIRECTORY_SOURCE
+ RECENT_DIRECTORY_SOURCE = os.path.dirname(modules.globals.source_path)
+ image = render_image_preview(modules.globals.source_path, (200, 200))
+ source_label.configure(image=image)
+ else:
+ update_status("Please drop an image file for the source.")
+
+
</code_context>
<issue_to_address>
**suggestion (bug_risk):** handle_drop_source does not sanitize or validate file paths beyond extension.
Please add error handling for invalid, inaccessible, or corrupted files to ensure robust file access and image loading.
```suggestion
def handle_drop_source(event):
"""Handle files dropped on source button or label"""
file_path = event.data
# On Windows, file paths may be enclosed in {}
if file_path.startswith("{") and file_path.endswith("}"):
file_path = file_path[1:-1]
if not is_image(file_path):
update_status("Please drop an image file for the source.")
return
# Check if file exists and is accessible
if not os.path.isfile(file_path):
update_status("File does not exist or is not accessible.")
return
try:
# Try opening the file to check for accessibility/corruption
with open(file_path, "rb") as f:
data = f.read(10) # Try reading a small chunk
modules.globals.source_path = file_path
global RECENT_DIRECTORY_SOURCE
RECENT_DIRECTORY_SOURCE = os.path.dirname(modules.globals.source_path)
try:
image = render_image_preview(modules.globals.source_path, (200, 200))
if image is None:
update_status("Failed to load image preview. The file may be corrupted or unsupported.")
return
source_label.configure(image=image)
except Exception as e:
update_status(f"Error loading image preview: {str(e)}")
except Exception as e:
update_status(f"Error accessing file: {str(e)}")
```
</issue_to_address>
### Comment 2
<location> `modules/ui.py:1252-1254` </location>
<code_context>
+ image = render_image_preview(modules.globals.target_path, (200, 200))
+ target_label.configure(image=image)
+ elif is_video(file_path):
+ video_frame = render_video_preview(file_path, (200, 200))
+ target_label.configure(image=video_frame)
+ else:
</code_context>
<issue_to_address>
**suggestion:** No error handling for video preview rendering failures.
Add error handling to render_video_preview to catch exceptions and inform the user if preview generation fails.
```suggestion
elif is_video(file_path):
try:
video_frame = render_video_preview(file_path, (200, 200))
target_label.configure(image=video_frame)
except Exception as e:
import tkinter.messagebox as messagebox
messagebox.showerror("Preview Error", f"Failed to generate video preview:\n{e}")
target_label.configure(text="Video preview unavailable", image="")
```
</issue_to_address>
### Comment 3
<location> `modules/ui.py:1244` </location>
<code_context>
def handle_drop_target(event):
"""Handle files dropped on target button or label"""
file_path = event.data
# On Windows, file paths may be enclosed in {}
if file_path.startswith("{") and file_path.endswith("}"):
file_path = file_path[1:-1]
if is_image(file_path) or is_video(file_path):
modules.globals.target_path = file_path
global RECENT_DIRECTORY_TARGET
RECENT_DIRECTORY_TARGET = os.path.dirname(modules.globals.target_path)
if is_image(file_path):
image = render_image_preview(modules.globals.target_path, (200, 200))
target_label.configure(image=image)
elif is_video(file_path):
video_frame = render_video_preview(file_path, (200, 200))
target_label.configure(image=video_frame)
else:
update_status("Please drop an image or video file for the target.")
</code_context>
<issue_to_address>
**issue (code-quality):** We've found these issues:
- Split conditional into multiple branches ([`split-or-ifs`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/split-or-ifs/))
- Extract duplicate code into function ([`extract-duplicate-method`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/extract-duplicate-method/))
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Summary by Sourcery
Enable drag-and-drop file input in the UI by migrating to tkdnd.TkinterDnD.Tk, grouping widgets in a main frame, updating to dark mode, and adding drop handlers with preview support
New Features:
Enhancements: