first commit of shared_libs coarse build
This commit is contained in:
146
logview_app_config.py
Normal file
146
logview_app_config.py
Normal file
@ -0,0 +1,146 @@
|
||||
"""Configuration for the LogViewer application."""
|
||||
|
||||
import gettext
|
||||
import locale
|
||||
from pathlib import Path
|
||||
from typing import Dict, Any
|
||||
|
||||
|
||||
class AppConfig:
|
||||
"""Central configuration and system setup manager for the LogViewer application.
|
||||
|
||||
This class serves as a singleton-like container for all global configuration data,
|
||||
including paths, UI settings, localization, versioning, and system-specific resources.
|
||||
It ensures that required directories, files, and services are created and configured
|
||||
before the application starts. Additionally, it provides tools for managing translations,
|
||||
default settings, and autostart functionality to maintain a consistent user experience.
|
||||
|
||||
Key Responsibilities:
|
||||
- Centralizes all configuration values (paths, UI preferences, localization).
|
||||
- Ensures required directories and files exist on startup.
|
||||
- Handles translation setup via `gettext` for multilingual support.
|
||||
- Manages default settings file generation.
|
||||
- Configures autostart services using systemd for user-specific launch behavior.
|
||||
|
||||
This class is used globally across the application to access configuration data
|
||||
consistently and perform system-level setup tasks.
|
||||
"""
|
||||
|
||||
# Logging
|
||||
LOG_DIR = Path.home() / ".local/share/lxlogs"
|
||||
Path(LOG_DIR).mkdir(parents=True, exist_ok=True)
|
||||
LOG_FILE_PATH = LOG_DIR / "logviewer.log"
|
||||
|
||||
# Localization
|
||||
APP_NAME: str = "logviewer"
|
||||
LOCALE_DIR: Path = Path("/usr/share/locale/")
|
||||
|
||||
# Base paths
|
||||
BASE_DIR: Path = Path.home()
|
||||
CONFIG_DIR: Path = BASE_DIR / ".config/logviewer"
|
||||
|
||||
# Configuration files
|
||||
SETTINGS_FILE: Path = CONFIG_DIR / "settings"
|
||||
DEFAULT_SETTINGS: Dict[str, str] = {
|
||||
"# Configuration": "on",
|
||||
"# Theme": "light",
|
||||
"# Tooltips": True,
|
||||
"# Autostart": "off",
|
||||
"# Logfile": LOG_FILE_PATH,
|
||||
}
|
||||
|
||||
# Updates
|
||||
# 1 = 1. Year, 09 = Month of the Year, 2924 = Day and Year of the Year
|
||||
VERSION: str = "v. 1.06.3125"
|
||||
UPDATE_URL: str = "https://git.ilunix.de/api/v1/repos/punix/Wire-Py/releases"
|
||||
DOWNLOAD_URL: str = "https://git.ilunix.de/punix/Wire-Py/archive"
|
||||
|
||||
# UI configuration
|
||||
UI_CONFIG: Dict[str, Any] = {
|
||||
"window_title2": "LogViewer",
|
||||
"window_size": (600, 383),
|
||||
"font_family": "Ubuntu",
|
||||
"font_size": 11,
|
||||
"resizable_window": (True, True),
|
||||
}
|
||||
|
||||
# Images and icons paths
|
||||
IMAGE_PATHS: Dict[str, Path] = {
|
||||
"icon_info": "/usr/share/icons/lx-icons/64/info.png",
|
||||
"icon_error": "/usr/share/icons/lx-icons/64/error.png",
|
||||
"icon_log": "/usr/share/icons/lx-icons/48/log.png",
|
||||
}
|
||||
|
||||
# System-dependent paths
|
||||
SYSTEM_PATHS: Dict[str, Path] = {
|
||||
"tcl_path": "/usr/share/TK-Themes",
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def setup_translations() -> gettext.gettext:
|
||||
"""
|
||||
Initialize translations and set the translation function
|
||||
Special method for translating strings in this file
|
||||
|
||||
Returns:
|
||||
The gettext translation function
|
||||
"""
|
||||
locale.bindtextdomain(AppConfig.APP_NAME, AppConfig.LOCALE_DIR)
|
||||
gettext.bindtextdomain(AppConfig.APP_NAME, AppConfig.LOCALE_DIR)
|
||||
gettext.textdomain(AppConfig.APP_NAME)
|
||||
return gettext.gettext
|
||||
|
||||
@classmethod
|
||||
def create_default_settings(cls) -> None:
|
||||
"""Creates default settings if they don't exist"""
|
||||
if not cls.SETTINGS_FILE.exists():
|
||||
content = "\n".join(
|
||||
f"[{k.upper()}]\n{v}" for k, v in cls.DEFAULT_SETTINGS.items()
|
||||
)
|
||||
cls.SETTINGS_FILE.write_text(content)
|
||||
|
||||
@classmethod
|
||||
def ensure_directories(cls) -> None:
|
||||
"""Ensures that all required directories exist"""
|
||||
if not cls.CONFIG_DIR.exists():
|
||||
cls.CONFIG_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
@classmethod
|
||||
def ensure_log(cls) -> None:
|
||||
"""Ensures that the log file exists"""
|
||||
if not cls.LOG_FILE_PATH.exists():
|
||||
cls.LOG_FILE_PATH.touch()
|
||||
|
||||
|
||||
# here is initializing the class for translation strings
|
||||
_ = AppConfig.setup_translations()
|
||||
|
||||
|
||||
class Msg:
|
||||
"""
|
||||
A utility class that provides centralized access to translated message strings.
|
||||
|
||||
This class contains a dictionary of message strings used throughout the Wire-Py application.
|
||||
All strings are prepared for translation using gettext. The short key names make the code
|
||||
more concise while maintaining readability.
|
||||
|
||||
Attributes:
|
||||
STR (dict): A dictionary mapping short keys to translated message strings.
|
||||
Keys are abbreviated for brevity but remain descriptive.
|
||||
|
||||
Usage:
|
||||
Import this class and access messages using the dictionary:
|
||||
`Msg.STR["sel_tl"]` returns the translated "Select tunnel" message.
|
||||
|
||||
Note:
|
||||
Ensure that gettext translation is properly initialized before
|
||||
accessing these strings to ensure correct localization.
|
||||
"""
|
||||
|
||||
STR: Dict[str, str] = {
|
||||
# Strings for messages
|
||||
}
|
||||
TTIP: Dict[str, str] = {
|
||||
# Strings for Tooltips
|
||||
"settings": _("Click for Settings"),
|
||||
}
|
Reference in New Issue
Block a user