Source code for cosedaUI.windowsettings

"""Utilities for UI settings: version, changelog, and OS-specific style hints."""

import os
import platform

[docs] def get_version_from_log(versionlog): """Return the most recent version entry from the version log; fallback to 'Unknown' on error.""" # Get the absolute path of the current script script_path = os.path.abspath(__file__) # Get the directory containing the script script_dir = os.path.dirname(script_path) # Get the parent directory parent_dir = os.path.dirname(script_dir) versionlog_path = os.path.join(parent_dir, versionlog) try: with open(versionlog_path, 'r') as file: for line in file: pass version_info = line.strip().split(':') if len(version_info) >= 2: version_number = version_info[0].strip() return version_number else: return "Unknown" except Exception: try: root_dir = os.path.abspath(os.path.join(parent_dir, os.pardir)) versionlog_path = os.path.join(root_dir, versionlog) with open(versionlog_path, 'r') as file: for line in file: pass version_info = line.strip().split(':') if len(version_info) >= 2: version_number = version_info[0].strip() return version_number except Exception as e: return f"Error: {str(e)}"
from importlib.resources import files
[docs] def load_changelog(versionlog="CHANGELOG"): """Return changelog text safely. Lookup order: 1) packaged resource: cosedaUI/resources/CHANGELOG (wheel/Homebrew safe) 2) local resources dir next to the module (editable installs) 3) project root one level above the package (dev tree) If none found, return an empty string. """ # 1) packaged resource inside the installed wheel try: return files("cosedaUI.resources").joinpath(versionlog).read_text(encoding="utf-8") except Exception: pass # 2) resources directory next to this file (editable installs) try: here = os.path.dirname(os.path.abspath(__file__)) candidate = os.path.join(here, "resources", versionlog) if os.path.exists(candidate): with open(candidate, "r", encoding="utf-8") as f: return f.read() except Exception: pass # 3) project root (developer checkout) try: pkg_dir = os.path.dirname(os.path.abspath(__file__)) for up_levels in (1, 2): root = os.path.abspath(os.path.join(pkg_dir, *([os.pardir] * up_levels))) candidate = os.path.join(root, versionlog) if os.path.exists(candidate): with open(candidate, "r", encoding="utf-8") as f: return f.read() except Exception: pass return ""
[docs] def set_style(): current_os = platform.system() if current_os == 'Windows': theme = 'vista' elif current_os == 'Darwin': theme = 'aqua' elif current_os == 'Linux': theme = 'clam' else: theme = 'default' return theme