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