adding requirements for file menu; improving brush color palette.
This commit is contained in:
63
src/GUI.py
63
src/GUI.py
@@ -1,5 +1,5 @@
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog, messagebox, colorchooser, simpledialog
|
||||
from tkinter import filedialog, colorchooser
|
||||
from PIL import ImageTk, ImageDraw, Image
|
||||
from ImageContainer import ImageContainer
|
||||
from ImageManipulation.ManipulationList import *
|
||||
@@ -7,6 +7,8 @@ from SelectionArea import SelectionArea
|
||||
from utils.area_selection import AreaSelectionHandler
|
||||
from utils.brush import BrushHandler
|
||||
from utils.text_entry import TextEntryHandler
|
||||
from utils.file_operations import FileOperationsHandler
|
||||
from utils.image_properties import ImagePropertiesHandler
|
||||
from functools import partial
|
||||
|
||||
|
||||
@@ -31,6 +33,12 @@ class GUI:
|
||||
# Text entry handler (will be initialized in initialise())
|
||||
_textEntryHandler = None
|
||||
|
||||
# File operations handler (will be initialized in initialise())
|
||||
_fileOperationsHandler = None
|
||||
|
||||
# Image properties handler (will be initialized in initialise())
|
||||
_imagePropertiesHandler = None
|
||||
|
||||
_canvasImageWidth = None # Store canvas image dimensions
|
||||
_canvasImageHeight = None
|
||||
|
||||
@@ -61,9 +69,15 @@ class GUI:
|
||||
root.config(menu=menu)
|
||||
file_menu = tk.Menu(menu, tearoff=0)
|
||||
menu.add_cascade(label="File", menu=file_menu)
|
||||
file_menu.add_command(label="Open Image", accelerator="Ctrl+O", command=lambda: self._openImage())
|
||||
file_menu.add_command(label="New", accelerator="Ctrl+N", command=lambda: self._newImage())
|
||||
file_menu.add_command(label="Open", accelerator="Ctrl+O", command=lambda: self._openImage())
|
||||
file_menu.add_command(label="Open Camera", accelerator="Ctrl+K", command=lambda: self._openCamera())
|
||||
file_menu.add_command(label="Save Image", accelerator="Ctrl+S", command=lambda: self._saveImage())
|
||||
file_menu.add_separator()
|
||||
file_menu.add_command(label="Save", accelerator="Ctrl+S", command=lambda: self._saveImage())
|
||||
file_menu.add_command(label="Save As", command=lambda: self._saveImageAs())
|
||||
file_menu.add_separator()
|
||||
file_menu.add_command(label="Properties", command=lambda: self._showProperties())
|
||||
file_menu.add_separator()
|
||||
file_menu.add_command(label="Exit", accelerator="Ctrl+Q", command=root.quit)
|
||||
|
||||
test_menu = tk.Menu(menu, tearoff=0)
|
||||
@@ -167,10 +181,26 @@ class GUI:
|
||||
|
||||
# Text entry handler from utils/text_entry.py
|
||||
self._textEntryHandler = TextEntryHandler(root)
|
||||
|
||||
# File operations handler from utils/file_operations.py
|
||||
def set_current_image(image):
|
||||
self._currentImage = image
|
||||
|
||||
self._fileOperationsHandler = FileOperationsHandler(
|
||||
get_current_image=get_current_image,
|
||||
set_current_image=set_current_image,
|
||||
render_image=self._renderCurrentImage
|
||||
)
|
||||
|
||||
# Image properties handler from utils/image_properties.py
|
||||
self._imagePropertiesHandler = ImagePropertiesHandler(
|
||||
get_current_image=get_current_image
|
||||
)
|
||||
|
||||
# Key bindings
|
||||
root.bind_all('<Control-z>', lambda event: self._undo())
|
||||
root.bind_all('<Control-y>', lambda event: self._redo())
|
||||
root.bind_all('<Control-n>', lambda event: self._newImage())
|
||||
root.bind_all('<Control-o>', lambda event: self._openImage())
|
||||
root.bind_all('<Control-s>', lambda event: self._saveImage())
|
||||
root.bind_all('<Control-k>', lambda event: self._openCamera())
|
||||
@@ -181,6 +211,11 @@ class GUI:
|
||||
|
||||
root.mainloop()
|
||||
|
||||
def _newImage(self) -> None:
|
||||
"""Create a new blank image with user-specified dimensions."""
|
||||
if self._fileOperationsHandler:
|
||||
self._fileOperationsHandler.new_image()
|
||||
|
||||
def _openImage(self) -> None:
|
||||
file_path = filedialog.askopenfilename(
|
||||
filetypes=[("Image files", "*.jpg *.jpeg *.png *.gif *.bmp")]
|
||||
@@ -240,14 +275,14 @@ class GUI:
|
||||
self._renderCurrentImage()
|
||||
|
||||
def _saveImage(self) -> None:
|
||||
if self._currentImage is None or self._currentImage.getImage() is None:
|
||||
return
|
||||
path = filedialog.asksaveasfilename(defaultextension=".png", filetypes=[
|
||||
("PNG", "*.png"), ("JPEG", "*.jpg;*.jpeg"), ("Bitmap", "*.bmp"), ("All Files", "*.*")
|
||||
])
|
||||
if not path:
|
||||
return
|
||||
self._currentImage.saveImage(path)
|
||||
"""Save the current image without asking for a name (uses current path)."""
|
||||
if self._fileOperationsHandler:
|
||||
self._fileOperationsHandler.save_image()
|
||||
|
||||
def _saveImageAs(self) -> None:
|
||||
"""Save the current image with a new name (prompts for filename)."""
|
||||
if self._fileOperationsHandler:
|
||||
self._fileOperationsHandler.save_image_as()
|
||||
|
||||
def _undo(self) -> None:
|
||||
if self._currentImage is None:
|
||||
@@ -336,13 +371,15 @@ class GUI:
|
||||
else:
|
||||
return {}
|
||||
|
||||
|
||||
|
||||
def _toggleBrushMode(self) -> None:
|
||||
"""Toggle brush mode on/off."""
|
||||
if self._brushHandler:
|
||||
self._brushHandler.toggle_brush_mode()
|
||||
|
||||
def _showProperties(self) -> None:
|
||||
"""Display image properties in a dialog."""
|
||||
if self._imagePropertiesHandler:
|
||||
self._imagePropertiesHandler.show_properties()
|
||||
|
||||
def _openCamera(self):
|
||||
camera = CameraWindow()
|
||||
|
||||
Reference in New Issue
Block a user