Skip to content

src/robot/types #35

Closed
Closed

Description

@KavinduMethpura
No description provided.

Activity

  1. Dinithi-Gunathilake commented on Nov 11, 2025

    @Dinithi-Gunathilake

    In src/robot/types/rgb_color_type.py ;
    MODIFICATION #1: Change the original method body to fix the crash from the non-existent _validate() method.

    def set_color_from_hex_code(self, hex_code: str) -> None:
        # Expecting format like "#RRGGBB"
        try:
            r = int(hex_code[1:3], 16)
            g = int(hex_code[3:5], 16)
            b = int(hex_code[5:7], 16)
        except (ValueError, TypeError, IndexError):
            # Handle bad hex codes (e.g., "#F00", "ABC", or too short)
            raise RGBColorException(f"Invalid hex code format: {hex_code}")
    
        # Use the main set_color method, which already validates 0-255
        self.set_color(r, g, b)
    

    MODIFICATION #2: Change the str method of RGBColorType to output the hex code, since that's what the system seems to use for input.
    This makes the class "symmetrical": it reads hex codes, and it prints itself as a hex code.

    # NEW, BETTER version
    def __str__(self) -> str:
        # :02x formats an integer as a 2-character hex string (e.g., 0 -> "00")
        return f"#{self.R:02x}{self.G:02x}{self.B:02x}".upper()
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions