rename appconfig and mv configmanager to shared_libs

This commit is contained in:
2025-08-30 19:08:56 +02:00
parent 5f5cd78ee0
commit 269da49a1a
15 changed files with 22 additions and 94 deletions

View File

@@ -1,75 +0,0 @@
import json
from pathlib import Path
from typing import Any, Dict
class ConfigManager:
"""Manages loading and saving of application settings in a JSON file."""
def __init__(self, file_path: Path):
"""
Initializes the ConfigManager.
Args:
file_path: The path to the configuration file.
"""
self.file_path = file_path
self.settings: Dict[str, Any] = {}
self.load()
def load(self) -> None:
"""Loads the settings from the JSON file."""
if self.file_path.exists():
try:
with open(self.file_path, 'r', encoding='utf-8') as f:
self.settings = json.load(f)
except (IOError, json.JSONDecodeError) as e:
print(f"Error loading config file {self.file_path}: {e}")
self.settings = {}
else:
self.settings = {}
def save(self) -> None:
"""Saves the current settings to the JSON file."""
try:
# Ensure the parent directory exists
self.file_path.parent.mkdir(parents=True, exist_ok=True)
with open(self.file_path, 'w', encoding='utf-8') as f:
json.dump(self.settings, f, indent=4)
except IOError as e:
print(f"Error saving config file {self.file_path}: {e}")
def get_setting(self, key: str, default: Any = None) -> Any:
"""
Gets a setting value.
Args:
key: The key of the setting.
default: The default value to return if the key is not found.
Returns:
The value of the setting or the default value.
"""
return self.settings.get(key, default)
def set_setting(self, key: str, value: Any) -> None:
"""
Sets a setting value and immediately saves it to the file.
Args:
key: The key of the setting.
value: The value to set.
"""
self.settings[key] = value
self.save()
def remove_setting(self, key: str) -> None:
"""
Removes a setting from the configuration.
Args:
key: The key of the setting to remove.
"""
if key in self.settings:
del self.settings[key]
self.save()

View File

@@ -3,7 +3,7 @@ import os
import fnmatch
import shutil
import re
from app_config import AppConfig
from pbp_app_config import AppConfig
from shared_libs.logger import app_logger

View File

@@ -8,9 +8,9 @@ from shared_libs.log_window import LogWindow
from shared_libs.logger import app_logger
from shared_libs.animated_icon import AnimatedIcon
from shared_libs.common_tools import IconManager
from config_manager import ConfigManager
from shared_libs.config_manager import ConfigManager
from backup_manager import BackupManager
from app_config import AppConfig, Msg
from pbp_app_config import AppConfig, Msg
from pyimage_ui.scheduler_frame import SchedulerFrame
from pyimage_ui.backup_content_frame import BackupContentFrame
from pyimage_ui.header_frame import HeaderFrame

View File

@@ -9,7 +9,7 @@ from typing import Optional
from shared_libs.message import MessageDialog
from shared_libs.custom_file_dialog import CustomFileDialog
from app_config import AppConfig, Msg
from pbp_app_config import AppConfig, Msg
from shared_libs.logger import app_logger
from shared_libs.common_tools import message_box_animation

View File

@@ -3,7 +3,7 @@ from tkinter import ttk
import os
from pathlib import Path
from app_config import AppConfig, Msg
from pbp_app_config import AppConfig, Msg
from shared_libs.animated_icon import AnimatedIcon
from pyimage_ui.shared_logic import enforce_backup_type_exclusivity
@@ -170,9 +170,11 @@ class AdvancedSettingsFrame(tk.Toplevel):
items_to_display[backup_root_path_str] = (
Msg.STR["no"], backup_root_path.name, backup_root_path_str)
restore_src_path = self.config_manager.get_setting("restore_source_path")
restore_src_path = self.config_manager.get_setting(
"restore_source_path")
if restore_src_path and Path(restore_src_path).is_dir():
restore_root_path = Path(f"/{str(Path(restore_src_path)).strip('/').split('/')[0]}")
restore_root_path = Path(
f"/{str(Path(restore_src_path)).strip('/').split('/')[0]}")
restore_root_path_str = str(restore_root_path.absolute())
items_to_display[restore_root_path_str] = (
Msg.STR["no"], restore_root_path.name, restore_root_path_str)

View File

@@ -1,7 +1,7 @@
import tkinter as tk
from tkinter import ttk
from app_config import Msg
from pbp_app_config import Msg
from pyimage_ui.system_backup_content_frame import SystemBackupContentFrame
from pyimage_ui.user_backup_content_frame import UserBackupContentFrame

View File

@@ -1,6 +1,6 @@
# pyimage/ui/drawing.py
import tkinter as tk
from app_config import AppConfig, Msg
from pbp_app_config import AppConfig, Msg
import os
import threading
from shared_libs.animated_icon import AnimatedIcon

View File

@@ -1,6 +1,6 @@
import tkinter as tk
from app_config import Msg
from pbp_app_config import Msg
from shared_libs.common_tools import IconManager

View File

@@ -2,7 +2,7 @@
import os
import shutil
from shared_libs.message import MessageDialog
from app_config import Msg
from pbp_app_config import Msg
class Navigation:
@@ -146,7 +146,8 @@ class Navigation:
# Show the main content frames
self.app.canvas_frame.grid()
self.app.top_bar.grid()
self._update_task_bar_visibility("backup") # Ensures action_frame is visible
# Ensures action_frame is visible
self._update_task_bar_visibility("backup")
# Restore visibility of size frames based on the current mode
if self.app.mode == 'backup':

View File

@@ -4,7 +4,7 @@ import os
from shared_libs.custom_file_dialog import CustomFileDialog
from shared_libs.message import MessageDialog
from app_config import Msg
from pbp_app_config import Msg
class SchedulerFrame(ttk.Frame):

View File

@@ -3,7 +3,7 @@ from tkinter import ttk
import os
from pathlib import Path
from app_config import AppConfig, Msg
from pbp_app_config import AppConfig, Msg
from pyimage_ui.advanced_settings_frame import AdvancedSettingsFrame
@@ -14,7 +14,7 @@ class SettingsFrame(ttk.Frame):
self.navigation = navigation
self.actions = actions
self.app_config = AppConfig()
self.pbp_app_config = AppConfig()
self.user_exclude_patterns = []
# --- Container for Treeviews ---

View File

@@ -2,7 +2,7 @@ import tkinter as tk
from tkinter import ttk
import os
from app_config import Msg
from pbp_app_config import Msg
class SystemBackupContentFrame(ttk.Frame):

View File

@@ -2,7 +2,7 @@ import tkinter as tk
from tkinter import ttk
import os
from app_config import Msg
from pbp_app_config import Msg
class UserBackupContentFrame(ttk.Frame):
@@ -26,7 +26,7 @@ class UserBackupContentFrame(ttk.Frame):
"size", text=Msg.STR["size"])
self.content_tree.heading(
"folder_name", text=Msg.STR["folder"])
self.content_tree.column("date", width=120, anchor="w")
self.content_tree.column("size", width=100, anchor="e")
self.content_tree.column("folder_name", width=250, anchor="w")

View File

@@ -4,7 +4,7 @@ import os
from shared_libs.message import MessageDialog
from shared_libs.custom_file_dialog import CustomFileDialog
from app_config import Msg
from pbp_app_config import Msg
class ScheduleJobDialog(tk.Toplevel):