X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1d14e1836ab0989d5b34ed50ba43e6b67454eb54..170acdc90e9f92f8b8120fa6c04acdbf45c89582:/wxPython/src/_colour.i diff --git a/wxPython/src/_colour.i b/wxPython/src/_colour.i index 20467993dc..23ddd08c3c 100644 --- a/wxPython/src/_colour.i +++ b/wxPython/src/_colour.i @@ -23,6 +23,11 @@ enum { wxC2S_HTML_SYNTAX, // return colour in #rrggbb syntax }; +enum { + wxALPHA_TRANSPARENT, + wxALPHA_OPAQUE +}; + DocStr(wxColour, "A colour is an object representing a combination of Red, Green, and @@ -53,7 +58,7 @@ class wxColour : public wxObject { public: DocCtorStr( - wxColour(byte red=0, byte green=0, byte blue=0), + wxColour(byte red=0, byte green=0, byte blue=0, byte alpha=wxALPHA_OPAQUE), "Constructs a colour from red, green and blue values. :see: Alternate constructors `wx.NamedColour` and `wx.ColourRGB`. @@ -86,12 +91,17 @@ public: "Returns the blue intensity.", ""); DocDeclStr( - bool , Ok(), + byte , Alpha(), + "Returns the Alpha value.", ""); + + DocDeclStr( + bool , IsOk(), "Returns True if the colour object is valid (the colour has been initialised with RGB values).", ""); + %pythoncode { Ok = IsOk } DocDeclStr( - void , Set(byte red, byte green, byte blue), + void , Set(byte red, byte green, byte blue, byte alpha=wxALPHA_OPAQUE), "Sets the RGB intensity values.", ""); DocDeclStrName( @@ -100,11 +110,12 @@ initialised with RGB values).", ""); SetRGB); DocDeclStrName( - void , InitFromName(const wxString& colourName), + void , Set(const wxString& colourName), "Sets the RGB intensity values using a colour name listed in ``wx.TheColourDatabase``.", "", SetFromName); + DocDeclStr( wxString , GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const, "Return the colour as a string. Acceptable flags are: @@ -152,25 +163,31 @@ is returned if the pixel is invalid (on X, unallocated).", ""); %extend { + KeepGIL(Get); DocAStr(Get, "Get() -> (r, g, b)", "Returns the RGB intensity values as a tuple.", ""); - PyObject* Get() { - PyObject* rv = PyTuple_New(3); + PyObject* Get(bool includeAlpha=false) { + PyObject* rv = PyTuple_New(includeAlpha ? 4 : 3); int red = -1; int green = -1; int blue = -1; - if (self->Ok()) { + int alpha = wxALPHA_OPAQUE; + if (self->IsOk()) { red = self->Red(); green = self->Green(); blue = self->Blue(); + alpha = self->Alpha(); } PyTuple_SetItem(rv, 0, PyInt_FromLong(red)); PyTuple_SetItem(rv, 1, PyInt_FromLong(green)); PyTuple_SetItem(rv, 2, PyInt_FromLong(blue)); + if (includeAlpha) + PyTuple_SetItem(rv, 3, PyInt_FromLong(alpha)); return rv; } + KeepGIL(GetRGB); DocStr(GetRGB, "Return the colour as a packed RGB value", ""); unsigned long GetRGB() { @@ -181,12 +198,18 @@ is returned if the pixel is invalid (on X, unallocated).", ""); %pythoncode { asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead") - def __str__(self): return str(self.Get()) - def __repr__(self): return 'wx.Colour' + str(self.Get()) - def __nonzero__(self): return self.Ok() + def __str__(self): return str(self.Get(True)) + def __repr__(self): return 'wx.Colour' + str(self.Get(True)) + def __len__(self): return len(self.Get()) + def __getitem__(self, index): return self.Get()[index] + def __nonzero__(self): return self.IsOk() __safe_for_unpickling__ = True - def __reduce__(self): return (Colour, self.Get()) + def __reduce__(self): return (Colour, self.Get(True)) } + + %property(Pixel, GetPixel, doc="See `GetPixel`"); + %property(RGB, GetRGB, SetRGB, doc="See `GetRGB` and `SetRGB`"); + }; %pythoncode {