feat: add Gallery TUI for interactive configuration and generation
- Implemented a terminal user interface (TUI) for configuring the gallery generator using Textual. - Included functionality to manage sources with add/remove - Integrated a log pane to display generation output from subprocess calls. - Implemented save functionality to persist configuration changes.
This commit is contained in:
@@ -5,17 +5,50 @@ This module provides dataclasses for managing configuration, including
|
||||
defaults for gallery generation settings.
|
||||
"""
|
||||
|
||||
import shutil
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
import yaml
|
||||
from platformdirs import user_config_dir
|
||||
|
||||
|
||||
def default_config_path() -> Path:
|
||||
"""Return the path to the package-bundled default config."""
|
||||
"""Return the path to the package-bundled read-only template config."""
|
||||
return Path(__file__).parent / "config.yaml"
|
||||
|
||||
|
||||
def user_config_path() -> Path:
|
||||
"""Return the user-level config path (~/.config/gallery/config.yaml).
|
||||
|
||||
Follows the XDG Base Directory spec via platformdirs:
|
||||
Linux/macOS → ~/.config/gallery/config.yaml
|
||||
Windows → %APPDATA%/gallery/config.yaml
|
||||
"""
|
||||
return Path(user_config_dir("gallery", appauthor=False)) / "config.yaml"
|
||||
|
||||
|
||||
def get_active_config_path() -> Path:
|
||||
"""Return the config path to use, with this precedence:
|
||||
|
||||
1. User config (~/.config/gallery/config.yaml) — if it exists
|
||||
2. Package-bundled template — fallback
|
||||
"""
|
||||
ucp = user_config_path()
|
||||
return ucp if ucp.exists() else default_config_path()
|
||||
|
||||
|
||||
def ensure_user_config() -> Path:
|
||||
"""Ensure ~/.config/gallery/config.yaml exists, creating it from the
|
||||
package template if needed. Returns the path.
|
||||
"""
|
||||
ucp = user_config_path()
|
||||
if not ucp.exists():
|
||||
ucp.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy(default_config_path(), ucp)
|
||||
return ucp
|
||||
|
||||
|
||||
def _load_raw(path: Path) -> Dict[str, Any]:
|
||||
with open(path, "r") as f:
|
||||
return yaml.safe_load(f) or {}
|
||||
@@ -182,7 +215,6 @@ class GalleryConfig:
|
||||
|
||||
data = {
|
||||
"paths": {
|
||||
"work_dir": str(Path.cwd()),
|
||||
"web_folder": str(self.web_folder),
|
||||
},
|
||||
"gallery": {
|
||||
|
||||
Reference in New Issue
Block a user