Override __repr__ and __str__ fields for clutter.Color
Override __repr__ and __str__ fields for clutter.Color

As per the Python Object protocol:

        reprfunc PyTypeObject.tp_repr

  An optional pointer to a function that implements the built-in
  function repr().

  The signature is the same as for PyObject_Repr(); it must return a
  string or a Unicode object. Ideally, this function should return a
  string that, when passed to eval(), given a suitable environment,
  returns an object with the same value. If this is not feasible, it
  should return a string starting with '<' and ending with '>' from
  which both the type and the value of the object can be deduced.

        reprfunc PyTypeObject.tp_str

  An optional pointer to a function that implements the built-in
  operation str(). (Note that str is a type now, and str() calls the
  constructor for that type. This constructor calls PyObject_Str() to
  do the actual work, and PyObject_Str() will call this handler.)

  The signature is the same as for PyObject_Str(); it must return a
  string or a Unicode object. This function should return a “friendly”
  string representation of the object, as this is the representation
  that will be used by the print statement.

                -- Type Object, Python/C API Reference Manual
                   http://docs.python.org/c-api/typeobj.html

The tp_repr() slot implementation should return a string such that:

        >>> c0 = clutter.Color(r,g,b,a)
        >>> c1 = eval(repr(c0))

Produces a new clutter.Color 'c1' instance equivalent to c0. For this
reason, it returns the following string object:

        >>> repr(c0)
        'clutter.Color(red=r,green=g,blue=b,alpha=a)'

The string representation returned by the tp_str() slot is, instead,
equivalent to the to_string() method of clutter.Color, so that calling:

        >>> str(c0)
        '#rrggbbaa'

Where '#rrggbbaa' is the hexadecimal representation of the clutter.Color
channels, and (using the above c0 and c1) this condition holds:

        >>> str(c0) == str(c1)
        True

This should make clutter.Color slightly more pythonic to use.

pmarti/pyclutter,GNOME/pyclutter,pmarti/pyclutter,GNOME/pyclutter,pmarti/pyclutter,pmarti/pyclutter