1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface for wxColour
7 // Created: 7-July-1997
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
21 wxC2S_NAME, // return colour name, when possible
22 wxC2S_CSS_SYNTAX, // return colour in rgb(r,g,b) syntax
23 wxC2S_HTML_SYNTAX, // return colour in #rrggbb syntax
28 "A colour is an object representing a combination of Red, Green, and
29 Blue (RGB) intensity values, and is used to determine drawing colours,
30 window colours, etc. Valid RGB values are in the range 0 to 255.
32 In wxPython there are typemaps that will automatically convert from a
33 colour name, from a '#RRGGBB' colour hex value string, or from a 3
34 integer tuple to a wx.Colour object when calling C++ methods that
35 expect a wxColour. This means that the following are all
38 win.SetBackgroundColour(wxColour(0,0,255))
39 win.SetBackgroundColour('BLUE')
40 win.SetBackgroundColour('#0000FF')
41 win.SetBackgroundColour((0,0,255))
43 Additional colour names and their coresponding values can be added
44 using `wx.ColourDatabase`. Various system colours (as set in the
45 user's system preferences) can be retrieved with
46 `wx.SystemSettings.GetColour`.
50 MustHaveApp( wxColour(const wxString& colorName) );
52 class wxColour : public wxObject {
56 wxColour(byte red=0, byte green=0, byte blue=0),
57 "Constructs a colour from red, green and blue values.
59 :see: Alternate constructors `wx.NamedColour` and `wx.ColourRGB`.
63 wxColour( const wxString& colorName),
64 "Constructs a colour object using a colour name listed in
65 ``wx.TheColourDatabase``.", "",
69 wxColour( unsigned long colRGB ),
70 "Constructs a colour from a packed RGB value.", "",
78 "Returns the red intensity.", "");
82 "Returns the green intensity.", "");
86 "Returns the blue intensity.", "");
90 "Returns True if the colour object is valid (the colour has been
91 initialised with RGB values).", "");
94 void , Set(byte red, byte green, byte blue),
95 "Sets the RGB intensity values.", "");
98 void , Set(unsigned long colRGB),
99 "Sets the RGB intensity values from a packed RGB value.", "",
103 void , InitFromName(const wxString& colourName),
104 "Sets the RGB intensity values using a colour name listed in
105 ``wx.TheColourDatabase``.", "",
109 wxString , GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const,
110 "Return the colour as a string. Acceptable flags are:
112 =================== ==================================
113 wx.C2S_NAME return colour name, when possible
114 wx.C2S_CSS_SYNTAX return colour in rgb(r,g,b) syntax
115 wx.C2S_HTML_SYNTAX return colour in #rrggbb syntax
116 =================== ==================================", "");
120 long , GetPixel() const,
121 "Returns a pixel value which is platform-dependent. On Windows, a
122 COLORREF is returned. On X, an allocated pixel value is returned. -1
123 is returned if the pixel is invalid (on X, unallocated).", "");
128 DocStr(__eq__, "Compare colours for equality.", "");
129 bool __eq__(PyObject* other) {
130 wxColour temp, *obj = &temp;
131 if ( other == Py_None ) return false;
132 if ( ! wxColour_helper(other, &obj) ) {
136 return self->operator==(*obj);
141 DocStr(__ne__, "Compare colours for inequality.", "");
142 bool __ne__(PyObject* other) {
143 wxColour temp, *obj = &temp;
144 if ( other == Py_None ) return true;
145 if ( ! wxColour_helper(other, &obj)) {
149 return self->operator!=(*obj);
156 "Get() -> (r, g, b)",
157 "Returns the RGB intensity values as a tuple.", "");
159 PyObject* rv = PyTuple_New(3);
165 green = self->Green();
168 PyTuple_SetItem(rv, 0, PyInt_FromLong(red));
169 PyTuple_SetItem(rv, 1, PyInt_FromLong(green));
170 PyTuple_SetItem(rv, 2, PyInt_FromLong(blue));
175 "Return the colour as a packed RGB value", "");
176 unsigned long GetRGB() {
177 return self->Red() | (self->Green() << 8) | (self->Blue() << 16);
183 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
184 def __str__(self): return str(self.Get())
185 def __repr__(self): return 'wx.Colour' + str(self.Get())
186 def __nonzero__(self): return self.Ok()
187 __safe_for_unpickling__ = True
188 def __reduce__(self): return (Colour, self.Get())
194 NamedColor = NamedColour
198 //---------------------------------------------------------------------------