29 lines
910 B
Python
29 lines
910 B
Python
# backend/core/directory_handler.py
|
|
import os
|
|
from pathlib import Path
|
|
import tkinter as tk
|
|
from tkinter import filedialog
|
|
from flask import jsonify
|
|
|
|
def select_directory():
|
|
"""
|
|
Show directory selection dialog and return selected path
|
|
"""
|
|
root = tk.Tk()
|
|
root.withdraw() # Hide the main window
|
|
|
|
try:
|
|
print("Opening directory dialog...") # Debug
|
|
directory = filedialog.askdirectory(
|
|
title="Select Work Directory",
|
|
initialdir=os.path.expanduser("~")
|
|
)
|
|
print(f"Selected directory: {directory}") # Debug
|
|
result = {"path": directory} if directory else {"error": "No directory selected"}
|
|
print(f"Returning result: {result}") # Debug
|
|
return result
|
|
except Exception as e:
|
|
print(f"Error in select_directory: {str(e)}") # Debug
|
|
return {"error": str(e)}
|
|
finally:
|
|
root.destroy() |