]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _artprov.i | |
3 | // Purpose: SWIG interface stuff for wxArtProvider | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 18-June-1999 | |
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 | #include <wx/artprov.h> | |
21 | %} | |
22 | ||
23 | //--------------------------------------------------------------------------- | |
24 | ||
25 | ||
26 | // Art clients | |
27 | MAKE_CONST_WXSTRING(ART_TOOLBAR); | |
28 | MAKE_CONST_WXSTRING(ART_MENU); | |
29 | MAKE_CONST_WXSTRING(ART_FRAME_ICON); | |
30 | MAKE_CONST_WXSTRING(ART_CMN_DIALOG); | |
31 | MAKE_CONST_WXSTRING(ART_HELP_BROWSER); | |
32 | MAKE_CONST_WXSTRING(ART_MESSAGE_BOX); | |
33 | MAKE_CONST_WXSTRING(ART_OTHER); | |
34 | ||
35 | // Art IDs | |
36 | MAKE_CONST_WXSTRING(ART_ADD_BOOKMARK); | |
37 | MAKE_CONST_WXSTRING(ART_DEL_BOOKMARK); | |
38 | MAKE_CONST_WXSTRING(ART_HELP_SIDE_PANEL); | |
39 | MAKE_CONST_WXSTRING(ART_HELP_SETTINGS); | |
40 | MAKE_CONST_WXSTRING(ART_HELP_BOOK); | |
41 | MAKE_CONST_WXSTRING(ART_HELP_FOLDER); | |
42 | MAKE_CONST_WXSTRING(ART_HELP_PAGE); | |
43 | MAKE_CONST_WXSTRING(ART_GO_BACK); | |
44 | MAKE_CONST_WXSTRING(ART_GO_FORWARD); | |
45 | MAKE_CONST_WXSTRING(ART_GO_UP); | |
46 | MAKE_CONST_WXSTRING(ART_GO_DOWN); | |
47 | MAKE_CONST_WXSTRING(ART_GO_TO_PARENT); | |
48 | MAKE_CONST_WXSTRING(ART_GO_HOME); | |
49 | MAKE_CONST_WXSTRING(ART_FILE_OPEN); | |
50 | MAKE_CONST_WXSTRING(ART_PRINT); | |
51 | MAKE_CONST_WXSTRING(ART_HELP); | |
52 | MAKE_CONST_WXSTRING(ART_TIP); | |
53 | MAKE_CONST_WXSTRING(ART_REPORT_VIEW); | |
54 | MAKE_CONST_WXSTRING(ART_LIST_VIEW); | |
55 | MAKE_CONST_WXSTRING(ART_NEW_DIR); | |
56 | MAKE_CONST_WXSTRING(ART_FOLDER); | |
57 | MAKE_CONST_WXSTRING(ART_GO_DIR_UP); | |
58 | MAKE_CONST_WXSTRING(ART_EXECUTABLE_FILE); | |
59 | MAKE_CONST_WXSTRING(ART_NORMAL_FILE); | |
60 | MAKE_CONST_WXSTRING(ART_TICK_MARK); | |
61 | MAKE_CONST_WXSTRING(ART_CROSS_MARK); | |
62 | MAKE_CONST_WXSTRING(ART_ERROR); | |
63 | MAKE_CONST_WXSTRING(ART_QUESTION); | |
64 | MAKE_CONST_WXSTRING(ART_WARNING); | |
65 | MAKE_CONST_WXSTRING(ART_INFORMATION); | |
66 | MAKE_CONST_WXSTRING(ART_MISSING_IMAGE); | |
67 | ||
68 | //--------------------------------------------------------------------------- | |
69 | ||
70 | %{ // Python aware wxArtProvider | |
71 | class wxPyArtProvider : public wxArtProvider { | |
72 | public: | |
73 | ||
74 | virtual wxBitmap CreateBitmap(const wxArtID& id, | |
75 | const wxArtClient& client, | |
76 | const wxSize& size) { | |
77 | wxBitmap rval = wxNullBitmap; | |
da32eb53 | 78 | bool blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
79 | if ((wxPyCBH_findCallback(m_myInst, "CreateBitmap"))) { |
80 | PyObject* so = wxPyConstructObject((void*)&size, wxT("wxSize"), 0); | |
81 | PyObject* ro; | |
82 | wxBitmap* ptr; | |
83 | PyObject* s1, *s2; | |
84 | s1 = wx2PyString(id); | |
85 | s2 = wx2PyString(client); | |
86 | ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("(OOO)", s1, s2, so)); | |
87 | Py_DECREF(so); | |
88 | Py_DECREF(s1); | |
89 | Py_DECREF(s2); | |
90 | if (ro) { | |
91 | if (wxPyConvertSwigPtr(ro, (void**)&ptr, wxT("wxBitmap"))) | |
92 | rval = *ptr; | |
93 | Py_DECREF(ro); | |
94 | } | |
95 | } | |
da32eb53 | 96 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
97 | return rval; |
98 | } | |
99 | ||
100 | PYPRIVATE; | |
101 | }; | |
102 | %} | |
103 | ||
104 | // The one for SWIG to see | |
dce2bd22 RD |
105 | |
106 | ||
107 | ||
108 | DocStr(wxPyArtProvider, | |
109 | "The wx.ArtProvider class is used to customize the look of wxWidgets | |
110 | application. When wxWidgets needs to display an icon or a bitmap (e.g. | |
111 | in the standard file dialog), it does not use hard-coded resource but | |
112 | asks wx.ArtProvider for it instead. This way the users can plug in | |
113 | their own wx.ArtProvider class and easily replace standard art with | |
114 | his/her own version. It is easy thing to do: all that is needed is | |
115 | to derive a class from wx.ArtProvider, override it's CreateBitmap | |
116 | method and register the provider with wx.ArtProvider.PushProvider:: | |
117 | ||
118 | class MyArtProvider(wx.ArtProvider): | |
119 | def __init__(self): | |
120 | wx.ArtProvider.__init__(self) | |
121 | ||
122 | def CreateBitmap(self, artid, client, size): | |
123 | ... | |
124 | return bmp | |
d07d2bc9 | 125 | ", " |
dce2bd22 RD |
126 | |
127 | Identifying art resources | |
128 | ------------------------- | |
129 | ||
130 | Every bitmap is known to wx.ArtProvider under an unique ID that is | |
131 | used when requesting a resource from it. The IDs can have one of these | |
132 | predefined values: | |
133 | ||
134 | * wx.ART_ADD_BOOKMARK | |
135 | * wx.ART_DEL_BOOKMARK | |
136 | * wx.ART_HELP_SIDE_PANEL | |
137 | * wx.ART_HELP_SETTINGS | |
138 | * wx.ART_HELP_BOOK | |
139 | * wx.ART_HELP_FOLDER | |
140 | * wx.ART_HELP_PAGE | |
141 | * wx.ART_GO_BACK | |
142 | * wx.ART_GO_FORWARD | |
143 | * wx.ART_GO_UP | |
144 | * wx.ART_GO_DOWN | |
145 | * wx.ART_GO_TO_PARENT | |
146 | * wx.ART_GO_HOME | |
147 | * wx.ART_FILE_OPEN | |
148 | * wx.ART_PRINT | |
149 | * wx.ART_HELP | |
150 | * wx.ART_TIP | |
151 | * wx.ART_REPORT_VIEW | |
152 | * wx.ART_LIST_VIEW | |
153 | * wx.ART_NEW_DIR | |
154 | * wx.ART_FOLDER | |
155 | * wx.ART_GO_DIR_UP | |
156 | * wx.ART_EXECUTABLE_FILE | |
157 | * wx.ART_NORMAL_FILE | |
158 | * wx.ART_TICK_MARK | |
159 | * wx.ART_CROSS_MARK | |
160 | * wx.ART_ERROR | |
161 | * wx.ART_QUESTION | |
162 | * wx.ART_WARNING | |
163 | * wx.ART_INFORMATION | |
164 | * wx.ART_MISSING_IMAGE | |
165 | ||
166 | ||
167 | Clients | |
168 | ------- | |
169 | ||
170 | The Client is the entity that calls wx.ArtProvider's `GetBitmap` or | |
171 | `GetIcon` function. Client IDs server as a hint to wx.ArtProvider | |
172 | that is supposed to help it to choose the best looking bitmap. For | |
173 | example it is often desirable to use slightly different icons in menus | |
174 | and toolbars even though they represent the same action (e.g. | |
175 | wx.ART_FILE_OPEN). Remember that this is really only a hint for | |
176 | wx.ArtProvider -- it is common that `wx.ArtProvider.GetBitmap` returns | |
177 | identical bitmap for different client values! | |
178 | ||
179 | * wx.ART_TOOLBAR | |
180 | * wx.ART_MENU | |
181 | * wx.ART_FRAME_ICON | |
182 | * wx.ART_CMN_DIALOG | |
183 | * wx.ART_HELP_BROWSER | |
184 | * wx.ART_MESSAGE_BOX | |
185 | * wx.ART_OTHER (used for all requests that don't fit into any | |
186 | of the categories above) | |
187 | "); | |
188 | ||
ab1f7d2a RD |
189 | MustHaveApp(wxPyArtProvider); |
190 | MustHaveApp(wxPyArtProvider::GetBitmap); | |
191 | MustHaveApp(wxPyArtProvider::GetIcon); | |
192 | ||
d14a1e28 RD |
193 | %name(ArtProvider) class wxPyArtProvider /*: public wxObject*/ |
194 | { | |
195 | public: | |
196 | ||
2b9048c5 | 197 | %pythonAppend wxPyArtProvider "self._setCallbackInfo(self, ArtProvider)" |
d14a1e28 | 198 | wxPyArtProvider(); |
d14a1e28 RD |
199 | |
200 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
201 | ||
dce2bd22 RD |
202 | DocDeclStr( |
203 | static void , PushProvider(wxPyArtProvider *provider), | |
d07d2bc9 | 204 | "Add new provider to the top of providers stack.", ""); |
dce2bd22 | 205 | |
d14a1e28 | 206 | |
dce2bd22 RD |
207 | DocDeclStr( |
208 | static bool , PopProvider(), | |
d07d2bc9 | 209 | "Remove latest added provider and delete it.", ""); |
dce2bd22 | 210 | |
d14a1e28 | 211 | |
dce2bd22 RD |
212 | DocDeclStr( |
213 | static bool , RemoveProvider(wxPyArtProvider *provider), | |
214 | "Remove provider. The provider must have been added previously! The | |
d07d2bc9 | 215 | provider is _not_ deleted.", ""); |
dce2bd22 | 216 | |
d14a1e28 | 217 | |
dce2bd22 RD |
218 | DocDeclStr( |
219 | static wxBitmap , GetBitmap(const wxString& id, | |
220 | const wxString& client = wxPyART_OTHER, | |
221 | const wxSize& size = wxDefaultSize), | |
222 | "Query the providers for bitmap with given ID and return it. Return | |
d07d2bc9 | 223 | wx.NullBitmap if no provider provides it.", ""); |
dce2bd22 | 224 | |
d14a1e28 | 225 | |
dce2bd22 RD |
226 | DocDeclStr( |
227 | static wxIcon , GetIcon(const wxString& id, | |
d14a1e28 | 228 | const wxString& client = wxPyART_OTHER, |
dce2bd22 RD |
229 | const wxSize& size = wxDefaultSize), |
230 | "Query the providers for icon with given ID and return it. Return | |
d07d2bc9 | 231 | wx.NullIcon if no provider provides it.", ""); |
dce2bd22 | 232 | |
d14a1e28 | 233 | |
1e0c8722 | 234 | %extend { void Destroy() { delete self; }} |
d14a1e28 RD |
235 | }; |
236 | ||
237 | ||
238 | ||
239 | //--------------------------------------------------------------------------- | |
240 | %init %{ | |
241 | wxPyPtrTypeMap_Add("wxArtProvider", "wxPyArtProvider"); | |
242 | %} | |
243 | //--------------------------------------------------------------------------- |