]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_colour.i
docstring update
[wxWidgets.git] / wxPython / src / _colour.i
CommitLineData
d14a1e28
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: _colour.i
3// Purpose: SWIG interface for wxColour
4//
5// Author: Robin Dunn
6//
7// Created: 7-July-1997
8// RCS-ID: $Id$
9// Copyright: (c) 2003 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13// Not a %module
14
15
16//---------------------------------------------------------------------------
17%newgroup;
18
d14a1e28 19
1d14e183
RD
20enum {
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
24};
25
28cc717d
RD
26enum {
27 wxALPHA_TRANSPARENT,
28 wxALPHA_OPAQUE
29};
30
1d14e183 31
6ad421ae 32DocStr(wxColour,
d07d2bc9
RD
33"A colour is an object representing a combination of Red, Green, and
34Blue (RGB) intensity values, and is used to determine drawing colours,
35window colours, etc. Valid RGB values are in the range 0 to 255.
6ad421ae 36
d07d2bc9 37In wxPython there are typemaps that will automatically convert from a
4617be08
RD
38colour name, from a '#RRGGBB' colour hex value string, or from a 3
39integer tuple to a wx.Colour object when calling C++ methods that
40expect a wxColour. This means that the following are all
41equivallent::
6ad421ae
RD
42
43 win.SetBackgroundColour(wxColour(0,0,255))
2b619822
RD
44 win.SetBackgroundColour('BLUE')
45 win.SetBackgroundColour('#0000FF')
4617be08 46 win.SetBackgroundColour((0,0,255))
6ad421ae 47
d07d2bc9
RD
48Additional colour names and their coresponding values can be added
49using `wx.ColourDatabase`. Various system colours (as set in the
50user's system preferences) can be retrieved with
51`wx.SystemSettings.GetColour`.
52", "");
6ad421ae
RD
53
54
e5156e15
RD
55MustHaveApp( wxColour(const wxString& colorName) );
56
d14a1e28
RD
57class wxColour : public wxObject {
58public:
6ad421ae
RD
59
60 DocCtorStr(
28cc717d 61 wxColour(byte red=0, byte green=0, byte blue=0, byte alpha=wxALPHA_OPAQUE),
d07d2bc9
RD
62 "Constructs a colour from red, green and blue values.
63
64:see: Alternate constructors `wx.NamedColour` and `wx.ColourRGB`.
65", "");
6ad421ae
RD
66
67 DocCtorStrName(
68 wxColour( const wxString& colorName),
d07d2bc9
RD
69 "Constructs a colour object using a colour name listed in
70``wx.TheColourDatabase``.", "",
6ad421ae
RD
71 NamedColour);
72
73 DocCtorStrName(
74 wxColour( unsigned long colRGB ),
d07d2bc9 75 "Constructs a colour from a packed RGB value.", "",
6ad421ae
RD
76 ColourRGB);
77
d14a1e28
RD
78 ~wxColour();
79
6ad421ae
RD
80
81 DocDeclStr(
d07d2bc9
RD
82 byte , Red(),
83 "Returns the red intensity.", "");
6ad421ae
RD
84
85 DocDeclStr(
d07d2bc9
RD
86 byte , Green(),
87 "Returns the green intensity.", "");
6ad421ae
RD
88
89 DocDeclStr(
d07d2bc9
RD
90 byte , Blue(),
91 "Returns the blue intensity.", "");
6ad421ae 92
28cc717d
RD
93 DocDeclStr(
94 byte , Alpha(),
95 "Returns the Alpha value.", "");
96
6ad421ae
RD
97 DocDeclStr(
98 bool , Ok(),
d07d2bc9
RD
99 "Returns True if the colour object is valid (the colour has been
100initialised with RGB values).", "");
6ad421ae
RD
101
102 DocDeclStr(
28cc717d 103 void , Set(byte red, byte green, byte blue, byte alpha=wxALPHA_OPAQUE),
d07d2bc9 104 "Sets the RGB intensity values.", "");
d14a1e28 105
6ad421ae
RD
106 DocDeclStrName(
107 void , Set(unsigned long colRGB),
d07d2bc9 108 "Sets the RGB intensity values from a packed RGB value.", "",
6ad421ae 109 SetRGB);
d14a1e28 110
6ad421ae
RD
111 DocDeclStrName(
112 void , InitFromName(const wxString& colourName),
d07d2bc9
RD
113 "Sets the RGB intensity values using a colour name listed in
114``wx.TheColourDatabase``.", "",
6ad421ae
RD
115 SetFromName);
116
1d14e183
RD
117 DocDeclStr(
118 wxString , GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const,
119 "Return the colour as a string. Acceptable flags are:
120
121 =================== ==================================
122 wx.C2S_NAME return colour name, when possible
123 wx.C2S_CSS_SYNTAX return colour in rgb(r,g,b) syntax
124 wx.C2S_HTML_SYNTAX return colour in #rrggbb syntax
125 =================== ==================================", "");
126
6ad421ae
RD
127
128 DocDeclStr(
129 long , GetPixel() const,
d07d2bc9
RD
130 "Returns a pixel value which is platform-dependent. On Windows, a
131COLORREF is returned. On X, an allocated pixel value is returned. -1
132is returned if the pixel is invalid (on X, unallocated).", "");
6ad421ae
RD
133
134
1fce4e96
RD
135 %extend {
136 KeepGIL(__eq__);
137 DocStr(__eq__, "Compare colours for equality.", "");
138 bool __eq__(PyObject* other) {
139 wxColour temp, *obj = &temp;
140 if ( other == Py_None ) return false;
141 if ( ! wxColour_helper(other, &obj) ) {
142 PyErr_Clear();
143 return false;
144 }
145 return self->operator==(*obj);
146 }
147
148
149 KeepGIL(__ne__);
150 DocStr(__ne__, "Compare colours for inequality.", "");
151 bool __ne__(PyObject* other) {
152 wxColour temp, *obj = &temp;
153 if ( other == Py_None ) return true;
154 if ( ! wxColour_helper(other, &obj)) {
155 PyErr_Clear();
156 return true;
157 }
158 return self->operator!=(*obj);
159 }
160 }
d14a1e28 161
3f0ff538 162
d14a1e28 163 %extend {
c4caf81d 164 KeepGIL(Get);
6ad421ae
RD
165 DocAStr(Get,
166 "Get() -> (r, g, b)",
d07d2bc9 167 "Returns the RGB intensity values as a tuple.", "");
28cc717d
RD
168 PyObject* Get(bool includeAlpha=false) {
169 PyObject* rv = PyTuple_New(includeAlpha ? 4 : 3);
d14a1e28
RD
170 int red = -1;
171 int green = -1;
172 int blue = -1;
28cc717d 173 int alpha = wxALPHA_OPAQUE;
d14a1e28
RD
174 if (self->Ok()) {
175 red = self->Red();
176 green = self->Green();
177 blue = self->Blue();
28cc717d 178 alpha = self->Alpha();
d14a1e28
RD
179 }
180 PyTuple_SetItem(rv, 0, PyInt_FromLong(red));
181 PyTuple_SetItem(rv, 1, PyInt_FromLong(green));
182 PyTuple_SetItem(rv, 2, PyInt_FromLong(blue));
28cc717d
RD
183 if (includeAlpha)
184 PyTuple_SetItem(rv, 3, PyInt_FromLong(alpha));
d14a1e28
RD
185 return rv;
186 }
6ad421ae 187
c4caf81d 188 KeepGIL(GetRGB);
6ad421ae 189 DocStr(GetRGB,
d07d2bc9 190 "Return the colour as a packed RGB value", "");
6ad421ae
RD
191 unsigned long GetRGB() {
192 return self->Red() | (self->Green() << 8) | (self->Blue() << 16);
193 }
d14a1e28
RD
194 }
195
196
197 %pythoncode {
d07d2bc9 198 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
28cc717d
RD
199 def __str__(self): return str(self.Get(True))
200 def __repr__(self): return 'wx.Colour' + str(self.Get(True))
d14a1e28 201 def __nonzero__(self): return self.Ok()
02376d73 202 __safe_for_unpickling__ = True
28cc717d 203 def __reduce__(self): return (Colour, self.Get(True))
d14a1e28 204 }
0eae5d09
RD
205
206 %property(Pixel, GetPixel, doc="See `GetPixel`");
207 %property(RGB, GetRGB, SetRGB, doc="See `GetRGB` and `SetRGB`");
208
d14a1e28
RD
209};
210
2b9048c5
RD
211%pythoncode {
212 Color = Colour
213 NamedColor = NamedColour
214 ColorRGB = ColourRGB
215}
cf763f5b 216
d14a1e28
RD
217//---------------------------------------------------------------------------
218