]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _pen.i | |
3 | // Purpose: SWIG interface for wxPen | |
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 | ||
18 | // wxDash is a signed char, byte is unsigned char... | |
19 | %typemap(in) (int dashes, wxDash* dashes_array ) { | |
20 | $1 = PyList_Size($input); | |
21 | $2 = (wxDash*)byte_LIST_helper($input); | |
22 | if ($2 == NULL) SWIG_fail; | |
23 | } | |
24 | %typemap(freearg) (int dashes, wxDash* dashes_array ) { | |
25 | if ($2) delete [] $2; | |
26 | } | |
27 | ||
28 | //--------------------------------------------------------------------------- | |
29 | %newgroup | |
30 | ||
31 | ||
ab1f7d2a RD |
32 | MustHaveApp(wxPen); |
33 | ||
d14a1e28 RD |
34 | class wxPen : public wxGDIObject { |
35 | public: | |
36 | wxPen(wxColour& colour, int width=1, int style=wxSOLID); | |
37 | ~wxPen(); | |
38 | ||
39 | int GetCap(); | |
40 | wxColour GetColour(); | |
41 | int GetJoin(); | |
42 | int GetStyle(); | |
43 | int GetWidth(); | |
44 | ||
45 | bool Ok(); | |
46 | ||
47 | void SetCap(int cap_style); | |
48 | void SetColour(wxColour& colour); | |
49 | void SetJoin(int join_style); | |
50 | void SetStyle(int style); | |
51 | void SetWidth(int width); | |
52 | ||
53 | void SetDashes(int dashes, wxDash* dashes_array); | |
54 | //int GetDashes(wxDash **dashes); | |
55 | %extend { | |
56 | PyObject* GetDashes() { | |
57 | wxDash* dashes; | |
58 | int count = self->GetDashes(&dashes); | |
6e6b3557 | 59 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
d14a1e28 | 60 | PyObject* retval = PyList_New(0); |
ad411ab2 RD |
61 | for (int x=0; x<count; x++) { |
62 | PyObject* pyint = PyInt_FromLong(dashes[x]); | |
63 | PyList_Append(retval, pyint); | |
64 | Py_DECREF(pyint); | |
65 | } | |
da32eb53 | 66 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
67 | return retval; |
68 | } | |
9e4e25d5 RD |
69 | |
70 | void _SetDashes(PyObject* _self, PyObject* pyDashes) { | |
6e6b3557 | 71 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); |
9e4e25d5 RD |
72 | int size = PyList_Size(pyDashes); |
73 | wxDash* dashes = (wxDash*)byte_LIST_helper(pyDashes); | |
74 | ||
75 | // black magic warning! The array of wxDashes needs to exist as | |
76 | // long as the pen does because wxPen does not copy the array. So | |
77 | // stick a copy in a Python string object and attach it to _self, | |
78 | // and then call SetDashes with a pointer to that array. Then | |
79 | // when the Python pen object is destroyed the array will be | |
80 | // cleaned up too. | |
81 | PyObject* strDashes = PyString_FromStringAndSize((char*)dashes, size*sizeof(wxDash)); | |
82 | PyObject_SetAttrString(_self, "_dashes", strDashes); | |
83 | ||
84 | self->SetDashes(size, (wxDash*)PyString_AS_STRING(strDashes)); | |
85 | delete [] dashes; | |
86 | Py_DECREF(strDashes); | |
87 | wxPyEndBlockThreads(blocked); | |
88 | } | |
d14a1e28 | 89 | } |
9e4e25d5 RD |
90 | %pythoncode { |
91 | def SetDashes(self, dashes): | |
92 | """ | |
93 | Associate a list of dash lengths with the Pen. | |
94 | """ | |
95 | self._SetDashes(self, dashes) | |
22faec7d | 96 | } |
d14a1e28 | 97 | |
9e4e25d5 | 98 | |
9fd4be55 | 99 | #ifndef __WXMAC__ |
3f0ff538 | 100 | int GetDashCount() const; |
9c21b187 | 101 | %property(DashCount, GetDashCount, doc="See `GetDashCount`"); |
9fd4be55 RD |
102 | #endif |
103 | ||
d14a1e28 RD |
104 | #ifdef __WXMSW__ |
105 | wxBitmap* GetStipple(); | |
106 | void SetStipple(wxBitmap& stipple); | |
9c21b187 | 107 | %property(Stipple, GetStipple, SetStipple, doc="See `GetStipple` and `SetStipple`"); |
d14a1e28 RD |
108 | #endif |
109 | ||
9e4e25d5 RD |
110 | |
111 | %extend { | |
a72f4631 RD |
112 | bool __eq__(const wxPen* other) { return other ? (*self == *other) : false; } |
113 | bool __ne__(const wxPen* other) { return other ? (*self != *other) : true; } | |
d14a1e28 | 114 | } |
9e4e25d5 | 115 | %pythoncode { def __nonzero__(self): return self.Ok() } |
7012bb9f RD |
116 | |
117 | %property(Cap, GetCap, SetCap, doc="See `GetCap` and `SetCap`"); | |
118 | %property(Colour, GetColour, SetColour, doc="See `GetColour` and `SetColour`"); | |
7012bb9f RD |
119 | %property(Dashes, GetDashes, SetDashes, doc="See `GetDashes` and `SetDashes`"); |
120 | %property(Join, GetJoin, SetJoin, doc="See `GetJoin` and `SetJoin`"); | |
121 | %property(Style, GetStyle, SetStyle, doc="See `GetStyle` and `SetStyle`"); | |
122 | %property(Width, GetWidth, SetWidth, doc="See `GetWidth` and `SetWidth`"); | |
d14a1e28 RD |
123 | }; |
124 | ||
d14a1e28 RD |
125 | |
126 | //--------------------------------------------------------------------------- |