adding requirements for file menu; improving brush color palette.
This commit is contained in:
64
src/utils/image_properties.py
Normal file
64
src/utils/image_properties.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
from typing import Callable
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add parent directory to path for imports (since we're in utils/ subdirectory)
|
||||
_parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
if _parent_dir not in sys.path:
|
||||
sys.path.insert(0, _parent_dir)
|
||||
|
||||
|
||||
class ImagePropertiesHandler:
|
||||
"""Handler for displaying image properties.
|
||||
|
||||
This class encapsulates the functionality to display image information
|
||||
such as dimensions, mode, format, file size, and path.
|
||||
"""
|
||||
|
||||
def __init__(self, get_current_image: Callable):
|
||||
"""Initialize the image properties handler.
|
||||
|
||||
Args:
|
||||
get_current_image: Callable that returns the current ImageContainer
|
||||
"""
|
||||
self._get_current_image = get_current_image
|
||||
|
||||
def show_properties(self) -> None:
|
||||
"""Display image properties in a dialog."""
|
||||
current_image = self._get_current_image()
|
||||
if current_image is None or current_image.getImage() is None:
|
||||
messagebox.showwarning("No Image", "No image loaded.")
|
||||
return
|
||||
|
||||
image = current_image.getImage()
|
||||
width, height = current_image.getDimensions()
|
||||
path = current_image.getPath()
|
||||
mode = image.mode if image else "N/A"
|
||||
format_name = image.format if image else "N/A"
|
||||
|
||||
# Get file size if path exists
|
||||
file_size = "N/A"
|
||||
if path:
|
||||
try:
|
||||
size_bytes = os.path.getsize(path)
|
||||
if size_bytes < 1024:
|
||||
file_size = f"{size_bytes} bytes"
|
||||
elif size_bytes < 1024 * 1024:
|
||||
file_size = f"{size_bytes / 1024:.2f} KB"
|
||||
else:
|
||||
file_size = f"{size_bytes / (1024 * 1024):.2f} MB"
|
||||
except:
|
||||
file_size = "Unknown"
|
||||
|
||||
# Create properties message
|
||||
properties_text = f"Image Properties\n\n"
|
||||
properties_text += f"Dimensions: {width} x {height} pixels\n"
|
||||
properties_text += f"Mode: {mode}\n"
|
||||
properties_text += f"Format: {format_name}\n"
|
||||
properties_text += f"File Size: {file_size}\n"
|
||||
properties_text += f"Path: {path if path else 'Unsaved'}"
|
||||
|
||||
messagebox.showinfo("Image Properties", properties_text)
|
||||
|
||||
Reference in New Issue
Block a user