pycocoa.colors.Color

Package pycocoa :: Module colors :: Class Color |
[frames] | no frames]

# Class Color

      object --+
               |
    bases._Type0 --+
                   |
                  Color

Known Subclasses:
  - CMYColor
  - , GrayScaleColor
  - , HSBColor
  - , RGBColor
  - , _SystemColor

Base `Color` class wrapping `NSColor` objects, intended specifically to avoid fatal exceptions when accessing non-applicable `NSColor` attributes.

For example, getting the `cyanComponent` of an RGB `NSColor` instance throws an `NSException`, but using Color.cyan for any non-CMYColor safely returns `None`. Likewise for other attributes.

Note: Only pre-existing `NSColor` can be wrapped, creating new `NSColor` is reserved for a future `PyCocoa` release. Also, color conversion and any other "color math" are not supported (yet).

Instance Methods
__init__(self, name, nsColor='') New Color from an existing `NSColor`. |
copy(self, name) Copy this color with a new given name. |
toCMY3(self, upscale=0) Get the RGB components as 3-tuple `(cyan, magenta, yellow`) or `None` if not applicable. |
toHSB3(self, upscale=0) Get the HSB components as 3-tuple `(hue, saturation, brightness`) or `None` if not applicable. |
toRGB3(self, upscale=0) Get the RGB components as 3-tuple `(red, green, blue`) or `None` if not applicable. |
Inherited from `bases._Type0`: `__repr__`, `__str__`, `type2strepr` Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__sizeof__`, `__subclasshook__`

Properties
| alpha Get the alpha component (`float`) or `None` if not applicable or ignored.
| black Get the black component (`float`) or `None` if not applicable.
| blue Get the blue component (`float`) or `None` if not applicable.
| brightness Get the brightness component (`float`) or `None` if not applicable.
| colorSpace Get the space of this color (`str`).
| cyan Get the cyan component (`float`) or `None` if not applicable.
| green Get the green component (`float`) or `None` if not applicable.
| hex Get the RGB components as hex (`int`) or `None` if not applicable.
| hue Get the hue component (`float`) or `None` if not applicable.
| magenta Get the magenta component (`float`) or `None` if not applicable.
| n Get the number of components of this color (`int`) or `None` if not applicable.
| name Get the given name of this color (`str`).
| nsColor Get the name of the `NSColor` of this color (`str`).
| red Get the red component (`float`) or `None` if not applicable.
| saturation Get the saturation component (`float`) or `None` if not applicable.
| white Get the white component (`float`) or `None` if not applicable.
| yellow Get the yellow component (`float`) or `None` if not applicable.
Inherited from `bases._Type0`: `NS`, `NSDelegate`, `typename` Inherited from `object`: `__class__`

Method Details

### __init__(self, name, nsColor='') (Constructor) |
New Color from an existing `NSColor`. Parameters: `name` - Given color name (`str`). `nsColor` - Optionally, the name of an existing `NSColor` (`str`). Raises: `ColorError` - Invalid `name` or `nsColor`. Overrides: object.__init__ Note: If no `nsColor` is specified, it is assumed to be the value of `name` suffixed with `"Color"`, provided `name` does not end with `"Color"`.

Property Details

### alpha Get the alpha component (`float`) or `None` if not applicable or ignored. Get Method: alpha(self) - Get the alpha component (`float`) or `None` if not applicable or ignored. Set Method: Read_Only(inst, value) - Throws an `AttributeError`, always.

### black Get the black component (`float`) or `None` if not applicable. Get Method: black(self) - Get the black component (`float`) or `None` if not applicable. Set Method: Read_Only(inst, value) - Throws an `AttributeError`, always.

### blue Get the blue component (`float`) or `None` if not applicable. Get Method: blue(self) - Get the blue component (`float`) or `None` if not applicable. Set Method: Read_Only(inst, value) - Throws an `AttributeError`, always.

### brightness Get the brightness component (`float`) or `None` if not applicable. Get Method: brightness(self) - Get the brightness component (`float`) or `None` if not applicable. Set Method: Read_Only(inst, value) - Throws an `AttributeError`, always.

### colorSpace Get the space of this color (`str`). Get Method: colorSpace(self) - Get the space of this color (`str`). Set Method: Read_Only(inst, value) - Throws an `AttributeError`, always.

### cyan Get the cyan component (`float`) or `None` if not applicable. Get Method: cyan(self) - Get the cyan component (`float`) or `None` if not applicable. Set Method: Read_Only(inst, value) - Throws an `AttributeError`, always.

### green Get the green component (`float`) or `None` if not applicable. Get Method: green(self) - Get the green component (`float`) or `None` if not applicable. Set Method: Read_Only(inst, value) - Throws an `AttributeError`, always.

### hex Get the RGB components as hex (`int`) or `None` if not applicable. Get Method: hex(self) - Get the RGB components as hex (`int`) or `None` if not applicable. Set Method: Read_Only(inst, value) - Throws an `AttributeError`, always.

### hue Get the hue component (`float`) or `None` if not applicable. Get Method: hue(self) - Get the hue component (`float`) or `None` if not applicable. Set Method: Read_Only(inst, value) - Throws an `AttributeError`, always.

### magenta Get the magenta component (`float`) or `None` if not applicable. Get Method: magenta(self) - Get the magenta component (`float`) or `None` if not applicable. Set Method: Read_Only(inst, value) - Throws an `AttributeError`, always.

### n Get the number of components of this color (`int`) or `None` if not applicable. Get Method: n(self) - Get the number of components of this color (`int`) or `None` if not applicable. Set Method: Read_Only(inst, value) - Throws an `AttributeError`, always.

### name Get the given name of this color (`str`). Get Method: name(self) - Get the given name of this color (`str`). Set Method: name(self, name) - Set the given name of this color (`str`).

### nsColor Get the name of the `NSColor` of this color (`str`). Get Method: nsColor(self) - Get the name of the `NSColor` of this color (`str`). Set Method: Read_Only(inst, value) - Throws an `AttributeError`, always.

### red Get the red component (`float`) or `None` if not applicable. Get Method: red(self) - Get the red component (`float`) or `None` if not applicable. Set Method: Read_Only(inst, value) - Throws an `AttributeError`, always.

### saturation Get the saturation component (`float`) or `None` if not applicable. Get Method: saturation(self) - Get the saturation component (`float`) or `None` if not applicable. Set Method: Read_Only(inst, value) - Throws an `AttributeError`, always.

### white Get the white component (`float`) or `None` if not applicable. Get Method: white(self) - Get the white component (`float`) or `None` if not applicable. Set Method: Read_Only(inst, value) - Throws an `AttributeError`, always.

### yellow Get the yellow component (`float`) or `None` if not applicable. Get Method: yellow(self) - Get the yellow component (`float`) or `None` if not applicable. Set Method: Read_Only(inst, value) - Throws an `AttributeError`, always.