From 034c0959cb7b76e503baece71d8ab4886833d9d9 Mon Sep 17 00:00:00 2001 From: Yeo Wang Date: Sun, 18 Aug 2024 18:12:15 +0000 Subject: [PATCH] first commit --- .gitignore | 1 + __init__.py | 28 ++++++++++++++++++++++++++++ color_name_to_hex.py | 40 ++++++++++++++++++++++++++++++++++++++++ requirements.txt | 1 + 4 files changed, 70 insertions(+) create mode 100644 .gitignore create mode 100644 __init__.py create mode 100644 color_name_to_hex.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed8ebf5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__ \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..247663d --- /dev/null +++ b/__init__.py @@ -0,0 +1,28 @@ +import importlib +import subprocess +import sys + +def check_and_install_dependencies(): + required_packages = ['colorcontroller'] + + for package in required_packages: + try: + importlib.import_module(package) + except ImportError: + print(f"{package} not found. Attempting to install...") + subprocess.check_call([sys.executable, "-m", "pip", "install", package]) + print(f"{package} installed successfully.") + +check_and_install_dependencies() + +from .color_name_to_hex import ColorNameToHex + +NODE_CLASS_MAPPINGS = { + "ColorNameToHex": ColorNameToHex +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "ColorNameToHex": "Color Name to Hex" +} + +__all__ = ['NODE_CLASS_MAPPINGS'] \ No newline at end of file diff --git a/color_name_to_hex.py b/color_name_to_hex.py new file mode 100644 index 0000000..63c56e2 --- /dev/null +++ b/color_name_to_hex.py @@ -0,0 +1,40 @@ +from ColorController import ColorController + +class ColorNameToHex: + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "color_name": ("STRING", { + "multiline": False, + "default": "blue" + }), + }, + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("hex_color",) + FUNCTION = "convert" + CATEGORY = "color" + + def convert(self, color_name): + try: + color = ColorController(name=color_name) + hex_codes = color.hex_code + if isinstance(hex_codes, list): + # If multiple hex codes are returned, use the first one + hex_color = hex_codes[0] + else: + hex_color = hex_codes + return (hex_color,) + except Exception as e: + print(f"Error converting color name '{color_name}': {str(e)}") + return ("#000000",) # Return black as default + +NODE_CLASS_MAPPINGS = { + "ColorNameToHex": ColorNameToHex +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "ColorNameToHex": "Color Name to Hex" +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d2af14f --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +colorcontroller \ No newline at end of file