From 08973257a89b4b4391c3492015029d5a31efccfb Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 20 Jan 2026 13:45:56 +0100 Subject: [PATCH] persistencia --- config.json | 7 +++++++ test_tkinter.py | 19 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 config.json diff --git a/config.json b/config.json new file mode 100644 index 0000000..06a33f4 --- /dev/null +++ b/config.json @@ -0,0 +1,7 @@ +{ + "path": "C:/mingw/gitea/python_gui/ROMs", + "selected": [ + "atarilynx", + "atarist" + ] +} \ No newline at end of file diff --git a/test_tkinter.py b/test_tkinter.py index 2911b3c..8520df1 100644 --- a/test_tkinter.py +++ b/test_tkinter.py @@ -3,7 +3,9 @@ import json import tkinter as tk from tkinter import filedialog, messagebox -CONFIG_FILE = "config.json" +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +CONFIG_FILE = os.path.join(BASE_DIR, "config.json") + class DirectorySelectorApp: def __init__(self, root): @@ -68,20 +70,33 @@ class DirectorySelectorApp: "selected": [self.listbox.get(i) for i in self.listbox.curselection()] } + print("\n[DEBUG] Intentando guardar configuración...") + print("[DEBUG] Ruta del archivo:", os.path.abspath(CONFIG_FILE)) + print("[DEBUG] Datos a guardar:", data) + try: with open(CONFIG_FILE, "w", encoding="utf-8") as f: json.dump(data, f, indent=4) + print("[DEBUG] Guardado correctamente.") except Exception as e: + print("[DEBUG] ERROR al guardar:", repr(e)) messagebox.showerror("Error", f"No se pudo guardar la configuración:\n{e}") def load_config(self): + print("[DEBUG] Buscando archivo de configuración...") + if not os.path.exists(CONFIG_FILE): + print("[DEBUG] No existe config.json, nada que cargar.") return + print("[DEBUG] config.json encontrado:", os.path.abspath(CONFIG_FILE)) + try: with open(CONFIG_FILE, "r", encoding="utf-8") as f: data = json.load(f) - except Exception: + print("[DEBUG] Configuración cargada:", data) + except Exception as e: + print("[DEBUG] ERROR al cargar:", repr(e)) return # Restaurar ruta