diff --git a/package.xml b/package.xml index 4f29cd2..333882a 100644 --- a/package.xml +++ b/package.xml @@ -29,4 +29,14 @@ + + + 0.1.0 + 50 + true + + sdk + + + diff --git a/ztools/ztools/resources/theme.py b/ztools/ztools/resources/theme.py index 32d2692..65bb397 100644 --- a/ztools/ztools/resources/theme.py +++ b/ztools/ztools/resources/theme.py @@ -8,35 +8,41 @@ # by Init.py at startup, making it available in: # Edit > Preferences > General > Stylesheet -from .icons import MOCHA +# Use the SDK palette when available; fall back to local MOCHA dict. +try: + from kindred_sdk import get_theme_tokens + + _palette = get_theme_tokens("catppuccin-mocha") +except Exception: + from .icons import MOCHA as _palette # Convenience aliases for commonly used colors -_base = MOCHA["base"] -_mantle = MOCHA["mantle"] -_crust = MOCHA["crust"] -_surface0 = MOCHA["surface0"] -_surface1 = MOCHA["surface1"] -_surface2 = MOCHA["surface2"] -_overlay0 = MOCHA["overlay0"] -_overlay1 = MOCHA["overlay1"] -_overlay2 = MOCHA["overlay2"] -_subtext0 = MOCHA["subtext0"] -_subtext1 = MOCHA["subtext1"] -_text = MOCHA["text"] -_lavender = MOCHA["lavender"] -_blue = MOCHA["blue"] -_sapphire = MOCHA["sapphire"] -_sky = MOCHA["sky"] -_teal = MOCHA["teal"] -_green = MOCHA["green"] -_yellow = MOCHA["yellow"] -_peach = MOCHA["peach"] -_maroon = MOCHA["maroon"] -_red = MOCHA["red"] -_mauve = MOCHA["mauve"] -_pink = MOCHA["pink"] -_flamingo = MOCHA["flamingo"] -_rosewater = MOCHA["rosewater"] +_base = _palette["base"] +_mantle = _palette["mantle"] +_crust = _palette["crust"] +_surface0 = _palette["surface0"] +_surface1 = _palette["surface1"] +_surface2 = _palette["surface2"] +_overlay0 = _palette["overlay0"] +_overlay1 = _palette["overlay1"] +_overlay2 = _palette["overlay2"] +_subtext0 = _palette["subtext0"] +_subtext1 = _palette["subtext1"] +_text = _palette["text"] +_lavender = _palette["lavender"] +_blue = _palette["blue"] +_sapphire = _palette["sapphire"] +_sky = _palette["sky"] +_teal = _palette["teal"] +_green = _palette["green"] +_yellow = _palette["yellow"] +_peach = _palette["peach"] +_maroon = _palette["maroon"] +_red = _palette["red"] +_mauve = _palette["mauve"] +_pink = _palette["pink"] +_flamingo = _palette["flamingo"] +_rosewater = _palette["rosewater"] def generate_stylesheet() -> str: @@ -1355,39 +1361,29 @@ def apply_spreadsheet_colors(): # Get the parameter group for Spreadsheet colors params = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Spreadsheet") - # Convert hex color to unsigned int (FreeCAD stores colors as unsigned 32-bit RGBA) - def hex_to_rgba_uint(hex_color: str) -> int: - """Convert hex color (#RRGGBB) to FreeCAD's unsigned int format (0xRRGGBBAA).""" - hex_color = hex_color.lstrip("#") - r = int(hex_color[0:2], 16) - g = int(hex_color[2:4], 16) - b = int(hex_color[4:6], 16) - a = 255 # Full opacity - # FreeCAD uses RGBA format as unsigned int - return (r << 24) | (g << 16) | (b << 8) | a + # Use SDK palette conversion when available; fall back to local implementation + try: + from kindred_sdk import load_palette + + palette = load_palette("catppuccin-mocha") + hex_to_rgba_uint = palette.hex_to_rgba_uint + colors = palette.colors + except Exception: + from .icons import MOCHA as colors + + def hex_to_rgba_uint(hex_color: str) -> int: + hex_color = hex_color.lstrip("#") + r = int(hex_color[0:2], 16) + g = int(hex_color[2:4], 16) + b = int(hex_color[4:6], 16) + return (r << 24) | (g << 16) | (b << 8) | 255 # Set text/foreground color to Catppuccin Mocha "text" (#cdd6f4) - text_color = hex_to_rgba_uint(MOCHA["text"]) - params.SetUnsigned("TextColor", text_color) - - # Set background colors - bg_color = hex_to_rgba_uint(MOCHA["base"]) - params.SetUnsigned("BackgroundColor", bg_color) - - # Alternate row background - alt_bg_color = hex_to_rgba_uint(MOCHA["surface0"]) - params.SetUnsigned("AltBackgroundColor", alt_bg_color) - - # Alias text color (for cells with aliases) - use teal for distinction - alias_color = hex_to_rgba_uint(MOCHA["teal"]) - params.SetUnsigned("AliasedTextColor", alias_color) - - # Positive number color - green - positive_color = hex_to_rgba_uint(MOCHA["green"]) - params.SetUnsigned("PositiveNumberColor", positive_color) - - # Negative number color - red - negative_color = hex_to_rgba_uint(MOCHA["red"]) - params.SetUnsigned("NegativeNumberColor", negative_color) + params.SetUnsigned("TextColor", hex_to_rgba_uint(colors["text"])) + params.SetUnsigned("BackgroundColor", hex_to_rgba_uint(colors["base"])) + params.SetUnsigned("AltBackgroundColor", hex_to_rgba_uint(colors["surface0"])) + params.SetUnsigned("AliasedTextColor", hex_to_rgba_uint(colors["teal"])) + params.SetUnsigned("PositiveNumberColor", hex_to_rgba_uint(colors["green"])) + params.SetUnsigned("NegativeNumberColor", hex_to_rgba_uint(colors["red"])) App.Console.PrintLog("ztools: Applied Catppuccin Mocha spreadsheet colors\n")