]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_colour.i
reSWIGged
[wxWidgets.git] / wxPython / src / _colour.i
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
19
20 DocStr(wxColour,
21 "A colour is an object representing a combination of Red, Green, and
22 Blue (RGB) intensity values, and is used to determine drawing colours,
23 window colours, etc. Valid RGB values are in the range 0 to 255.
24
25 In wxPython there are typemaps that will automatically convert from a
26 colour name, or from a '#RRGGBB' colour hex value string to a
27 wx.Colour object when calling C++ methods that expect a wxColour.
28 This means that the following are all equivallent::
29
30 win.SetBackgroundColour(wxColour(0,0,255))
31 win.SetBackgroundColour('BLUE')
32 win.SetBackgroundColour('#0000FF')
33
34 Additional colour names and their coresponding values can be added
35 using `wx.ColourDatabase`. Various system colours (as set in the
36 user's system preferences) can be retrieved with
37 `wx.SystemSettings.GetColour`.
38 ", "");
39
40
41 class wxColour : public wxObject {
42 public:
43
44 DocCtorStr(
45 wxColour(byte red=0, byte green=0, byte blue=0),
46 "Constructs a colour from red, green and blue values.
47
48 :see: Alternate constructors `wx.NamedColour` and `wx.ColourRGB`.
49 ", "");
50
51 DocCtorStrName(
52 wxColour( const wxString& colorName),
53 "Constructs a colour object using a colour name listed in
54 ``wx.TheColourDatabase``.", "",
55 NamedColour);
56
57 DocCtorStrName(
58 wxColour( unsigned long colRGB ),
59 "Constructs a colour from a packed RGB value.", "",
60 ColourRGB);
61
62 ~wxColour();
63
64
65 DocDeclStr(
66 byte , Red(),
67 "Returns the red intensity.", "");
68
69 DocDeclStr(
70 byte , Green(),
71 "Returns the green intensity.", "");
72
73 DocDeclStr(
74 byte , Blue(),
75 "Returns the blue intensity.", "");
76
77 DocDeclStr(
78 bool , Ok(),
79 "Returns True if the colour object is valid (the colour has been
80 initialised with RGB values).", "");
81
82 DocDeclStr(
83 void , Set(byte red, byte green, byte blue),
84 "Sets the RGB intensity values.", "");
85
86 DocDeclStrName(
87 void , Set(unsigned long colRGB),
88 "Sets the RGB intensity values from a packed RGB value.", "",
89 SetRGB);
90
91 DocDeclStrName(
92 void , InitFromName(const wxString& colourName),
93 "Sets the RGB intensity values using a colour name listed in
94 ``wx.TheColourDatabase``.", "",
95 SetFromName);
96
97
98 DocDeclStr(
99 long , GetPixel() const,
100 "Returns a pixel value which is platform-dependent. On Windows, a
101 COLORREF is returned. On X, an allocated pixel value is returned. -1
102 is returned if the pixel is invalid (on X, unallocated).", "");
103
104
105 DocDeclStr(
106 bool , operator==(const wxColour& colour) const,
107 "Compare colours for equality", "");
108
109 DocDeclStr(
110 bool , operator!=(const wxColour& colour) const,
111 "Compare colours for inequality", "");
112
113
114
115 %extend {
116 DocAStr(Get,
117 "Get() -> (r, g, b)",
118 "Returns the RGB intensity values as a tuple.", "");
119 PyObject* Get() {
120 PyObject* rv = PyTuple_New(3);
121 int red = -1;
122 int green = -1;
123 int blue = -1;
124 if (self->Ok()) {
125 red = self->Red();
126 green = self->Green();
127 blue = self->Blue();
128 }
129 PyTuple_SetItem(rv, 0, PyInt_FromLong(red));
130 PyTuple_SetItem(rv, 1, PyInt_FromLong(green));
131 PyTuple_SetItem(rv, 2, PyInt_FromLong(blue));
132 return rv;
133 }
134
135 DocStr(GetRGB,
136 "Return the colour as a packed RGB value", "");
137 unsigned long GetRGB() {
138 return self->Red() | (self->Green() << 8) | (self->Blue() << 16);
139 }
140 }
141
142
143 %pythoncode {
144 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
145 def __str__(self): return str(self.Get())
146 def __repr__(self): return 'wx.Colour' + str(self.Get())
147 def __nonzero__(self): return self.Ok()
148 __safe_for_unpickling__ = True
149 def __reduce__(self): return (Colour, self.Get())
150 }
151 };
152
153 %pythoncode {
154 Color = Colour
155 NamedColor = NamedColour
156 ColorRGB = ColourRGB
157 }
158
159 //---------------------------------------------------------------------------
160