]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_sizers.i
Docstring updates and tweaks for epydoc
[wxWidgets.git] / wxPython / src / _sizers.i
CommitLineData
d14a1e28
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: _sizers.i
3// Purpose: SWIG interface defs for the Sizers
4//
5// Author: Robin Dunn
6//
7// Created: 18-Sept-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
18%{
19%}
20
21//---------------------------------------------------------------------------
22%newgroup;
23
24
25class wxSizerItem : public wxObject {
26public:
27 wxSizerItem();
28
29 %name(SizerItemSpacer) wxSizerItem( int width, int height, int proportion, int flag, int border, wxObject* userData);
30 %name(SizerItemWindow) wxSizerItem( wxWindow *window, int proportion, int flag, int border, wxObject* userData );
31 %name(SizerItemSizer) wxSizerItem( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData );
32
33 void DeleteWindows();
34 void DetachSizer();
35
36 wxSize GetSize();
37 wxSize CalcMin();
38 void SetDimension( wxPoint pos, wxSize size );
39
40 wxSize GetMinSize();
41 void SetInitSize( int x, int y );
42
43 %name(SetRatioWH) void SetRatio( int width, int height );
44 %name(SetRatioSize) void SetRatio( wxSize size );
45 void SetRatio( float ratio );
46 float GetRatio();
47
48 bool IsWindow();
49 bool IsSizer();
50 bool IsSpacer();
51
52 void SetProportion( int proportion );
53 int GetProportion();
52868a75
RD
54 %pythoncode { SetOption = SetProportion}
55 %pythoncode { GetOption = GetProportion}
d14a1e28
RD
56
57 void SetFlag( int flag );
58 int GetFlag();
59
60 void SetBorder( int border );
61 int GetBorder();
62
63 wxWindow *GetWindow();
64 void SetWindow( wxWindow *window );
65
66 wxSizer *GetSizer();
67 void SetSizer( wxSizer *sizer );
68
69 const wxSize& GetSpacer();
70 void SetSpacer( const wxSize &size );
71
72 void Show( bool show );
73 bool IsShown();
74
75 wxPoint GetPosition();
76
77 // wxObject* GetUserData();
78 %extend {
79 // Assume that the user data is a wxPyUserData object and return the contents
80 PyObject* GetUserData() {
81 wxPyUserData* data = (wxPyUserData*)self->GetUserData();
82 if (data) {
83 Py_INCREF(data->m_obj);
84 return data->m_obj;
85 } else {
86 Py_INCREF(Py_None);
87 return Py_None;
88 }
89 }
90 }
91};
92
93
94//---------------------------------------------------------------------------
95
96%{
97// Figure out the type of the sizer item
98
99struct wxPySizerItemInfo {
100 wxPySizerItemInfo()
dd9f7fea
RD
101 : window(NULL), sizer(NULL), gotSize(False),
102 size(wxDefaultSize), gotPos(False), pos(-1)
d14a1e28
RD
103 {}
104
105 wxWindow* window;
106 wxSizer* sizer;
107 bool gotSize;
108 wxSize size;
109 bool gotPos;
110 int pos;
111};
112
113static wxPySizerItemInfo wxPySizerItemTypeHelper(PyObject* item, bool checkSize, bool checkIdx ) {
114
115 wxPySizerItemInfo info;
116 wxSize size;
117 wxSize* sizePtr = &size;
118
119 // Find out what the type of the item is
120 // try wxWindow
121 if ( ! wxPyConvertSwigPtr(item, (void**)&info.window, wxT("wxWindow")) ) {
122 PyErr_Clear();
123 info.window = NULL;
124
125 // try wxSizer
126 if ( ! wxPyConvertSwigPtr(item, (void**)&info.sizer, wxT("wxSizer")) ) {
127 PyErr_Clear();
128 info.sizer = NULL;
129
130 // try wxSize or (w,h)
131 if ( checkSize && wxSize_helper(item, &sizePtr)) {
132 info.size = *sizePtr;
dd9f7fea 133 info.gotSize = True;
d14a1e28
RD
134 }
135
136 // or a single int
137 if (checkIdx && PyInt_Check(item)) {
138 info.pos = PyInt_AsLong(item);
dd9f7fea 139 info.gotPos = True;
d14a1e28
RD
140 }
141 }
142 }
143
144 if ( !(info.window || info.sizer || (checkSize && info.gotSize) || (checkIdx && info.gotPos)) ) {
145 // no expected type, figure out what kind of error message to generate
146 if ( !checkSize && !checkIdx )
147 PyErr_SetString(PyExc_TypeError, "wxWindow or wxSizer expected for item");
148 else if ( checkSize && !checkIdx )
149 PyErr_SetString(PyExc_TypeError, "wxWindow, wxSizer, wxSize, or (w,h) expected for item");
150 else if ( !checkSize && checkIdx)
151 PyErr_SetString(PyExc_TypeError, "wxWindow, wxSizer or int (position) expected for item");
152 else
153 // can this one happen?
154 PyErr_SetString(PyExc_TypeError, "wxWindow, wxSizer, wxSize, or (w,h) or int (position) expected for item");
155 }
156
157 return info;
158}
159%}
160
161
162
163
164class wxSizer : public wxObject {
165public:
166 // wxSizer(); **** abstract, can't instantiate
167 // ~wxSizer();
168
169 %extend {
170 void _setOORInfo(PyObject* _self) {
171 self->SetClientObject(new wxPyOORClientData(_self));
172 }
173
174
175 void Add(PyObject* item, int proportion=0, int flag=0, int border=0,
176 PyObject* userData=NULL) {
177
178 wxPyUserData* data = NULL;
da32eb53 179 bool blocked = wxPyBeginBlockThreads();
dd9f7fea 180 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, True, False);
d14a1e28
RD
181 if ( userData && (info.window || info.sizer || info.gotSize) )
182 data = new wxPyUserData(userData);
da32eb53 183 wxPyEndBlockThreads(blocked);
d14a1e28
RD
184
185 // Now call the real Add method if a valid item type was found
186 if ( info.window )
187 self->Add(info.window, proportion, flag, border, data);
188 else if ( info.sizer )
189 self->Add(info.sizer, proportion, flag, border, data);
190 else if (info.gotSize)
191 self->Add(info.size.GetWidth(), info.size.GetHeight(),
192 proportion, flag, border, data);
193 }
194
195
196 void Insert(int before, PyObject* item, int proportion=0, int flag=0,
197 int border=0, PyObject* userData=NULL) {
198
199 wxPyUserData* data = NULL;
da32eb53 200 bool blocked = wxPyBeginBlockThreads();
dd9f7fea 201 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, True, False);
d14a1e28
RD
202 if ( userData && (info.window || info.sizer || info.gotSize) )
203 data = new wxPyUserData(userData);
da32eb53 204 wxPyEndBlockThreads(blocked);
d14a1e28
RD
205
206 // Now call the real Insert method if a valid item type was found
207 if ( info.window )
208 self->Insert(before, info.window, proportion, flag, border, data);
209 else if ( info.sizer )
210 self->Insert(before, info.sizer, proportion, flag, border, data);
211 else if (info.gotSize)
212 self->Insert(before, info.size.GetWidth(), info.size.GetHeight(),
213 proportion, flag, border, data);
214 }
215
216
217
218 void Prepend(PyObject* item, int proportion=0, int flag=0, int border=0,
219 PyObject* userData=NULL) {
220
221 wxPyUserData* data = NULL;
da32eb53 222 bool blocked = wxPyBeginBlockThreads();
dd9f7fea 223 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, True, False);
d14a1e28
RD
224 if ( userData && (info.window || info.sizer || info.gotSize) )
225 data = new wxPyUserData(userData);
da32eb53 226 wxPyEndBlockThreads(blocked);
d14a1e28
RD
227
228 // Now call the real Prepend method if a valid item type was found
229 if ( info.window )
230 self->Prepend(info.window, proportion, flag, border, data);
231 else if ( info.sizer )
232 self->Prepend(info.sizer, proportion, flag, border, data);
233 else if (info.gotSize)
234 self->Prepend(info.size.GetWidth(), info.size.GetHeight(),
235 proportion, flag, border, data);
236 }
237
238
239 bool Remove(PyObject* item) {
da32eb53 240 bool blocked = wxPyBeginBlockThreads();
dd9f7fea 241 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, True);
da32eb53 242 wxPyEndBlockThreads(blocked);
d14a1e28
RD
243 if ( info.window )
244 return self->Remove(info.window);
245 else if ( info.sizer )
246 return self->Remove(info.sizer);
247 else if ( info.gotPos )
248 return self->Remove(info.pos);
249 else
dd9f7fea 250 return False;
d14a1e28
RD
251 }
252
253
dd9f7fea 254 void _SetItemMinSize(PyObject* item, const wxSize& size) {
da32eb53 255 bool blocked = wxPyBeginBlockThreads();
dd9f7fea 256 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, True);
da32eb53 257 wxPyEndBlockThreads(blocked);
d14a1e28
RD
258 if ( info.window )
259 self->SetItemMinSize(info.window, size);
260 else if ( info.sizer )
261 self->SetItemMinSize(info.sizer, size);
262 else if ( info.gotPos )
263 self->SetItemMinSize(info.pos, size);
264 }
265 }
266
267 %name(AddItem) void Add( wxSizerItem *item );
268 %name(InsertItem) void Insert( size_t index, wxSizerItem *item );
269 %name(PrependItem) void Prepend( wxSizerItem *item );
270
271
272 %pythoncode {
273 def AddMany(self, widgets):
dce2bd22
RD
274 """
275 AddMany is a convenience method for adding several items
276 to a sizer at one time. Simply pass it a list of tuples,
277 where each tuple consists of the parameters that you
278 would normally pass to the `Add` method.
279 """
d14a1e28 280 for childinfo in widgets:
dd9f7fea 281 if type(childinfo) != type(()) or (len(childinfo) == 2 and type(childinfo[0]) == type(1)):
d14a1e28
RD
282 childinfo = (childinfo, )
283 self.Add(*childinfo)
284
d147c724 285 %# for backwards compatibility only, please do not use in new code
dce2bd22
RD
286 AddWindow = wx._deprecated(Add, "AddWindow is deprecated, use `Add` instead.")
287 AddSizer = wx._deprecated(Add, "AddSizer is deprecated, use `Add` instead.")
288 AddSpacer = wx._deprecated(Add, "AddSpacer is deprecated, use `Add` instead.")
289 PrependWindow = wx._deprecated(Prepend, "PrependWindow is deprecated, use `Prepend` instead.")
290 PrependSizer = wx._deprecated(Prepend, "PrependSizer is deprecated, use `Prepend` instead.")
291 PrependSpacer = wx._deprecated(Prepend, "PrependSpacer is deprecated, use `Prepend` instead.")
292 InsertWindow = wx._deprecated(Insert, "InsertWindow is deprecated, use `Insert` instead.")
293 InsertSizer = wx._deprecated(Insert, "InsertSizer is deprecated, use `Insert` instead.")
294 InsertSpacer = wx._deprecated(Insert, "InsertSpacer is deprecated, use `Insert` instead.")
295 RemoveWindow = wx._deprecated(Remove, "RemoveWindow is deprecated, use `Remove` instead.")
296 RemoveSizer = wx._deprecated(Remove, "RemoveSizer is deprecated, use `Remove` instead.")
297 RemovePos = wx._deprecated(Remove, "RemovePos is deprecated, use `Remove` instead.")
d14a1e28
RD
298
299
300 def SetItemMinSize(self, item, *args):
301 if len(args) == 2:
302 return self._SetItemMinSize(item, args)
303 else:
304 return self._SetItemMinSize(item, args[0])
305 }
306
307
308 void SetDimension( int x, int y, int width, int height );
e5e66a2d 309 void SetMinSize( const wxSize &size );
d14a1e28
RD
310
311 wxSize GetSize();
312 wxPoint GetPosition();
313 wxSize GetMinSize();
314
315 %pythoncode {
316 def GetSizeTuple(self):
317 return self.GetSize().asTuple()
318 def GetPositionTuple(self):
319 return self.GetPosition().asTuple()
320 def GetMinSizeTuple(self):
321 return self.GetMinSize().asTuple()
322 }
323
324 virtual void RecalcSizes();
325 virtual wxSize CalcMin();
326
327 void Layout();
328
329 wxSize Fit( wxWindow *window );
330 void FitInside( wxWindow *window );
331
332 void SetSizeHints( wxWindow *window );
333 void SetVirtualSizeHints( wxWindow *window );
334
dd9f7fea 335 void Clear( bool delete_windows=False );
d14a1e28
RD
336 void DeleteWindows();
337
338
339 // wxList& GetChildren();
340 %extend {
341 PyObject* GetChildren() {
342 wxSizerItemList& list = self->GetChildren();
343 return wxPy_ConvertList(&list);
344 }
345 }
346
347
348 // Manage whether individual windows or sub-sizers are considered
349 // in the layout calculations or not.
350
351 %extend {
dd9f7fea
RD
352 void Show(PyObject* item, bool show = True) {
353 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, False);
d14a1e28
RD
354 if ( info.window )
355 self->Show(info.window, show);
356 else if ( info.sizer )
357 self->Show(info.sizer, show);
358 }
359
360
361 void Hide(PyObject* item) {
dd9f7fea 362 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, False);
d14a1e28
RD
363 if ( info.window )
364 self->Hide(info.window);
365 else if ( info.sizer )
366 self->Hide(info.sizer);
367 }
368
369
370 bool IsShown(PyObject* item) {
dd9f7fea 371 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, False);
d14a1e28
RD
372 if ( info.window )
373 return self->IsShown(info.window);
374 else if ( info.sizer )
375 return self->IsShown(info.sizer);
376 else
dd9f7fea 377 return False;
d14a1e28
RD
378 }
379 }
380
381
382 // Recursively call wxWindow::Show() on all sizer items.
383 void ShowItems(bool show);
384
385};
386
387
388//---------------------------------------------------------------------------
389// Use this one for deriving Python classes from
390%{
391// See pyclasses.h
392IMP_PYCALLBACK___pure(wxPySizer, wxSizer, RecalcSizes);
393IMP_PYCALLBACK_wxSize__pure(wxPySizer, wxSizer, CalcMin);
394IMPLEMENT_DYNAMIC_CLASS(wxPySizer, wxSizer);
395%}
396
397
398
399class wxPySizer : public wxSizer {
400public:
2b9048c5 401 %pythonAppend wxPySizer "self._setCallbackInfo(self, PySizer);self._setOORInfo(self)"
d14a1e28
RD
402
403 wxPySizer();
404 void _setCallbackInfo(PyObject* self, PyObject* _class);
405};
406
407
408//---------------------------------------------------------------------------
409%newgroup;
410
411class wxBoxSizer : public wxSizer {
412public:
2b9048c5 413 %pythonAppend wxBoxSizer "self._setOORInfo(self)"
d14a1e28
RD
414
415 wxBoxSizer(int orient = wxHORIZONTAL);
416
417 int GetOrientation();
418 void SetOrientation(int orient);
419 void RecalcSizes();
420 wxSize CalcMin();
421};
422
423//---------------------------------------------------------------------------
424%newgroup;
425
426class wxStaticBoxSizer : public wxBoxSizer {
427public:
2b9048c5 428 %pythonAppend wxStaticBoxSizer "self._setOORInfo(self)"
d14a1e28
RD
429
430 wxStaticBoxSizer(wxStaticBox *box, int orient = wxHORIZONTAL);
431
432 wxStaticBox *GetStaticBox();
433 void RecalcSizes();
434 wxSize CalcMin();
435};
436
437//---------------------------------------------------------------------------
438%newgroup;
439
440class wxGridSizer: public wxSizer
441{
442public:
2b9048c5 443 %pythonAppend wxGridSizer "self._setOORInfo(self)"
d14a1e28
RD
444
445 wxGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 );
446
447 void RecalcSizes();
448 wxSize CalcMin();
449
450 void SetCols( int cols );
451 void SetRows( int rows );
452 void SetVGap( int gap );
453 void SetHGap( int gap );
454 int GetCols();
455 int GetRows();
456 int GetVGap();
457 int GetHGap();
458};
459
460//---------------------------------------------------------------------------
461%newgroup;
462
463enum wxFlexSizerGrowMode
464{
465 // don't resize the cells in non-flexible direction at all
466 wxFLEX_GROWMODE_NONE,
467
468 // uniformly resize only the specified ones (default)
469 wxFLEX_GROWMODE_SPECIFIED,
470
471 // uniformly resize all cells
472 wxFLEX_GROWMODE_ALL
473};
474
475
476class wxFlexGridSizer: public wxGridSizer
477{
478public:
2b9048c5 479 %pythonAppend wxFlexGridSizer "self._setOORInfo(self)"
d14a1e28
RD
480
481 wxFlexGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 );
482
483 void RecalcSizes();
484 wxSize CalcMin();
485
486 void AddGrowableRow( size_t idx, int proportion = 0 );
487 void RemoveGrowableRow( size_t idx );
488 void AddGrowableCol( size_t idx, int proportion = 0 );
489 void RemoveGrowableCol( size_t idx );
490
491 // the sizer cells may grow in both directions, not grow at all or only
492 // grow in one direction but not the other
493
494 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
495 void SetFlexibleDirection(int direction);
496 int GetFlexibleDirection();
497
498 // note that the grow mode only applies to the direction which is not
499 // flexible
500 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode);
501 wxFlexSizerGrowMode GetNonFlexibleGrowMode();
dd9f7fea
RD
502
503 // Read-only access to the row heights and col widths arrays
504 const wxArrayInt& GetRowHeights() const;
505 const wxArrayInt& GetColWidths() const;
d14a1e28
RD
506};
507
508//---------------------------------------------------------------------------