]>
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 | ||
32 | class wxPen : public wxGDIObject { | |
33 | public: | |
34 | wxPen(wxColour& colour, int width=1, int style=wxSOLID); | |
35 | ~wxPen(); | |
36 | ||
37 | int GetCap(); | |
38 | wxColour GetColour(); | |
39 | int GetJoin(); | |
40 | int GetStyle(); | |
41 | int GetWidth(); | |
42 | ||
43 | bool Ok(); | |
44 | ||
45 | void SetCap(int cap_style); | |
46 | void SetColour(wxColour& colour); | |
47 | void SetJoin(int join_style); | |
48 | void SetStyle(int style); | |
49 | void SetWidth(int width); | |
50 | ||
51 | void SetDashes(int dashes, wxDash* dashes_array); | |
52 | //int GetDashes(wxDash **dashes); | |
53 | %extend { | |
54 | PyObject* GetDashes() { | |
55 | wxDash* dashes; | |
56 | int count = self->GetDashes(&dashes); | |
da32eb53 | 57 | bool blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
58 | PyObject* retval = PyList_New(0); |
59 | for (int x=0; x<count; x++) | |
60 | PyList_Append(retval, PyInt_FromLong(dashes[x])); | |
da32eb53 | 61 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
62 | return retval; |
63 | } | |
9e4e25d5 RD |
64 | |
65 | void _SetDashes(PyObject* _self, PyObject* pyDashes) { | |
66 | bool blocked = wxPyBeginBlockThreads(); | |
67 | int size = PyList_Size(pyDashes); | |
68 | wxDash* dashes = (wxDash*)byte_LIST_helper(pyDashes); | |
69 | ||
70 | // black magic warning! The array of wxDashes needs to exist as | |
71 | // long as the pen does because wxPen does not copy the array. So | |
72 | // stick a copy in a Python string object and attach it to _self, | |
73 | // and then call SetDashes with a pointer to that array. Then | |
74 | // when the Python pen object is destroyed the array will be | |
75 | // cleaned up too. | |
76 | PyObject* strDashes = PyString_FromStringAndSize((char*)dashes, size*sizeof(wxDash)); | |
77 | PyObject_SetAttrString(_self, "_dashes", strDashes); | |
78 | ||
79 | self->SetDashes(size, (wxDash*)PyString_AS_STRING(strDashes)); | |
80 | delete [] dashes; | |
81 | Py_DECREF(strDashes); | |
82 | wxPyEndBlockThreads(blocked); | |
83 | } | |
d14a1e28 | 84 | } |
9e4e25d5 RD |
85 | %pythoncode { |
86 | def SetDashes(self, dashes): | |
87 | """ | |
88 | Associate a list of dash lengths with the Pen. | |
89 | """ | |
90 | self._SetDashes(self, dashes) | |
22faec7d | 91 | } |
d14a1e28 | 92 | |
9e4e25d5 | 93 | |
9fd4be55 | 94 | #ifndef __WXMAC__ |
3f0ff538 | 95 | int GetDashCount() const; |
9fd4be55 RD |
96 | #endif |
97 | ||
d14a1e28 RD |
98 | #ifdef __WXMSW__ |
99 | wxBitmap* GetStipple(); | |
100 | void SetStipple(wxBitmap& stipple); | |
101 | #endif | |
102 | ||
9e4e25d5 RD |
103 | |
104 | %extend { | |
105 | bool __eq__(const wxPen* other) { return other ? (*self == *other) : False; } | |
106 | bool __ne__(const wxPen* other) { return other ? (*self != *other) : True; } | |
d14a1e28 | 107 | } |
9e4e25d5 | 108 | %pythoncode { def __nonzero__(self): return self.Ok() } |
d14a1e28 RD |
109 | }; |
110 | ||
d14a1e28 RD |
111 | |
112 | //--------------------------------------------------------------------------- |