StuartJAtkinson / EXIF-SpaceTime

An application focused on editing geolocation & time metadata
0 stars 0 forks source link

Impliment a GUI interface #3

Closed StuartJAtkinson closed 2 days ago

StuartJAtkinson commented 4 days ago

What A GUI interface for the drag and drop or browsing for files or folders to itterate through.

Why I want this to be a batch process rather than a singular one. So I need a simple starting point. To begin I would want a simple GUI window with a file menu item to open files or folders. Functionally I would want this to open another window which lists the file names, their extention type, and path.

codeautopilot[bot] commented 4 days ago

Potential solution

To implement a GUI interface for batch processing files or folders, we can use the Tkinter library in Python. The GUI will allow users to drag and drop or browse for files or folders, and then display the file names, their extension types, and paths in a new window. This approach ensures a user-friendly interface for batch processing.

How to implement

  1. Import Required Libraries: Import the necessary modules from Tkinter and other standard libraries.
  2. Create Main Application Window: Set up the main window for the application.
  3. Add Menu Bar: Add a menu bar with options to open files or folders.
  4. File/Folder Dialog: Implement functionality to open file/folder dialog and retrieve selected paths.
  5. Display File Information: Create a new window to display the file names, their extension types, and paths.

Here is the complete implementation for gui_interface.py:

import tkinter as tk
from tkinter import filedialog, messagebox
import os

class GUIInterface:
    def __init__(self, root):
        self.root = root
        self.root.title("Batch File Processor")

        # Create a menu bar
        menubar = tk.Menu(root)
        filemenu = tk.Menu(menubar, tearoff=0)
        filemenu.add_command(label="Open Files", command=self.open_files)
        filemenu.add_command(label="Open Folder", command=self.open_folder)
        filemenu.add_separator()
        filemenu.add_command(label="Exit", command=root.quit)
        menubar.add_cascade(label="File", menu=filemenu)

        root.config(menu=menubar)

    def open_files(self):
        file_paths = filedialog.askopenfilenames(title="Select Files")
        if file_paths:
            self.display_file_info(file_paths)

    def open_folder(self):
        folder_path = filedialog.askdirectory(title="Select Folder")
        if folder_path:
            file_paths = [os.path.join(folder_path, f) for f in os.listdir(folder_path)]
            self.display_file_info(file_paths)

    def display_file_info(self, file_paths):
        info_window = tk.Toplevel(self.root)
        info_window.title("File Information")

        text = tk.Text(info_window, wrap='word')
        text.pack(expand=1, fill='both')

        for file_path in file_paths:
            if os.path.isfile(file_path):
                file_name = os.path.basename(file_path)
                file_ext = os.path.splitext(file_name)[1]
                text.insert(tk.END, f"Name: {file_name}, Extension: {file_ext}, Path: {file_path}\n")
            else:
                text.insert(tk.END, f"Path: {file_path} is not a file.\n")

        text.config(state=tk.DISABLED)

if __name__ == "__main__":
    root = tk.Tk()
    app = GUIInterface(root)
    root.mainloop()

Explanation:

  1. Import Required Libraries: The tkinter module is used for the GUI, and filedialog for file/folder selection dialogs. The os module is used to handle file paths.
  2. Create Main Application Window: The GUIInterface class initializes the main window and sets up the menu bar.
  3. Add Menu Bar: A menu bar with options to open files or folders is added. The filemenu contains commands to open files, open a folder, and exit the application.
  4. File/Folder Dialog: The open_files method uses filedialog.askopenfilenames to allow multiple file selection. The open_folder method uses filedialog.askdirectory to select a folder and lists all files in it.
  5. Display File Information: The display_file_info method creates a new window and displays the file names, their extension types, and paths in a text widget.

This implementation provides a basic GUI interface as requested. You can further enhance it by adding more features or improving the UI as needed.

Click here to create a Pull Request with the proposed solution

Files used for this task:

Changes on gui_interface.py To implement the requested GUI interface using Tkinter in Python, you can follow the steps below. This will create a simple GUI with a file menu to open files or folders and display another window listing the file names, their extension types, and paths. Here's a concrete implementation plan for `gui_interface.py`: 1. **Import Required Libraries**: Import the necessary modules from Tkinter and other standard libraries. 2. **Create Main Application Window**: Set up the main window for the application. 3. **Add Menu Bar**: Add a menu bar with options to open files or folders. 4. **File/Folder Dialog**: Implement functionality to open file/folder dialog and retrieve selected paths. 5. **Display File Information**: Create a new window to display the file names, their extension types, and paths. Here's the complete code for `gui_interface.py`: ```python import tkinter as tk from tkinter import filedialog, messagebox import os class GUIInterface: def __init__(self, root): self.root = root self.root.title("Batch File Processor") # Create a menu bar menubar = tk.Menu(root) filemenu = tk.Menu(menubar, tearoff=0) filemenu.add_command(label="Open Files", command=self.open_files) filemenu.add_command(label="Open Folder", command=self.open_folder) filemenu.add_separator() filemenu.add_command(label="Exit", command=root.quit) menubar.add_cascade(label="File", menu=filemenu) root.config(menu=menubar) def open_files(self): file_paths = filedialog.askopenfilenames(title="Select Files") if file_paths: self.display_file_info(file_paths) def open_folder(self): folder_path = filedialog.askdirectory(title="Select Folder") if folder_path: file_paths = [os.path.join(folder_path, f) for f in os.listdir(folder_path)] self.display_file_info(file_paths) def display_file_info(self, file_paths): info_window = tk.Toplevel(self.root) info_window.title("File Information") text = tk.Text(info_window, wrap='word') text.pack(expand=1, fill='both') for file_path in file_paths: if os.path.isfile(file_path): file_name = os.path.basename(file_path) file_ext = os.path.splitext(file_name)[1] text.insert(tk.END, f"Name: {file_name}, Extension: {file_ext}, Path: {file_path}\n") else: text.insert(tk.END, f"Path: {file_path} is not a file.\n") text.config(state=tk.DISABLED) if __name__ == "__main__": root = tk.Tk() app = GUIInterface(root) root.mainloop() ``` ### Explanation: 1. **Import Required Libraries**: The `tkinter` module is used for the GUI, and `filedialog` for file/folder selection dialogs. The `os` module is used to handle file paths. 2. **Create Main Application Window**: The `GUIInterface` class initializes the main window and sets up the menu bar. 3. **Add Menu Bar**: A menu bar with options to open files or folders is added. The `filemenu` contains commands to open files, open a folder, and exit the application. 4. **File/Folder Dialog**: The `open_files` method uses `filedialog.askopenfilenames` to allow multiple file selection. The `open_folder` method uses `filedialog.askdirectory` to select a folder and lists all files in it. 5. **Display File Information**: The `display_file_info` method creates a new window and displays the file names, their extension types, and paths in a text widget. This implementation provides a basic GUI interface as requested. You can further enhance it by adding more features or improving the UI as needed.