]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: _picker.i | |
3 | // Purpose: SWIG interface for Colour, Dir, File, Font picker controls | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 6-June-2006 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2006 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
16 | //--------------------------------------------------------------------------- | |
17 | %newgroup | |
18 | ||
19 | enum { | |
20 | wxPB_USE_TEXTCTRL, | |
21 | }; | |
22 | ||
23 | ||
24 | DocStr(wxPickerBase, | |
25 | "Base abstract class for all pickers which support an auxiliary text | |
26 | control. This class handles all positioning and sizing of the text | |
27 | control like a an horizontal `wx.BoxSizer` would do, with the text | |
28 | control on the left of the picker button and the proportion of the | |
29 | picker fixed to value 1.", ""); | |
30 | ||
31 | class wxPickerBase : public wxControl | |
32 | { | |
33 | public: | |
34 | // This class is an ABC, can't be instantiated from Python. | |
35 | //wxPickerBase() : m_text(NULL), m_picker(NULL), | |
36 | // m_margin(5), m_textProportion(2) {} | |
37 | //virtual ~wxPickerBase(); | |
38 | ||
39 | ||
40 | // if present, intercepts wxPB_USE_TEXTCTRL style and creates the text control | |
41 | // The 3rd argument is the initial wxString to display in the text control | |
42 | bool CreateBase(wxWindow *parent, wxWindowID id, | |
43 | const wxString& text = wxEmptyString, | |
44 | const wxPoint& pos = wxDefaultPosition, | |
45 | const wxSize& size = wxDefaultSize, long style = 0, | |
46 | const wxValidator& validator = wxDefaultValidator, | |
47 | const wxString& name = wxButtonNameStr); | |
48 | ||
49 | ||
50 | ||
51 | DocDeclStr( | |
52 | void , SetInternalMargin(int newmargin), | |
53 | "Sets the margin (in pixels) between the picker and the text control.", ""); | |
54 | ||
55 | DocDeclStr( | |
56 | int , GetInternalMargin() const, | |
57 | "Returns the margin (in pixels) between the picker and the text | |
58 | control.", ""); | |
59 | ||
60 | ||
61 | DocDeclStr( | |
62 | void , SetTextCtrlProportion(int prop), | |
63 | "Sets the proportion between the text control and the picker button. | |
64 | This is used to set relative sizes of the text contorl and the picker. | |
65 | The value passed to this function must be >= 1.", ""); | |
66 | ||
67 | DocDeclStr( | |
68 | int , GetTextCtrlProportion() const, | |
69 | "Returns the proportion between the text control and the picker.", ""); | |
70 | ||
71 | ||
72 | DocDeclStr( | |
73 | void , SetPickerCtrlProportion(int prop), | |
74 | "Sets the proportion value of the picker.", ""); | |
75 | ||
76 | DocDeclStr( | |
77 | int , GetPickerCtrlProportion() const, | |
78 | "Gets the proportion value of the picker.", ""); | |
79 | ||
80 | ||
81 | DocDeclStr( | |
82 | bool , IsTextCtrlGrowable() const, | |
83 | "", ""); | |
84 | ||
85 | DocDeclStr( | |
86 | void , SetTextCtrlGrowable(bool grow = true), | |
87 | "", ""); | |
88 | ||
89 | ||
90 | DocDeclStr( | |
91 | bool , IsPickerCtrlGrowable() const, | |
92 | "", ""); | |
93 | ||
94 | DocDeclStr( | |
95 | void , SetPickerCtrlGrowable(bool grow = true), | |
96 | "", ""); | |
97 | ||
98 | ||
99 | DocDeclStr( | |
100 | bool , HasTextCtrl() const, | |
101 | "Returns true if this class has a valid text control (i.e. if the | |
102 | wx.PB_USE_TEXTCTRL style was given when creating this control).", ""); | |
103 | ||
104 | DocDeclStr( | |
105 | wxTextCtrl *, GetTextCtrl(), | |
106 | "Returns a pointer to the text control handled by this class or None if | |
107 | the wx.PB_USE_TEXTCTRL style was not specified when this control was | |
108 | created. | |
109 | ||
110 | Very important: the contents of the text control could be containing | |
111 | an invalid representation of the entity which can be chosen through | |
112 | the picker (e.g. the user entered an invalid colour syntax because of | |
113 | a typo). Thus you should never parse the content of the textctrl to | |
114 | get the user's input; rather use the derived-class getter | |
115 | (e.g. `wx.ColourPickerCtrl.GetColour`, `wx.FilePickerCtrl.GetPath`, | |
116 | etc).", ""); | |
117 | ||
118 | DocDeclStr( | |
119 | wxControl *, GetPickerCtrl(), | |
120 | "", ""); | |
121 | ||
122 | ||
123 | %property(InternalMargin, GetInternalMargin, SetInternalMargin, doc="See `GetInternalMargin` and `SetInternalMargin`"); | |
124 | %property(PickerCtrl, GetPickerCtrl, doc="See `GetPickerCtrl`"); | |
125 | %property(PickerCtrlProportion, GetPickerCtrlProportion, SetPickerCtrlProportion, doc="See `GetPickerCtrlProportion` and `SetPickerCtrlProportion`"); | |
126 | %property(TextCtrl, GetTextCtrl, doc="See `GetTextCtrl`"); | |
127 | %property(TextCtrlProportion, GetTextCtrlProportion, SetTextCtrlProportion, doc="See `GetTextCtrlProportion` and `SetTextCtrlProportion`"); | |
128 | ||
129 | %property(TextCtrlGrowable, IsTextCtrlGrowable, SetTextCtrlGrowable, doc="See `IsTextCtrlGrowable` and `SetTextCtrlGrowable`"); | |
130 | %property(PickerCtrlGrowable, IsPickerCtrlGrowable, SetPickerCtrlGrowable, doc="See `IsPickerCtrlGrowable` and `SetPickerCtrlGrowable`"); | |
131 | ||
132 | }; | |
133 | ||
134 | //--------------------------------------------------------------------------- | |
135 | %newgroup | |
136 | ||
137 | MAKE_CONST_WXSTRING(ColourPickerCtrlNameStr); | |
138 | ||
139 | enum { | |
140 | wxCLRP_SHOW_LABEL, | |
141 | wxCLRP_USE_TEXTCTRL, | |
142 | wxCLRP_DEFAULT_STYLE, | |
143 | }; | |
144 | ||
145 | ||
146 | MustHaveApp(wxColourPickerCtrl); | |
147 | DocStr(wxColourPickerCtrl, | |
148 | "This control allows the user to select a colour. The generic | |
149 | implementation is a button which brings up a `wx.ColourDialog` when | |
150 | clicked. Native implementations may differ but this is usually a | |
151 | (small) widget which give access to the colour-chooser dialog.", | |
152 | ||
153 | " | |
154 | Window Styles | |
155 | ------------- | |
156 | ||
157 | ====================== ============================================ | |
158 | wx.CLRP_DEFAULT Default style. | |
159 | wx.CLRP_USE_TEXTCTRL Creates a text control to the left of the | |
160 | picker button which is completely managed | |
161 | by the `wx.ColourPickerCtrl` and which can | |
162 | be used by the user to specify a colour. | |
163 | The text control is automatically synchronized | |
164 | with the button's value. Use functions defined in | |
165 | `wx.PickerBase` to modify the text control. | |
166 | wx.CLRP_SHOW_LABEL Shows the colour in HTML form (AABBCC) as the | |
167 | colour button label (instead of no label at all). | |
168 | ====================== ============================================ | |
169 | ||
170 | Events | |
171 | ------ | |
172 | ||
173 | ======================== ========================================== | |
174 | EVT_COLOURPICKER_CHANGED The user changed the colour selected in the | |
175 | control either using the button or using the | |
176 | text control (see wx.CLRP_USE_TEXTCTRL; note | |
177 | that in this case the event is fired only if | |
178 | the user's input is valid, i.e. recognizable). | |
179 | ======================== ========================================== | |
180 | "); | |
181 | ||
182 | class wxColourPickerCtrl : public wxPickerBase | |
183 | { | |
184 | public: | |
185 | %pythonAppend wxColourPickerCtrl "self._setOORInfo(self)" | |
186 | %pythonAppend wxColourPickerCtrl() "" | |
187 | ||
188 | wxColourPickerCtrl(wxWindow *parent, wxWindowID id=-1, | |
189 | const wxColour& col = *wxBLACK, | |
190 | const wxPoint& pos = wxDefaultPosition, | |
191 | const wxSize& size = wxDefaultSize, | |
192 | long style = wxCLRP_DEFAULT_STYLE, | |
193 | const wxValidator& validator = wxDefaultValidator, | |
194 | const wxString& name = wxPyColourPickerCtrlNameStr); | |
195 | %RenameCtor(PreColourPickerCtrl, wxColourPickerCtrl()); | |
196 | ||
197 | bool Create(wxWindow *parent, wxWindowID id, | |
198 | const wxColour& col = *wxBLACK, | |
199 | const wxPoint& pos = wxDefaultPosition, | |
200 | const wxSize& size = wxDefaultSize, | |
201 | long style = wxCLRP_DEFAULT_STYLE, | |
202 | const wxValidator& validator = wxDefaultValidator, | |
203 | const wxString& name = wxPyColourPickerCtrlNameStr); | |
204 | ||
205 | ||
206 | DocDeclStr( | |
207 | wxColour , GetColour() const, | |
208 | "Returns the currently selected colour.", ""); | |
209 | ||
210 | ||
211 | DocDeclStr( | |
212 | void , SetColour(const wxColour& col), | |
213 | "Set the displayed colour.", ""); | |
214 | ||
215 | %property(Colour, GetColour, SetColour, doc="See `GetColour` and `SetColour`"); | |
216 | }; | |
217 | ||
218 | ||
219 | ||
220 | %constant wxEventType wxEVT_COMMAND_COLOURPICKER_CHANGED; | |
221 | %pythoncode { | |
222 | EVT_COLOURPICKER_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_COLOURPICKER_CHANGED, 1 ) | |
223 | } | |
224 | ||
225 | class wxColourPickerEvent : public wxCommandEvent | |
226 | { | |
227 | public: | |
228 | wxColourPickerEvent(wxObject *generator, int id, const wxColour &col); | |
229 | ||
230 | wxColour GetColour() const; | |
231 | void SetColour(const wxColour &c); | |
232 | ||
233 | %property(Colour, GetColour, SetColour, doc="See `GetColour` and `SetColour`"); | |
234 | }; | |
235 | ||
236 | ||
237 | //--------------------------------------------------------------------------- | |
238 | %newgroup | |
239 | ||
240 | MAKE_CONST_WXSTRING(FilePickerCtrlNameStr); | |
241 | MAKE_CONST_WXSTRING(FileSelectorPromptStr); | |
242 | MAKE_CONST_WXSTRING(DirPickerCtrlNameStr); | |
243 | MAKE_CONST_WXSTRING(DirSelectorPromptStr); | |
244 | MAKE_CONST_WXSTRING(FileSelectorDefaultWildcardStr); | |
245 | ||
246 | ||
247 | enum { | |
248 | wxFLP_OPEN, | |
249 | wxFLP_SAVE, | |
250 | wxFLP_OVERWRITE_PROMPT, | |
251 | wxFLP_FILE_MUST_EXIST, | |
252 | wxFLP_CHANGE_DIR, | |
253 | wxDIRP_DIR_MUST_EXIST, | |
254 | wxDIRP_CHANGE_DIR, | |
255 | ||
256 | wxFLP_USE_TEXTCTRL, | |
257 | wxFLP_DEFAULT_STYLE, | |
258 | ||
259 | wxDIRP_USE_TEXTCTRL, | |
260 | wxDIRP_DEFAULT_STYLE, | |
261 | }; | |
262 | ||
263 | ||
264 | ||
265 | MustHaveApp(wxFilePickerCtrl); | |
266 | DocStr(wxFilePickerCtrl, | |
267 | "", ""); | |
268 | ||
269 | class wxFilePickerCtrl : public wxPickerBase | |
270 | { | |
271 | public: | |
272 | %pythonAppend wxFilePickerCtrl "self._setOORInfo(self)" | |
273 | %pythonAppend wxFilePickerCtrl() "" | |
274 | ||
275 | wxFilePickerCtrl(wxWindow *parent, | |
276 | wxWindowID id=-1, | |
277 | const wxString& path = wxPyEmptyString, | |
278 | const wxString& message = wxPyFileSelectorPromptStr, | |
279 | const wxString& wildcard = wxPyFileSelectorDefaultWildcardStr, | |
280 | const wxPoint& pos = wxDefaultPosition, | |
281 | const wxSize& size = wxDefaultSize, | |
282 | long style = wxFLP_DEFAULT_STYLE, | |
283 | const wxValidator& validator = wxDefaultValidator, | |
284 | const wxString& name = wxPyFilePickerCtrlNameStr); | |
285 | %RenameCtor(PreFilePickerCtrl, wxFilePickerCtrl()); | |
286 | ||
287 | bool Create(wxWindow *parent, | |
288 | wxWindowID id=-1, | |
289 | const wxString& path = wxPyEmptyString, | |
290 | const wxString& message = wxPyFileSelectorPromptStr, | |
291 | const wxString& wildcard = wxPyFileSelectorDefaultWildcardStr, | |
292 | const wxPoint& pos = wxDefaultPosition, | |
293 | const wxSize& size = wxDefaultSize, | |
294 | long style = wxFLP_DEFAULT_STYLE, | |
295 | const wxValidator& validator = wxDefaultValidator, | |
296 | const wxString& name = wxPyFilePickerCtrlNameStr); | |
297 | ||
298 | wxString GetPath() const; | |
299 | void SetPath(const wxString &str); | |
300 | ||
301 | // return true if the given path is valid for this control | |
302 | bool CheckPath(const wxString& path) const; | |
303 | ||
304 | // Returns the filtered value currently placed in the text control (if present). | |
305 | wxString GetTextCtrlValue() const; | |
306 | ||
307 | %property(Path, GetPath, SetPath, doc="See `GetPath` and `SetPath`"); | |
308 | %property(TextCtrlValue, GetTextCtrlValue, doc="See `GetTextCtrlValue`"); | |
309 | }; | |
310 | ||
311 | ||
312 | ||
313 | ||
314 | MustHaveApp(wxDirPickerCtrl); | |
315 | DocStr(wxDirPickerCtrl, | |
316 | "", ""); | |
317 | ||
318 | class wxDirPickerCtrl : public wxPickerBase | |
319 | { | |
320 | public: | |
321 | %pythonAppend wxDirPickerCtrl "self._setOORInfo(self)" | |
322 | %pythonAppend wxDirPickerCtrl() "" | |
323 | ||
324 | wxDirPickerCtrl(wxWindow *parent, wxWindowID id=-1, | |
325 | const wxString& path = wxPyEmptyString, | |
326 | const wxString& message = wxPyDirSelectorPromptStr, | |
327 | const wxPoint& pos = wxDefaultPosition, | |
328 | const wxSize& size = wxDefaultSize, | |
329 | long style = wxDIRP_DEFAULT_STYLE, | |
330 | const wxValidator& validator = wxDefaultValidator, | |
331 | const wxString& name = wxPyDirPickerCtrlNameStr); | |
332 | %RenameCtor(PreDirPickerCtrl, wxDirPickerCtrl()); | |
333 | ||
334 | bool Create(wxWindow *parent, wxWindowID id=-1, | |
335 | const wxString& path = wxPyEmptyString, | |
336 | const wxString& message = wxPyDirSelectorPromptStr, | |
337 | const wxPoint& pos = wxDefaultPosition, | |
338 | const wxSize& size = wxDefaultSize, | |
339 | long style = wxDIRP_DEFAULT_STYLE, | |
340 | const wxValidator& validator = wxDefaultValidator, | |
341 | const wxString& name = wxPyDirPickerCtrlNameStr); | |
342 | ||
343 | wxString GetPath() const; | |
344 | void SetPath(const wxString &str); | |
345 | ||
346 | // return true if the given path is valid for this control | |
347 | bool CheckPath(const wxString& path) const; | |
348 | ||
349 | // Returns the filtered value currently placed in the text control (if present). | |
350 | wxString GetTextCtrlValue() const; | |
351 | ||
352 | %property(Path, GetPath, SetPath, doc="See `GetPath` and `SetPath`"); | |
353 | %property(TextCtrlValue, GetTextCtrlValue, doc="See `GetTextCtrlValue`"); | |
354 | ||
355 | }; | |
356 | ||
357 | ||
358 | %constant wxEventType wxEVT_COMMAND_FILEPICKER_CHANGED; | |
359 | %constant wxEventType wxEVT_COMMAND_DIRPICKER_CHANGED; | |
360 | ||
361 | %pythoncode { | |
362 | EVT_FILEPICKER_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_FILEPICKER_CHANGED, 1 ) | |
363 | EVT_DIRPICKER_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_DIRPICKER_CHANGED, 1 ) | |
364 | } | |
365 | ||
366 | class wxFileDirPickerEvent : public wxCommandEvent | |
367 | { | |
368 | public: | |
369 | wxFileDirPickerEvent(wxEventType type, wxObject *generator, int id, const wxString &path); | |
370 | ||
371 | wxString GetPath() const { return m_path; } | |
372 | void SetPath(const wxString &p) { m_path = p; } | |
373 | ||
374 | %property(Path, GetPath, SetPath, doc="See `GetPath` and `SetPath`"); | |
375 | }; | |
376 | ||
377 | ||
378 | //--------------------------------------------------------------------------- | |
379 | %newgroup | |
380 | ||
381 | MAKE_CONST_WXSTRING(FontPickerCtrlNameStr); | |
382 | ||
383 | enum { | |
384 | wxFNTP_FONTDESC_AS_LABEL, | |
385 | wxFNTP_USEFONT_FOR_LABEL, | |
386 | wxFNTP_USE_TEXTCTRL, | |
387 | wxFNTP_DEFAULT_STYLE, | |
388 | }; | |
389 | ||
390 | ||
391 | MustHaveApp(wxFontPickerCtrl); | |
392 | DocStr(wxFontPickerCtrl, | |
393 | "", ""); | |
394 | ||
395 | ||
396 | class wxFontPickerCtrl : public wxPickerBase | |
397 | { | |
398 | public: | |
399 | %pythonAppend wxFontPickerCtrl "self._setOORInfo(self)" | |
400 | %pythonAppend wxFontPickerCtrl() "" | |
401 | ||
402 | ||
403 | wxFontPickerCtrl(wxWindow *parent, | |
404 | wxWindowID id=-1, | |
405 | const wxFont& initial = wxNullFont, | |
406 | const wxPoint& pos = wxDefaultPosition, | |
407 | const wxSize& size = wxDefaultSize, | |
408 | long style = wxFNTP_DEFAULT_STYLE, | |
409 | const wxValidator& validator = wxDefaultValidator, | |
410 | const wxString& name = wxPyFontPickerCtrlNameStr); | |
411 | %RenameCtor(PreFontPickerCtrl, wxFontPickerCtrl()); | |
412 | ||
413 | bool Create(wxWindow *parent, | |
414 | wxWindowID id=-1, | |
415 | const wxFont& initial = wxNullFont, | |
416 | const wxPoint& pos = wxDefaultPosition, | |
417 | const wxSize& size = wxDefaultSize, | |
418 | long style = wxFNTP_DEFAULT_STYLE, | |
419 | const wxValidator& validator = wxDefaultValidator, | |
420 | const wxString& name = wxPyFontPickerCtrlNameStr); | |
421 | ||
422 | ||
423 | // get the font chosen | |
424 | wxFont GetSelectedFont() const; | |
425 | ||
426 | // sets currently displayed font | |
427 | void SetSelectedFont(const wxFont& f); | |
428 | ||
429 | // set/get the max pointsize | |
430 | void SetMaxPointSize(unsigned int max); | |
431 | unsigned int GetMaxPointSize() const; | |
432 | ||
433 | %property(MaxPointSize, GetMaxPointSize, SetMaxPointSize, doc="See `GetMaxPointSize` and `SetMaxPointSize`"); | |
434 | %property(SelectedFont, GetSelectedFont, SetSelectedFont, doc="See `GetSelectedFont` and `SetSelectedFont`"); | |
435 | }; | |
436 | ||
437 | ||
438 | %constant wxEventType wxEVT_COMMAND_FONTPICKER_CHANGED; | |
439 | ||
440 | %pythoncode { | |
441 | EVT_FONTPICKER_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_FONTPICKER_CHANGED, 1 ) | |
442 | } | |
443 | ||
444 | ||
445 | class wxFontPickerEvent : public wxCommandEvent | |
446 | { | |
447 | public: | |
448 | wxFontPickerEvent(wxObject *generator, int id, const wxFont &f); | |
449 | ||
450 | wxFont GetFont() const; | |
451 | void SetFont(const wxFont &c); | |
452 | ||
453 | %property(Font, GetFont, SetFont, doc="See `GetFont` and `SetFont`"); | |
454 | }; | |
455 | ||
456 | //--------------------------------------------------------------------------- |