color_palette_configurator.py¶
Color palette configuration node implementation for Houdini.
This module provides functionality for creating, modifying, and managing color palettes in Houdini through a specialized node interface. It handles:
- Importing and exporting Houdini color palette files
- Converting between hex and RGB color formats
- Gradient-based color generation including cosine gradients
- Text-based color parsing and extraction
- Screen color sampling
- Default Houdini color palette management
The module uses a singleton pattern to ensure consistent state management per node instance, with separate managers for gradient and text-based operations.
Classes:
Name | Description |
---|---|
ColorPaletteConfigurator |
Core color palette management |
GradientManager |
Gradient-based color operations |
TextColorManager |
Text-based color parsing and conversion |
Note
This node implementation relies on the nodeweaver.utils.colors module for core color manipulation functions and nodeweaver.config for gradient presets.
ColorPaletteConfigurator
¶
Manages color palette configuration node functionality.
This class handles importing, exporting and modifying color palettes for use in Houdini's interface. It maintains a singleton instance per node to ensure consistent state.
Attributes:
Name | Type | Description |
---|---|---|
node |
HDA node this instance manages |
Example
configurator = ColorPaletteConfigurator.get_instance(node) configurator.import_colors()
Note
Use get_instance() instead of direct instantiation to maintain singleton pattern.
Source code in nodes/color_palette_configurator.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
__init__(node)
¶
Initialize with the node instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Node
|
The Houdini node containing color palette parameters. Must be a valid node with color parameters. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If node is None or invalid |
TypeError
|
If node is not of type hou.Node |
Source code in nodes/color_palette_configurator.py
export_colors()
¶
Export colors to a palette file.
Saves the current color palette configuration to a file in the specified format.
Returns:
Name | Type | Description |
---|---|---|
bool |
None
|
True if export successful, False otherwise |
Raises:
Type | Description |
---|---|
ValueError
|
If filepath is invalid or format_type not supported |
IOError
|
If file cannot be written |
Example
configurator = ColorPaletteConfigurator(node) success = configurator.export_palette('C:/colors.json')
Source code in nodes/color_palette_configurator.py
get_instance(node)
classmethod
¶
Get or create configurator instance for a node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Node
|
HDA node requiring configurator |
required |
Returns:
Type | Description |
---|---|
ColorPaletteConfigurator
|
Singleton instance for the node |
Example
configurator = ColorPaletteConfigurator.get_instance(node) configurator.reset_colors()
Source code in nodes/color_palette_configurator.py
import_colors()
¶
Import colors from a palette file.
Reads colors from a Houdini color palette file and creates corresponding entries in the node's color list.
Notes
- Validates file format and existence
- Prompts for confirmation if colors exist
- Converts color formats automatically
- Updates both RGB and hex representations
Example
configurator.import_colors() # Imports from node's file parameter
Source code in nodes/color_palette_configurator.py
reset_colors()
¶
Reset colors to Houdini defaults.
Resets all color parameters to their original Houdini default values, discarding any custom color palette settings.
Raises:
Type | Description |
---|---|
RuntimeError
|
If default values cannot be restored |
ValueError
|
If color parameters are invalid |
Example
configurator = ColorPaletteConfigurator(node) configurator.reset_colors() # Restores default Houdini colors
Source code in nodes/color_palette_configurator.py
update_hex(kwargs)
¶
Update hex value when RGB changed.
Callback method that updates the hex color parameter whenever RGB values are modified by the user.
Raises:
Type | Description |
---|---|
ValueError
|
If RGB values are invalid |
RuntimeError
|
If hex parameter update fails |
Example
Automatically called when RGB parameters change¶
node.parm('r').set(255) # Triggers hex update¶
Source code in nodes/color_palette_configurator.py
update_rgb(kwargs)
¶
Update RGB values when hex changed.
Callback method that updates the RGB color parameters whenever the hex color value is modified by the user.
Raises:
Type | Description |
---|---|
ValueError
|
If hex value is invalid |
RuntimeError
|
If RGB parameter updates fail |
Example
Automatically called when hex parameter changes¶
node.parm('hex').set('#FF0000') # Triggers RGB update¶
Source code in nodes/color_palette_configurator.py
GradientManager
¶
Manages gradient-based color operations for the color palette configurator.
Handles creation, sampling, and management of color gradients including cosine-based gradient generation.
Example
manager = GradientManager.get_instance(node) manager.create_cosine_gradient()
Note
Use get_instance() instead of direct instantiation.
Source code in nodes/color_palette_configurator.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
|
__init__(node)
¶
Initialize with the node instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Node
|
The Houdini node containing gradient parameters. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If node is None or invalid. |
Source code in nodes/color_palette_configurator.py
add_gradient_samples()
¶
Add gradient samples to the main color list.
Includes the option to delete samples from the gradient multiparm afterwards.
Raises:
Type | Description |
---|---|
RuntimeError
|
If sample addition fails. |
ValueError
|
If color parameters are invalid. |
Source code in nodes/color_palette_configurator.py
apply_cosine_preset()
¶
Apply a predefined cosine gradient preset.
Applies a preset gradient using cosine interpolation between colors, creating smooth transitions between complementary colors.
Raises:
Type | Description |
---|---|
RuntimeError
|
If gradient preset cannot be applied |
ValueError
|
If gradient parameters are invalid |
Example
manager = GradientManager.get_instance(node) manager.apply_cosine_preset() # Applies cosine gradient
Source code in nodes/color_palette_configurator.py
create_auto_samples()
¶
Create automatically spaced gradient samples.
Creates evenly spaced samples along the gradient, optionally replacing existing samples.
Raises:
Type | Description |
---|---|
RuntimeError
|
If auto sample creation fails. |
ValueError
|
If sample count is invalid. |
Source code in nodes/color_palette_configurator.py
create_cosine_gradient()
¶
Create a cosine-based color gradient.
Generates a gradient using cosine functions with configurable parameters for each color channel.
Notes
- Uses separate cosine functions for R, G, B channels
- Maintains smooth color transitions
- Automatically updates gradient samples
Example
manager.create_cosine_gradient()
Source code in nodes/color_palette_configurator.py
get_instance(node)
classmethod
¶
Get or create gradient manager instance for a node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Node
|
The Houdini node to manage gradients for. |
required |
Returns:
Name | Type | Description |
---|---|---|
GradientManager |
GradientManager
|
Instance associated with the node. |
Raises:
Type | Description |
---|---|
TypeError
|
If node is not a hou.Node instance. |
Source code in nodes/color_palette_configurator.py
reset_gradient_samples(kwargs)
¶
Reset colors on all gradient samples.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs
|
Dict
|
Parameter kwargs from callback. |
required |
Raises:
Type | Description |
---|---|
RuntimeError
|
If gradient reset fails. |
Source code in nodes/color_palette_configurator.py
sample_gradient(kwargs, index=-1)
¶
Sample a color from the defined gradient.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs
|
Dict
|
Parameter kwargs from callback. |
required |
index
|
int
|
Specific index to sample. Defaults to -1 for current. |
-1
|
Raises:
Type | Description |
---|---|
ValueError
|
If gradient parameters are invalid. |
Source code in nodes/color_palette_configurator.py
TextColorManager
¶
Manages text-based color operations for the color palette configurator.
A class that handles text input parsing and color extraction for the color palette configurator, supporting different text formats and gradient generation.
Attributes:
Name | Type | Description |
---|---|---|
node |
Node
|
The Houdini node containing text and color parameters |
_instances |
Dict[str, TextColorManager]
|
Class-level dictionary of instances |
Methods:
Name | Description |
---|---|
get_instance |
Get or create manager instance for a node |
extract_text_colors |
Parse text input for color values |
add_text_samples |
Add extracted colors to main palette |
add_text_gradient |
Create gradient from text colors |
Example
node = hou.node('/obj/palette1') manager = TextColorManager.get_instance(node) manager.extract_text_colors()
Source code in nodes/color_palette_configurator.py
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 |
|
add_text_gradient()
¶
Create a gradient from text-based colors.
Creates a gradient ramp using colors extracted from text input, with linear interpolation between colors.
Raises:
Type | Description |
---|---|
RuntimeError
|
If gradient creation fails |
ValueError
|
If no valid colors found in text |
Source code in nodes/color_palette_configurator.py
add_text_samples()
¶
Add text-based colors to the main color list.
Extracts colors from text input and adds them to the main color parameter list, with options for positioning and text cleanup.
Raises:
Type | Description |
---|---|
RuntimeError
|
If color addition fails |
Source code in nodes/color_palette_configurator.py
extract_text_colors(delete_lines=False)
¶
Extract color values from text input.
Parses text input for hex color values in different formats based on mode.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
delete_lines
|
bool
|
Whether to remove color lines from text. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Tuple[int, List[str], str]
|
Tuple[int, List[str], str]: Contains: - Number of colors found - List of extracted hex color values - Updated text with colors optionally removed |
Raises:
Type | Description |
---|---|
ValueError
|
If text input is invalid |
Source code in nodes/color_palette_configurator.py
get_instance(node)
classmethod
¶
Get or create text color manager instance for a node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
Node
|
The Houdini node to manage text colors for |
required |
Returns:
Name | Type | Description |
---|---|---|
TextColorManager |
TextColorManager
|
Instance associated with the node |
Raises:
Type | Description |
---|---|
TypeError
|
If node is not a hou.Node instance |
Source code in nodes/color_palette_configurator.py
sample_screen_color(kwargs, ramp_parm_name)
¶
Sample a color from the screen using a custom python state from SideFX Labs. The sampled color is applied to the parameter specified in the kwargs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kwargs
|
Dict
|
Node callback kwargs dictionary containing 'parms' key that specifies target parameters to receive the color value |
required |
Note
This is a wrapper around screensampling.sample_ramp_color() that handles the parameter formatting required by the underlying function.