persistencia

This commit is contained in:
2026-01-20 13:45:56 +01:00
parent fa0ef01893
commit 08973257a8
2 changed files with 24 additions and 2 deletions
+7
View File
@@ -0,0 +1,7 @@
{
"path": "C:/mingw/gitea/python_gui/ROMs",
"selected": [
"atarilynx",
"atarist"
]
}
+17 -2
View File
@@ -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