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