]>
Commit | Line | Data |
---|---|---|
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 | DocStr(wxSizerItem, | |
25 | "The wx.SizerItem class is used to track the position, size and other | |
26 | attributes of each item managed by a `wx.Sizer`. In normal usage user | |
27 | code should never need to deal directly with a wx.SizerItem, but | |
28 | custom classes derived from `wx.PySizer` will probably need to use the | |
29 | collection of wx.SizerItems held by wx.Sizer when calculating layout. | |
30 | ||
31 | :see: `wx.Sizer`, `wx.GBSizerItem`", ""); | |
32 | ||
33 | class wxSizerItem : public wxObject { | |
34 | public: | |
35 | DocCtorStr( | |
36 | wxSizerItem(), | |
37 | "Constructs an empty wx.SizerItem. Either a window, sizer or spacer | |
38 | size will need to be set before this item can be used in a Sizer. | |
39 | ||
40 | You will probably never need to create a wx.SizerItem directly as they | |
41 | are created automatically when the sizer's Add, Insert or Prepend | |
42 | methods are called. | |
43 | ||
44 | :see: `wx.SizerItemSpacer`, `wx.SizerItemWindow`, `wx.SizerItemSizer`", ""); | |
45 | ||
46 | ||
47 | ~wxSizerItem(); | |
48 | ||
49 | ||
50 | %extend { | |
51 | DocStr( | |
52 | wxSizerItem( wxWindow *window, int proportion, int flag, | |
53 | int border, PyObject* userData=NULL ), | |
54 | "Constructs a `wx.SizerItem` for tracking a window.", ""); | |
55 | ||
56 | %RenameCtor(SizerItemWindow, wxSizerItem( wxWindow *window, int proportion, int flag, | |
57 | int border, PyObject* userData=NULL )) | |
58 | { | |
59 | wxPyUserData* data = NULL; | |
60 | if ( userData ) { | |
61 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
62 | data = new wxPyUserData(userData); | |
63 | wxPyEndBlockThreads(blocked); | |
64 | } | |
65 | return new wxSizerItem(window, proportion, flag, border, data); | |
66 | } | |
67 | ||
68 | ||
69 | DocStr( | |
70 | wxSizerItem( int width, int height, int proportion, int flag, | |
71 | int border, PyObject* userData=NULL), | |
72 | "Constructs a `wx.SizerItem` for tracking a spacer.", ""); | |
73 | ||
74 | %RenameCtor(SizerItemSpacer, wxSizerItem( int width, int height, int proportion, int flag, | |
75 | int border, PyObject* userData=NULL)) | |
76 | { | |
77 | wxPyUserData* data = NULL; | |
78 | if ( userData ) { | |
79 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
80 | data = new wxPyUserData(userData); | |
81 | wxPyEndBlockThreads(blocked); | |
82 | } | |
83 | return new wxSizerItem(width, height, proportion, flag, border, data); | |
84 | } | |
85 | ||
86 | DocStr( | |
87 | wxSizerItem( wxSizer *sizer, int proportion, int flag, | |
88 | int border, PyObject* userData=NULL ), | |
89 | "Constructs a `wx.SizerItem` for tracking a subsizer", ""); | |
90 | ||
91 | %disownarg( wxSizer *sizer ); | |
92 | %RenameCtor(SizerItemSizer, wxSizerItem( wxSizer *sizer, int proportion, int flag, | |
93 | int border, PyObject* userData=NULL )) | |
94 | { | |
95 | wxPyUserData* data = NULL; | |
96 | if ( userData ) { | |
97 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
98 | data = new wxPyUserData(userData); | |
99 | wxPyEndBlockThreads(blocked); | |
100 | } | |
101 | return new wxSizerItem(sizer, proportion, flag, border, data); | |
102 | } | |
103 | %cleardisown( wxSizer *sizer ); | |
104 | } | |
105 | ||
106 | ||
107 | ||
108 | DocDeclStr( | |
109 | void , DeleteWindows(), | |
110 | "Destroy the window or the windows in a subsizer, depending on the type | |
111 | of item.", ""); | |
112 | ||
113 | DocDeclStr( | |
114 | void , DetachSizer(), | |
115 | "Enable deleting the SizerItem without destroying the contained sizer.", ""); | |
116 | ||
117 | ||
118 | DocDeclStr( | |
119 | wxSize , GetSize(), | |
120 | "Get the current size of the item, as set in the last Layout.", ""); | |
121 | ||
122 | DocDeclStr( | |
123 | wxSize , CalcMin(), | |
124 | "Calculates the minimum desired size for the item, including any space | |
125 | needed by borders.", ""); | |
126 | ||
127 | DocDeclStr( | |
128 | void , SetDimension( const wxPoint& pos, const wxSize& size ), | |
129 | "Set the position and size of the space allocated for this item by the | |
130 | sizer, and adjust the position and size of the item (window or | |
131 | subsizer) to be within that space taking alignment and borders into | |
132 | account.", ""); | |
133 | ||
134 | ||
135 | DocDeclStr( | |
136 | wxSize , GetMinSize(), | |
137 | "Get the minimum size needed for the item.", ""); | |
138 | ||
139 | DocDeclStr( | |
140 | wxSize , GetMinSizeWithBorder() const, | |
141 | "Get the minimum size needed for the item with space for the borders | |
142 | added, if needed.", ""); | |
143 | ||
144 | DocDeclStr( | |
145 | void , SetInitSize( int x, int y ), | |
146 | "", ""); | |
147 | ||
148 | ||
149 | DocStr(SetRatio, | |
150 | "Set the ratio item attribute.", ""); | |
151 | %Rename(SetRatioWH, void, SetRatio( int width, int height )); | |
152 | %Rename(SetRatioSize, void, SetRatio( const wxSize& size )); | |
153 | void SetRatio( float ratio ); | |
154 | ||
155 | DocDeclStr( | |
156 | float , GetRatio(), | |
157 | "Set the ratio item attribute.", ""); | |
158 | ||
159 | DocDeclStr( | |
160 | wxRect , GetRect(), | |
161 | "Returns the rectangle that the sizer item should occupy", ""); | |
162 | ||
163 | ||
164 | DocDeclStr( | |
165 | bool , IsWindow(), | |
166 | "Is this sizer item a window?", ""); | |
167 | ||
168 | DocDeclStr( | |
169 | bool , IsSizer(), | |
170 | "Is this sizer item a subsizer?", ""); | |
171 | ||
172 | DocDeclStr( | |
173 | bool , IsSpacer(), | |
174 | "Is this sizer item a spacer?", ""); | |
175 | ||
176 | ||
177 | DocDeclStr( | |
178 | void , SetProportion( int proportion ), | |
179 | "Set the proportion value for this item.", ""); | |
180 | ||
181 | DocDeclStr( | |
182 | int , GetProportion(), | |
183 | "Get the proportion value for this item.", ""); | |
184 | ||
185 | %pythoncode { SetOption = wx._deprecated(SetProportion, "Please use `SetProportion` instead.") } | |
186 | %pythoncode { GetOption = wx._deprecated(GetProportion, "Please use `GetProportion` instead.") } | |
187 | ||
188 | ||
189 | DocDeclStr( | |
190 | void , SetFlag( int flag ), | |
191 | "Set the flag value for this item.", ""); | |
192 | ||
193 | DocDeclStr( | |
194 | int , GetFlag(), | |
195 | "Get the flag value for this item.", ""); | |
196 | ||
197 | ||
198 | DocDeclStr( | |
199 | void , SetBorder( int border ), | |
200 | "Set the border value for this item.", ""); | |
201 | ||
202 | DocDeclStr( | |
203 | int , GetBorder(), | |
204 | "Get the border value for this item.", ""); | |
205 | ||
206 | ||
207 | ||
208 | DocDeclStr( | |
209 | wxWindow *, GetWindow(), | |
210 | "Get the window (if any) that is managed by this sizer item.", ""); | |
211 | ||
212 | DocDeclStr( | |
213 | void , SetWindow( wxWindow *window ), | |
214 | "Set the window to be managed by this sizer item.", ""); | |
215 | ||
216 | ||
217 | DocDeclStr( | |
218 | wxSizer *, GetSizer(), | |
219 | "Get the subsizer (if any) that is managed by this sizer item.", ""); | |
220 | ||
221 | %disownarg( wxSizer *sizer ); | |
222 | DocDeclStr( | |
223 | void , SetSizer( wxSizer *sizer ), | |
224 | "Set the subsizer to be managed by this sizer item.", ""); | |
225 | %cleardisown( wxSizer *sizer ); | |
226 | ||
227 | ||
228 | DocDeclStr( | |
229 | const wxSize& , GetSpacer(), | |
230 | "Get the size of the spacer managed by this sizer item.", ""); | |
231 | ||
232 | DocDeclStr( | |
233 | void , SetSpacer( const wxSize &size ), | |
234 | "Set the size of the spacer to be managed by this sizer item.", ""); | |
235 | ||
236 | ||
237 | DocDeclStr( | |
238 | void , Show( bool show ), | |
239 | "Set the show item attribute, which sizers use to determine if the item | |
240 | is to be made part of the layout or not. If the item is tracking a | |
241 | window then it is shown or hidden as needed.", ""); | |
242 | ||
243 | DocDeclStr( | |
244 | bool , IsShown(), | |
245 | "Is the item to be shown in the layout?", ""); | |
246 | ||
247 | ||
248 | DocDeclStr( | |
249 | wxPoint , GetPosition(), | |
250 | "Returns the current position of the item, as set in the last Layout.", ""); | |
251 | ||
252 | ||
253 | // wxObject* GetUserData(); | |
254 | %extend { | |
255 | // Assume that the user data is a wxPyUserData object and return the contents | |
256 | ||
257 | DocStr(GetUserData, | |
258 | "Returns the userData associated with this sizer item, or None if there | |
259 | isn't any.", ""); | |
260 | PyObject* GetUserData() { | |
261 | wxPyUserData* data = (wxPyUserData*)self->GetUserData(); | |
262 | if (data) { | |
263 | Py_INCREF(data->m_obj); | |
264 | return data->m_obj; | |
265 | } else { | |
266 | Py_INCREF(Py_None); | |
267 | return Py_None; | |
268 | } | |
269 | } | |
270 | ||
271 | DocStr(SetUserData, | |
272 | "Associate a Python object with this sizer item.", ""); | |
273 | void SetUserData(PyObject* userData) { | |
274 | wxPyUserData* data = NULL; | |
275 | if ( userData ) { | |
276 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
277 | data = new wxPyUserData(userData); | |
278 | wxPyEndBlockThreads(blocked); | |
279 | } | |
280 | self->SetUserData(data); | |
281 | } | |
282 | } | |
283 | }; | |
284 | ||
285 | ||
286 | //--------------------------------------------------------------------------- | |
287 | ||
288 | %{ | |
289 | // Figure out the type of the sizer item | |
290 | ||
291 | struct wxPySizerItemInfo { | |
292 | wxPySizerItemInfo() | |
293 | : window(NULL), sizer(NULL), gotSize(false), | |
294 | size(wxDefaultSize), gotPos(false), pos(-1) | |
295 | {} | |
296 | ||
297 | wxWindow* window; | |
298 | wxSizer* sizer; | |
299 | bool gotSize; | |
300 | wxSize size; | |
301 | bool gotPos; | |
302 | int pos; | |
303 | }; | |
304 | ||
305 | static wxPySizerItemInfo wxPySizerItemTypeHelper(PyObject* item, bool checkSize, bool checkIdx ) { | |
306 | ||
307 | wxPySizerItemInfo info; | |
308 | wxSize size; | |
309 | wxSize* sizePtr = &size; | |
310 | ||
311 | // Find out what the type of the item is | |
312 | // try wxWindow | |
313 | if ( ! wxPyConvertSwigPtr(item, (void**)&info.window, wxT("wxWindow")) ) { | |
314 | PyErr_Clear(); | |
315 | info.window = NULL; | |
316 | ||
317 | // try wxSizer | |
318 | if ( ! wxPyConvertSwigPtr(item, (void**)&info.sizer, wxT("wxSizer")) ) { | |
319 | PyErr_Clear(); | |
320 | info.sizer = NULL; | |
321 | ||
322 | // try wxSize or (w,h) | |
323 | if ( checkSize && wxSize_helper(item, &sizePtr)) { | |
324 | info.size = *sizePtr; | |
325 | info.gotSize = true; | |
326 | } | |
327 | ||
328 | // or a single int | |
329 | if (checkIdx && PyInt_Check(item)) { | |
330 | info.pos = PyInt_AsLong(item); | |
331 | info.gotPos = true; | |
332 | } | |
333 | } | |
334 | } | |
335 | ||
336 | if ( !(info.window || info.sizer || (checkSize && info.gotSize) || (checkIdx && info.gotPos)) ) { | |
337 | // no expected type, figure out what kind of error message to generate | |
338 | if ( !checkSize && !checkIdx ) | |
339 | PyErr_SetString(PyExc_TypeError, "wx.Window or wx.Sizer expected for item"); | |
340 | else if ( checkSize && !checkIdx ) | |
341 | PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer, wx.Size, or (w,h) expected for item"); | |
342 | else if ( !checkSize && checkIdx) | |
343 | PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer or int (position) expected for item"); | |
344 | else | |
345 | // can this one happen? | |
346 | PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer, wx.Size, or (w,h) or int (position) expected for item"); | |
347 | } | |
348 | ||
349 | return info; | |
350 | } | |
351 | %} | |
352 | ||
353 | ||
354 | ||
355 | ||
356 | DocStr(wxSizer, | |
357 | "wx.Sizer is the abstract base class used for laying out subwindows in | |
358 | a window. You cannot use wx.Sizer directly; instead, you will have to | |
359 | use one of the sizer classes derived from it such as `wx.BoxSizer`, | |
360 | `wx.StaticBoxSizer`, `wx.NotebookSizer`, `wx.GridSizer`, `wx.FlexGridSizer` | |
361 | and `wx.GridBagSizer`. | |
362 | ||
363 | The concept implemented by sizers in wxWidgets is closely related to | |
364 | layout tools in other GUI toolkits, such as Java's AWT, the GTK | |
365 | toolkit or the Qt toolkit. It is based upon the idea of the individual | |
366 | subwindows reporting their minimal required size and their ability to | |
367 | get stretched if the size of the parent window has changed. This will | |
368 | most often mean that the programmer does not set the original size of | |
369 | a dialog in the beginning, rather the dialog will assigned a sizer and | |
370 | this sizer will be queried about the recommended size. The sizer in | |
371 | turn will query its children, which can be normal windows or contorls, | |
372 | empty space or other sizers, so that a hierarchy of sizers can be | |
373 | constructed. Note that wxSizer does not derive from wxWindow and thus | |
374 | do not interfere with tab ordering and requires very little resources | |
375 | compared to a real window on screen. | |
376 | ||
377 | What makes sizers so well fitted for use in wxWidgets is the fact that | |
378 | every control reports its own minimal size and the algorithm can | |
379 | handle differences in font sizes or different window (dialog item) | |
380 | sizes on different platforms without problems. If for example the | |
381 | standard font as well as the overall design of Mac widgets requires | |
382 | more space than on Windows, then the initial size of a dialog using a | |
383 | sizer will automatically be bigger on Mac than on Windows.", " | |
384 | ||
385 | Sizers may also be used to control the layout of custom drawn items on | |
386 | the window. The `Add`, `Insert`, and `Prepend` functions return a | |
387 | pointer to the newly added `wx.SizerItem`. Just add empty space of the | |
388 | desired size and attributes, and then use the `wx.SizerItem.GetRect` | |
389 | method to determine where the drawing operations should take place. | |
390 | ||
391 | :note: If you wish to create a custom sizer class in wxPython you | |
392 | should derive the class from `wx.PySizer` in order to get | |
393 | Python-aware capabilities for the various virtual methods. | |
394 | ||
395 | :see: `wx.SizerItem` | |
396 | ||
397 | :todo: More dscriptive text here along with some pictures... | |
398 | ||
399 | "); | |
400 | ||
401 | class wxSizer : public wxObject { | |
402 | public: | |
403 | // wxSizer(); **** abstract, can't instantiate | |
404 | ||
405 | ~wxSizer(); | |
406 | ||
407 | %extend { | |
408 | void _setOORInfo(PyObject* _self) { | |
409 | if (!self->GetClientObject()) | |
410 | self->SetClientObject(new wxPyOORClientData(_self)); | |
411 | } | |
412 | ||
413 | DocAStr(Add, | |
414 | "Add(self, item, int proportion=0, int flag=0, int border=0, | |
415 | PyObject userData=None) -> wx.SizerItem", | |
416 | ||
417 | "Appends a child item to the sizer.", " | |
418 | ||
419 | :param item: The item can be one of three kinds of objects: | |
420 | ||
421 | - **window**: A `wx.Window` to be managed by the sizer. Its | |
422 | minimal size (either set explicitly by the user or | |
423 | calculated internally when constructed with wx.DefaultSize) | |
424 | is interpreted as the minimal size to use when laying out | |
425 | item in the sizer. This is particularly useful in | |
426 | connection with `wx.Window.SetSizeHints`. | |
427 | ||
428 | - **sizer**: The (child-)sizer to be added to the sizer. This | |
429 | allows placing a child sizer in a sizer and thus to create | |
430 | hierarchies of sizers (typically a vertical box as the top | |
431 | sizer and several horizontal boxes on the level beneath). | |
432 | ||
433 | - **size**: A `wx.Size` or a 2-element sequence of integers | |
434 | that represents the width and height of a spacer to be added | |
435 | to the sizer. Adding spacers to sizers gives more | |
436 | flexibility in the design of dialogs; imagine for example a | |
437 | horizontal box with two buttons at the bottom of a dialog: | |
438 | you might want to insert a space between the two buttons and | |
439 | make that space stretchable using the *proportion* value and | |
440 | the result will be that the left button will be aligned with | |
441 | the left side of the dialog and the right button with the | |
442 | right side - the space in between will shrink and grow with | |
443 | the dialog. | |
444 | ||
445 | :param proportion: Although the meaning of this parameter is | |
446 | undefined in wx.Sizer, it is used in `wx.BoxSizer` to indicate | |
447 | if a child of a sizer can change its size in the main | |
448 | orientation of the wx.BoxSizer - where 0 stands for not | |
449 | changeable and a value of more than zero is interpreted | |
450 | relative (a proportion of the total) to the value of other | |
451 | children of the same wx.BoxSizer. For example, you might have | |
452 | a horizontal wx.BoxSizer with three children, two of which are | |
453 | supposed to change their size with the sizer. Then the two | |
454 | stretchable windows should each be given *proportion* value of | |
455 | 1 to make them grow and shrink equally with the sizer's | |
456 | horizontal dimension. But if one of them had a *proportion* | |
457 | value of 2 then it would get a double share of the space | |
458 | available after the fixed size items are positioned. | |
459 | ||
460 | :param flag: This parameter can be used to set a number of flags | |
461 | which can be combined using the binary OR operator ``|``. Two | |
462 | main behaviours are defined using these flags. One is the | |
463 | border around a window: the *border* parameter determines the | |
464 | border width whereas the flags given here determine which | |
465 | side(s) of the item that the border will be added. The other | |
466 | flags determine how the sizer item behaves when the space | |
467 | allotted to the sizer changes, and is somewhat dependent on | |
468 | the specific kind of sizer used. | |
469 | ||
470 | +----------------------------+------------------------------------------+ | |
471 | |- wx.TOP |These flags are used to specify | | |
472 | |- wx.BOTTOM |which side(s) of the sizer item that | | |
473 | |- wx.LEFT |the *border* width will apply to. | | |
474 | |- wx.RIGHT | | | |
475 | |- wx.ALL | | | |
476 | | | | | |
477 | +----------------------------+------------------------------------------+ | |
478 | |- wx.EXPAND |The item will be expanded to fill | | |
479 | | |the space allotted to the item. | | |
480 | +----------------------------+------------------------------------------+ | |
481 | |- wx.SHAPED |The item will be expanded as much as | | |
482 | | |possible while also maintaining its | | |
483 | | |aspect ratio | | |
484 | +----------------------------+------------------------------------------+ | |
485 | |- wx.FIXED_MINSIZE |Normally wx.Sizers will use | | |
486 | | |`wx.Window.GetMinSize` or | | |
487 | | |`wx.Window.GetBestSize` to determine what | | |
488 | | |the minimal size of window items should | | |
489 | | |be, and will use that size to calculate | | |
490 | | |the layout. This allows layouts to adjust | | |
491 | | |when an item changes and it's best size | | |
492 | | |becomes different. If you would rather | | |
493 | | |have a window item stay the size it | | |
494 | | |started with then use wx.FIXED_MINSIZE. | | |
495 | +----------------------------+------------------------------------------+ | |
496 | |- wx.ALIGN_CENTER |The wx.ALIGN flags allow you to specify | | |
497 | |- wx.ALIGN_LEFT |the alignment of the item within the space| | |
498 | |- wx.ALIGN_RIGHT |allotted to it by the sizer, ajusted for | | |
499 | |- wx.ALIGN_TOP |the border if any. | | |
500 | |- wx.ALIGN_BOTTOM | | | |
501 | |- wx.ALIGN_CENTER_VERTICAL | | | |
502 | |- wx.ALIGN_CENTER_HORIZONTAL| | | |
503 | +----------------------------+------------------------------------------+ | |
504 | ||
505 | ||
506 | :param border: Determines the border width, if the *flag* | |
507 | parameter is set to include any border flag. | |
508 | ||
509 | :param userData: Allows an extra object to be attached to the | |
510 | sizer item, for use in derived classes when sizing information | |
511 | is more complex than the *proportion* and *flag* will allow for. | |
512 | "); | |
513 | ||
514 | wxSizerItem* Add(PyObject* item, int proportion=0, int flag=0, int border=0, | |
515 | PyObject* userData=NULL) { | |
516 | ||
517 | wxPyUserData* data = NULL; | |
518 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
519 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); | |
520 | if ( userData && (info.window || info.sizer || info.gotSize) ) | |
521 | data = new wxPyUserData(userData); | |
522 | if ( info.sizer ) | |
523 | PyObject_SetAttrString(item,"thisown",Py_False); | |
524 | wxPyEndBlockThreads(blocked); | |
525 | ||
526 | // Now call the real Add method if a valid item type was found | |
527 | if ( info.window ) | |
528 | return self->Add(info.window, proportion, flag, border, data); | |
529 | else if ( info.sizer ) | |
530 | return self->Add(info.sizer, proportion, flag, border, data); | |
531 | else if (info.gotSize) | |
532 | return self->Add(info.size.GetWidth(), info.size.GetHeight(), | |
533 | proportion, flag, border, data); | |
534 | else | |
535 | return NULL; | |
536 | } | |
537 | ||
538 | // virtual wxSizerItem* AddSpacer(int size); | |
539 | // virtual wxSizerItem* AddStretchSpacer(int prop = 1); | |
540 | ||
541 | DocAStr(Insert, | |
542 | "Insert(self, int before, item, int proportion=0, int flag=0, int border=0, | |
543 | PyObject userData=None) -> wx.SizerItem", | |
544 | ||
545 | "Inserts a new item into the list of items managed by this sizer before | |
546 | the item at index *before*. See `Add` for a description of the parameters.", ""); | |
547 | wxSizerItem* Insert(int before, PyObject* item, int proportion=0, int flag=0, | |
548 | int border=0, PyObject* userData=NULL) { | |
549 | ||
550 | wxPyUserData* data = NULL; | |
551 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
552 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); | |
553 | if ( userData && (info.window || info.sizer || info.gotSize) ) | |
554 | data = new wxPyUserData(userData); | |
555 | if ( info.sizer ) | |
556 | PyObject_SetAttrString(item,"thisown",Py_False); | |
557 | wxPyEndBlockThreads(blocked); | |
558 | ||
559 | // Now call the real Insert method if a valid item type was found | |
560 | if ( info.window ) | |
561 | return self->Insert(before, info.window, proportion, flag, border, data); | |
562 | else if ( info.sizer ) | |
563 | return self->Insert(before, info.sizer, proportion, flag, border, data); | |
564 | else if (info.gotSize) | |
565 | return self->Insert(before, info.size.GetWidth(), info.size.GetHeight(), | |
566 | proportion, flag, border, data); | |
567 | else | |
568 | return NULL; | |
569 | } | |
570 | ||
571 | ||
572 | // virtual wxSizerItem* InsertSpacer(size_t index, int size); | |
573 | // virtual wxSizerItem* InsertStretchSpacer(size_t index, int prop = 1); | |
574 | ||
575 | DocAStr(Prepend, | |
576 | "Prepend(self, item, int proportion=0, int flag=0, int border=0, | |
577 | PyObject userData=None) -> wx.SizerItem", | |
578 | ||
579 | "Adds a new item to the begining of the list of sizer items managed by | |
580 | this sizer. See `Add` for a description of the parameters.", ""); | |
581 | wxSizerItem* Prepend(PyObject* item, int proportion=0, int flag=0, int border=0, | |
582 | PyObject* userData=NULL) { | |
583 | ||
584 | wxPyUserData* data = NULL; | |
585 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
586 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false); | |
587 | if ( userData && (info.window || info.sizer || info.gotSize) ) | |
588 | data = new wxPyUserData(userData); | |
589 | if ( info.sizer ) | |
590 | PyObject_SetAttrString(item,"thisown",Py_False); | |
591 | wxPyEndBlockThreads(blocked); | |
592 | ||
593 | // Now call the real Prepend method if a valid item type was found | |
594 | if ( info.window ) | |
595 | return self->Prepend(info.window, proportion, flag, border, data); | |
596 | else if ( info.sizer ) | |
597 | return self->Prepend(info.sizer, proportion, flag, border, data); | |
598 | else if (info.gotSize) | |
599 | return self->Prepend(info.size.GetWidth(), info.size.GetHeight(), | |
600 | proportion, flag, border, data); | |
601 | else | |
602 | return NULL; | |
603 | } | |
604 | ||
605 | // virtual wxSizerItem* PrependSpacer(int size); | |
606 | // virtual wxSizerItem* PrependStretchSpacer(int prop = 1); | |
607 | ||
608 | DocAStr(Remove, | |
609 | "Remove(self, item) -> bool", | |
610 | "Removes an item from the sizer and destroys it. This method does not | |
611 | cause any layout or resizing to take place, call `Layout` to update | |
612 | the layout on screen after removing a child from the sizer. The | |
613 | *item* parameter can be either a window, a sizer, or the zero-based | |
614 | index of an item to remove. Returns True if the child item was found | |
615 | and removed.", " | |
616 | ||
617 | :note: For historical reasons calling this method with a `wx.Window` | |
618 | parameter is depreacted, as it will not be able to destroy the | |
619 | window since it is owned by its parent. You should use `Detach` | |
620 | instead. | |
621 | "); | |
622 | bool Remove(PyObject* item) { | |
623 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
624 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); | |
625 | wxPyEndBlockThreads(blocked); | |
626 | if ( info.window ) | |
627 | return self->Remove(info.window); | |
628 | else if ( info.sizer ) | |
629 | return self->Remove(info.sizer); | |
630 | else if ( info.gotPos ) | |
631 | return self->Remove(info.pos); | |
632 | else | |
633 | return false; | |
634 | } | |
635 | ||
636 | ||
637 | DocAStr(Detach, | |
638 | "Detach(self, item) -> bool", | |
639 | "Detaches an item from the sizer without destroying it. This method | |
640 | does not cause any layout or resizing to take place, call `Layout` to | |
641 | do so. The *item* parameter can be either a window, a sizer, or the | |
642 | zero-based index of the item to be detached. Returns True if the child item | |
643 | was found and detached.", ""); | |
644 | bool Detach(PyObject* item) { | |
645 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
646 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); | |
647 | wxPyEndBlockThreads(blocked); | |
648 | if ( info.window ) | |
649 | return self->Detach(info.window); | |
650 | else if ( info.sizer ) | |
651 | return self->Detach(info.sizer); | |
652 | else if ( info.gotPos ) | |
653 | return self->Detach(info.pos); | |
654 | else | |
655 | return false; | |
656 | } | |
657 | ||
658 | ||
659 | DocAStr(GetItem, | |
660 | "GetItem(self, item) -> wx.SizerItem", | |
661 | "Returns the `wx.SizerItem` which holds the *item* given. The *item* | |
662 | parameter can be either a window, a sizer, or the zero-based index of | |
663 | the item to be found.", ""); | |
664 | wxSizerItem* GetItem(PyObject* item) { | |
665 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
666 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); | |
667 | wxPyEndBlockThreads(blocked); | |
668 | if ( info.window ) | |
669 | return self->GetItem(info.window); | |
670 | else if ( info.sizer ) | |
671 | return self->GetItem(info.sizer); | |
672 | else if ( info.gotPos ) | |
673 | return self->GetItem(info.pos); | |
674 | else | |
675 | return NULL; | |
676 | } | |
677 | ||
678 | ||
679 | void _SetItemMinSize(PyObject* item, const wxSize& size) { | |
680 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
681 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); | |
682 | wxPyEndBlockThreads(blocked); | |
683 | if ( info.window ) | |
684 | self->SetItemMinSize(info.window, size); | |
685 | else if ( info.sizer ) | |
686 | self->SetItemMinSize(info.sizer, size); | |
687 | else if ( info.gotPos ) | |
688 | self->SetItemMinSize(info.pos, size); | |
689 | } | |
690 | } | |
691 | ||
692 | %pythoncode { | |
693 | def SetItemMinSize(self, item, *args): | |
694 | """ | |
695 | SetItemMinSize(self, item, Size size) | |
696 | ||
697 | Sets the minimum size that will be allocated for an item in the sizer. | |
698 | The *item* parameter can be either a window, a sizer, or the | |
699 | zero-based index of the item. If a window or sizer is given then it | |
700 | will be searched for recursivly in subsizers if neccessary. | |
701 | """ | |
702 | if len(args) == 2: | |
703 | %# for backward compatibility accept separate width,height args too | |
704 | return self._SetItemMinSize(item, args) | |
705 | else: | |
706 | return self._SetItemMinSize(item, args[0]) | |
707 | } | |
708 | ||
709 | ||
710 | %disownarg( wxSizerItem *item ); | |
711 | ||
712 | DocDeclAStrName( | |
713 | wxSizerItem* , Add( wxSizerItem *item ), | |
714 | "AddItem(self, SizerItem item)", | |
715 | "Adds a `wx.SizerItem` to the sizer.", "", | |
716 | AddItem); | |
717 | ||
718 | DocDeclAStrName( | |
719 | wxSizerItem* , Insert( size_t index, wxSizerItem *item ), | |
720 | "InsertItem(self, int index, SizerItem item)", | |
721 | "Inserts a `wx.SizerItem` to the sizer at the position given by *index*.", "", | |
722 | InsertItem); | |
723 | ||
724 | DocDeclAStrName( | |
725 | wxSizerItem* , Prepend( wxSizerItem *item ), | |
726 | "PrependItem(self, SizerItem item)", | |
727 | "Prepends a `wx.SizerItem` to the sizer.", "", | |
728 | PrependItem); | |
729 | ||
730 | %cleardisown( wxSizerItem *item ); | |
731 | ||
732 | ||
733 | %pythoncode { | |
734 | def AddMany(self, items): | |
735 | """ | |
736 | AddMany is a convenience method for adding several items | |
737 | to a sizer at one time. Simply pass it a list of tuples, | |
738 | where each tuple consists of the parameters that you | |
739 | would normally pass to the `Add` method. | |
740 | """ | |
741 | for item in items: | |
742 | if type(item) != type(()) or (len(item) == 2 and type(item[0]) == type(1)): | |
743 | item = (item, ) | |
744 | self.Add(*item) | |
745 | ||
746 | %# for backwards compatibility only, please do not use in new code | |
747 | def AddWindow(self, *args, **kw): | |
748 | """Compatibility alias for `Add`.""" | |
749 | return self.Add(*args, **kw) | |
750 | def AddSizer(self, *args, **kw): | |
751 | """Compatibility alias for `Add`.""" | |
752 | return self.Add(*args, **kw) | |
753 | def AddSpacer(self, *args, **kw): | |
754 | """Compatibility alias for `Add`.""" | |
755 | return self.Add(*args, **kw) | |
756 | ||
757 | def PrependWindow(self, *args, **kw): | |
758 | """Compatibility alias for `Prepend`.""" | |
759 | return self.Prepend(*args, **kw) | |
760 | def PrependSizer(self, *args, **kw): | |
761 | """Compatibility alias for `Prepend`.""" | |
762 | return self.Prepend(*args, **kw) | |
763 | def PrependSpacer(self, *args, **kw): | |
764 | """Compatibility alias for `Prepend`.""" | |
765 | return self.Prepend(*args, **kw) | |
766 | ||
767 | def InsertWindow(self, *args, **kw): | |
768 | """Compatibility alias for `Insert`.""" | |
769 | return self.Insert(*args, **kw) | |
770 | def InsertSizer(self, *args, **kw): | |
771 | """Compatibility alias for `Insert`.""" | |
772 | return self.Insert(*args, **kw) | |
773 | def InsertSpacer(self, *args, **kw): | |
774 | """Compatibility alias for `Insert`.""" | |
775 | return self.Insert(*args, **kw) | |
776 | ||
777 | def RemoveWindow(self, *args, **kw): | |
778 | """Compatibility alias for `Remove`.""" | |
779 | return self.Remove(*args, **kw) | |
780 | def RemoveSizer(self, *args, **kw): | |
781 | """Compatibility alias for `Remove`.""" | |
782 | return self.Remove(*args, **kw) | |
783 | def RemovePos(self, *args, **kw): | |
784 | """Compatibility alias for `Remove`.""" | |
785 | return self.Remove(*args, **kw) | |
786 | ||
787 | } | |
788 | ||
789 | ||
790 | DocDeclStr( | |
791 | void , SetDimension( int x, int y, int width, int height ), | |
792 | "Call this to force the sizer to take the given dimension and thus | |
793 | force the items owned by the sizer to resize themselves according to | |
794 | the rules defined by the parameter in the `Add`, `Insert` or `Prepend` | |
795 | methods.", ""); | |
796 | ||
797 | DocDeclStr( | |
798 | void , SetMinSize( const wxSize &size ), | |
799 | "Call this to give the sizer a minimal size. Normally, the sizer will | |
800 | calculate its minimal size based purely on how much space its children | |
801 | need. After calling this method `GetMinSize` will return either the | |
802 | minimal size as requested by its children or the minimal size set | |
803 | here, depending on which is bigger.", ""); | |
804 | ||
805 | ||
806 | DocDeclStr( | |
807 | wxSize , GetSize(), | |
808 | "Returns the current size of the space managed by the sizer.", ""); | |
809 | ||
810 | DocDeclStr( | |
811 | wxPoint , GetPosition(), | |
812 | "Returns the current position of the sizer's managed space.", ""); | |
813 | ||
814 | DocDeclStr( | |
815 | wxSize , GetMinSize(), | |
816 | "Returns the minimal size of the sizer. This is either the combined | |
817 | minimal size of all the children and their borders or the minimal size | |
818 | set by SetMinSize, depending on which is bigger.", ""); | |
819 | ||
820 | ||
821 | %pythoncode { | |
822 | def GetSizeTuple(self): | |
823 | return self.GetSize().Get() | |
824 | def GetPositionTuple(self): | |
825 | return self.GetPosition().Get() | |
826 | def GetMinSizeTuple(self): | |
827 | return self.GetMinSize().Get() | |
828 | } | |
829 | ||
830 | DocDeclStr( | |
831 | virtual void , RecalcSizes(), | |
832 | "Using the sizes calculated by `CalcMin` reposition and resize all the | |
833 | items managed by this sizer. You should not need to call this directly as | |
834 | it is called by `Layout`.", ""); | |
835 | ||
836 | DocDeclStr( | |
837 | virtual wxSize , CalcMin(), | |
838 | "This method is where the sizer will do the actual calculation of its | |
839 | children's minimal sizes. You should not need to call this directly as | |
840 | it is called by `Layout`.", ""); | |
841 | ||
842 | ||
843 | DocDeclStr( | |
844 | void , Layout(), | |
845 | "This method will force the recalculation and layout of the items | |
846 | controlled by the sizer using the current space allocated to the | |
847 | sizer. Normally this is called automatically from the owning window's | |
848 | EVT_SIZE handler, but it is also useful to call it from user code when | |
849 | one of the items in a sizer change size, or items are added or | |
850 | removed.", ""); | |
851 | ||
852 | ||
853 | DocDeclStr( | |
854 | wxSize , Fit( wxWindow *window ), | |
855 | "Tell the sizer to resize the *window* to match the sizer's minimal | |
856 | size. This is commonly done in the constructor of the window itself in | |
857 | order to set its initial size to match the needs of the children as | |
858 | determined by the sizer. Returns the new size. | |
859 | ||
860 | For a top level window this is the total window size, not the client size.", ""); | |
861 | ||
862 | DocDeclStr( | |
863 | void , FitInside( wxWindow *window ), | |
864 | "Tell the sizer to resize the *virtual size* of the *window* to match the | |
865 | sizer's minimal size. This will not alter the on screen size of the | |
866 | window, but may cause the addition/removal/alteration of scrollbars | |
867 | required to view the virtual area in windows which manage it. | |
868 | ||
869 | :see: `wx.ScrolledWindow.SetScrollbars`, `SetVirtualSizeHints` | |
870 | ", ""); | |
871 | ||
872 | ||
873 | DocDeclStr( | |
874 | void , SetSizeHints( wxWindow *window ), | |
875 | "Tell the sizer to set (and `Fit`) the minimal size of the *window* to | |
876 | match the sizer's minimal size. This is commonly done in the | |
877 | constructor of the window itself if the window is resizable (as are | |
878 | many dialogs under Unix and frames on probably all platforms) in order | |
879 | to prevent the window from being sized smaller than the minimal size | |
880 | required by the sizer.", ""); | |
881 | ||
882 | DocDeclStr( | |
883 | void , SetVirtualSizeHints( wxWindow *window ), | |
884 | "Tell the sizer to set the minimal size of the window virtual area to | |
885 | match the sizer's minimal size. For windows with managed scrollbars | |
886 | this will set them appropriately. | |
887 | ||
888 | :see: `wx.ScrolledWindow.SetScrollbars` | |
889 | ", ""); | |
890 | ||
891 | ||
892 | DocDeclStr( | |
893 | void , Clear( bool deleteWindows=false ), | |
894 | "Clear all items from the sizer, optionally destroying the window items | |
895 | as well.", ""); | |
896 | ||
897 | DocDeclStr( | |
898 | void , DeleteWindows(), | |
899 | "Destroy all windows managed by the sizer.", ""); | |
900 | ||
901 | ||
902 | ||
903 | // wxList& GetChildren(); | |
904 | %extend { | |
905 | DocAStr(GetChildren, | |
906 | "GetChildren(self) -> list", | |
907 | "Returns a list of all the `wx.SizerItem` objects managed by the sizer.", ""); | |
908 | PyObject* GetChildren() { | |
909 | wxSizerItemList& list = self->GetChildren(); | |
910 | return wxPy_ConvertList(&list); | |
911 | } | |
912 | } | |
913 | ||
914 | ||
915 | // Manage whether individual windows or subsizers are considered | |
916 | // in the layout calculations or not. | |
917 | ||
918 | %extend { | |
919 | DocAStr(Show, | |
920 | "Show(self, item, bool show=True, bool recursive=false) -> bool", | |
921 | "Shows or hides an item managed by the sizer. To make a sizer item | |
922 | disappear or reappear, use Show followed by `Layout`. The *item* | |
923 | parameter can be either a window, a sizer, or the zero-based index of | |
924 | the item. Use the recursive parameter to show or hide an item in a | |
925 | subsizer. Returns True if the item was found.", ""); | |
926 | bool Show(PyObject* item, bool show = true, bool recursive=false) { | |
927 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
928 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true); | |
929 | wxPyEndBlockThreads(blocked); | |
930 | if ( info.window ) | |
931 | return self->Show(info.window, show, recursive); | |
932 | else if ( info.sizer ) | |
933 | return self->Show(info.sizer, show, recursive); | |
934 | else if ( info.gotPos ) | |
935 | return self->Show(info.pos, show); | |
936 | else | |
937 | return false; | |
938 | } | |
939 | ||
940 | DocAStr(IsShown, | |
941 | "IsShown(self, item)", | |
942 | "Determines if the item is currently shown. To make a sizer | |
943 | item disappear or reappear, use Show followed by `Layout`. The *item* | |
944 | parameter can be either a window, a sizer, or the zero-based index of | |
945 | the item.", ""); | |
946 | bool IsShown(PyObject* item) { | |
947 | wxPyBlock_t blocked = wxPyBeginBlockThreads(); | |
948 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, false); | |
949 | wxPyEndBlockThreads(blocked); | |
950 | if ( info.window ) | |
951 | return self->IsShown(info.window); | |
952 | else if ( info.sizer ) | |
953 | return self->IsShown(info.sizer); | |
954 | else if ( info.gotPos ) | |
955 | return self->IsShown(info.pos); | |
956 | else | |
957 | return false; | |
958 | } | |
959 | } | |
960 | ||
961 | %pythoncode { | |
962 | def Hide(self, item, recursive=False): | |
963 | """ | |
964 | A convenience method for `Show` (item, False, recursive). | |
965 | """ | |
966 | return self.Show(item, False, recursive) | |
967 | } | |
968 | ||
969 | ||
970 | DocDeclStr( | |
971 | void , ShowItems(bool show), | |
972 | "Recursively call `wx.SizerItem.Show` on all sizer items.", ""); | |
973 | ||
974 | }; | |
975 | ||
976 | ||
977 | //--------------------------------------------------------------------------- | |
978 | // Use this one for deriving Python classes from | |
979 | %{ | |
980 | // See pyclasses.h | |
981 | IMP_PYCALLBACK___pure(wxPySizer, wxSizer, RecalcSizes); | |
982 | IMP_PYCALLBACK_wxSize__pure(wxPySizer, wxSizer, CalcMin); | |
983 | IMPLEMENT_DYNAMIC_CLASS(wxPySizer, wxSizer); | |
984 | %} | |
985 | ||
986 | ||
987 | DocStr(wxPySizer, | |
988 | "wx.PySizer is a special version of `wx.Sizer` that has been | |
989 | instrumented to allow the C++ virtual methods to be overloaded in | |
990 | Python derived classes. You would derive from this class if you are | |
991 | wanting to implement a custom sizer in Python code. Simply implement | |
992 | `CalcMin` and `RecalcSizes` in the derived class and you're all set. | |
993 | For example:: | |
994 | ||
995 | class MySizer(wx.PySizer): | |
996 | def __init__(self): | |
997 | wx.PySizer.__init__(self) | |
998 | ||
999 | def CalcMin(self): | |
1000 | for item in self.GetChildren(): | |
1001 | # calculate the total minimum width and height needed | |
1002 | # by all items in the sizer according to this sizer's | |
1003 | # layout algorithm. | |
1004 | ... | |
1005 | return wx.Size(width, height) | |
1006 | ||
1007 | def RecalcSizes(self): | |
1008 | # find the space allotted to this sizer | |
1009 | pos = self.GetPosition() | |
1010 | size = self.GetSize() | |
1011 | for item in self.GetChildren(): | |
1012 | # Recalculate (if necessary) the position and size of | |
1013 | # each item and then call item.SetDimension to do the | |
1014 | # actual positioning and sizing of the items within the | |
1015 | # space alloted to this sizer. | |
1016 | ... | |
1017 | item.SetDimension(itemPos, itemSize) | |
1018 | ||
1019 | ||
1020 | When `Layout` is called it first calls `CalcMin` followed by | |
1021 | `RecalcSizes` so you can optimize a bit by saving the results of | |
1022 | `CalcMin` and reusing them in `RecalcSizes`. | |
1023 | ||
1024 | :see: `wx.SizerItem`, `wx.Sizer.GetChildren` | |
1025 | ||
1026 | ", ""); | |
1027 | class wxPySizer : public wxSizer { | |
1028 | public: | |
1029 | %pythonAppend wxPySizer "self._setCallbackInfo(self, PySizer);self._setOORInfo(self)" | |
1030 | ||
1031 | DocCtorStr( | |
1032 | wxPySizer(), | |
1033 | "Creates a wx.PySizer. Must be called from the __init__ in the derived | |
1034 | class.", ""); | |
1035 | ||
1036 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
1037 | }; | |
1038 | ||
1039 | ||
1040 | //--------------------------------------------------------------------------- | |
1041 | %newgroup; | |
1042 | ||
1043 | ||
1044 | DocStr(wxBoxSizer, | |
1045 | "The basic idea behind a box sizer is that windows will most often be | |
1046 | laid out in rather simple basic geometry, typically in a row or a | |
1047 | column or nested hierarchies of either. A wx.BoxSizer will lay out | |
1048 | its items in a simple row or column, depending on the orientation | |
1049 | parameter passed to the constructor.", " | |
1050 | ||
1051 | It is the unique feature of a box sizer, that it can grow in both | |
1052 | directions (height and width) but can distribute its growth in the | |
1053 | main direction (horizontal for a row) *unevenly* among its children. | |
1054 | This is determined by the proportion parameter give to items when they | |
1055 | are added to the sizer. It is interpreted as a weight factor, i.e. it | |
1056 | can be zero, indicating that the window may not be resized at all, or | |
1057 | above zero. If several windows have a value above zero, the value is | |
1058 | interpreted relative to the sum of all weight factors of the sizer, so | |
1059 | when adding two windows with a value of 1, they will both get resized | |
1060 | equally and each will receive half of the available space after the | |
1061 | fixed size items have been sized. If the items have unequal | |
1062 | proportion settings then they will receive a coresondingly unequal | |
1063 | allotment of the free space. | |
1064 | ||
1065 | :see: `wx.StaticBoxSizer` | |
1066 | "); | |
1067 | ||
1068 | class wxBoxSizer : public wxSizer { | |
1069 | public: | |
1070 | %pythonAppend wxBoxSizer "self._setOORInfo(self)" | |
1071 | ||
1072 | DocCtorStr( | |
1073 | wxBoxSizer(int orient = wxHORIZONTAL), | |
1074 | "Constructor for a wx.BoxSizer. *orient* may be one of ``wx.VERTICAL`` | |
1075 | or ``wx.HORIZONTAL`` for creating either a column sizer or a row | |
1076 | sizer.", ""); | |
1077 | ||
1078 | ||
1079 | DocDeclStr( | |
1080 | int , GetOrientation(), | |
1081 | "Returns the current orientation of the sizer.", ""); | |
1082 | ||
1083 | DocDeclStr( | |
1084 | void , SetOrientation(int orient), | |
1085 | "Resets the orientation of the sizer.", ""); | |
1086 | ||
1087 | }; | |
1088 | ||
1089 | //--------------------------------------------------------------------------- | |
1090 | %newgroup; | |
1091 | ||
1092 | ||
1093 | DocStr(wxStaticBoxSizer, | |
1094 | "wx.StaticBoxSizer derives from and functions identically to the | |
1095 | `wx.BoxSizer` and adds a `wx.StaticBox` around the items that the sizer | |
1096 | manages. Note that this static box must be created separately and | |
1097 | passed to the sizer constructor.", ""); | |
1098 | ||
1099 | class wxStaticBoxSizer : public wxBoxSizer { | |
1100 | public: | |
1101 | %pythonAppend wxStaticBoxSizer "self._setOORInfo(self)" | |
1102 | ||
1103 | DocCtorStr( | |
1104 | wxStaticBoxSizer(wxStaticBox *box, int orient = wxHORIZONTAL), | |
1105 | "Constructor. It takes an associated static box and the orientation | |
1106 | *orient* as parameters - orient can be either of ``wx.VERTICAL`` or | |
1107 | ``wx.HORIZONTAL``.", ""); | |
1108 | ||
1109 | // TODO: wxStaticBoxSizer(int orient, wxWindow *win, const wxString& label = wxEmptyString); | |
1110 | ||
1111 | DocDeclStr( | |
1112 | wxStaticBox *, GetStaticBox(), | |
1113 | "Returns the static box associated with this sizer.", ""); | |
1114 | ||
1115 | }; | |
1116 | ||
1117 | //--------------------------------------------------------------------------- | |
1118 | %newgroup; | |
1119 | ||
1120 | ||
1121 | DocStr(wxGridSizer, | |
1122 | "A grid sizer is a sizer which lays out its children in a | |
1123 | two-dimensional table with all cells having the same size. In other | |
1124 | words, the width of each cell within the grid is the width of the | |
1125 | widest item added to the sizer and the height of each grid cell is the | |
1126 | height of the tallest item. An optional vertical and/or horizontal | |
1127 | gap between items can also be specified (in pixels.) | |
1128 | ||
1129 | Items are placed in the cells of the grid in the order they are added, | |
1130 | in row-major order. In other words, the first row is filled first, | |
1131 | then the second, and so on until all items have been added. (If | |
1132 | neccessary, additional rows will be added as items are added.) If you | |
1133 | need to have greater control over the cells that items are placed in | |
1134 | then use the `wx.GridBagSizer`. | |
1135 | ", ""); | |
1136 | ||
1137 | class wxGridSizer: public wxSizer | |
1138 | { | |
1139 | public: | |
1140 | %pythonAppend wxGridSizer "self._setOORInfo(self)" | |
1141 | ||
1142 | DocCtorStr( | |
1143 | wxGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 ), | |
1144 | "Constructor for a wx.GridSizer. *rows* and *cols* determine the number | |
1145 | of columns and rows in the sizer - if either of the parameters is | |
1146 | zero, it will be calculated to from the total number of children in | |
1147 | the sizer, thus making the sizer grow dynamically. *vgap* and *hgap* | |
1148 | define extra space between all children.", ""); | |
1149 | ||
1150 | DocDeclStr( | |
1151 | void , SetCols( int cols ), | |
1152 | "Sets the number of columns in the sizer.", ""); | |
1153 | ||
1154 | DocDeclStr( | |
1155 | void , SetRows( int rows ), | |
1156 | "Sets the number of rows in the sizer.", ""); | |
1157 | ||
1158 | DocDeclStr( | |
1159 | void , SetVGap( int gap ), | |
1160 | "Sets the vertical gap (in pixels) between the cells in the sizer.", ""); | |
1161 | ||
1162 | DocDeclStr( | |
1163 | void , SetHGap( int gap ), | |
1164 | "Sets the horizontal gap (in pixels) between cells in the sizer", ""); | |
1165 | ||
1166 | DocDeclStr( | |
1167 | int , GetCols(), | |
1168 | "Returns the number of columns in the sizer.", ""); | |
1169 | ||
1170 | DocDeclStr( | |
1171 | int , GetRows(), | |
1172 | "Returns the number of rows in the sizer.", ""); | |
1173 | ||
1174 | DocDeclStr( | |
1175 | int , GetVGap(), | |
1176 | "Returns the vertical gap (in pixels) between the cells in the sizer.", ""); | |
1177 | ||
1178 | DocDeclStr( | |
1179 | int , GetHGap(), | |
1180 | "Returns the horizontal gap (in pixels) between cells in the sizer.", ""); | |
1181 | ||
1182 | %pythoncode { | |
1183 | def CalcRowsCols(self): | |
1184 | """ | |
1185 | CalcRowsCols() -> (rows, cols) | |
1186 | ||
1187 | Calculates how many rows and columns will be in the sizer based | |
1188 | on the current number of items and also the rows, cols specified | |
1189 | in the constructor. | |
1190 | """ | |
1191 | nitems = len(self.GetChildren()) | |
1192 | rows = self.GetRows() | |
1193 | cols = self.GetCols() | |
1194 | assert rows != 0 or cols != 0, "Grid sizer must have either rows or columns fixed" | |
1195 | if cols != 0: | |
1196 | rows = (nitems + cols - 1) / cols | |
1197 | elif rows != 0: | |
1198 | cols = (nitems + rows - 1) / rows | |
1199 | return (rows, cols) | |
1200 | } | |
1201 | }; | |
1202 | ||
1203 | //--------------------------------------------------------------------------- | |
1204 | %newgroup; | |
1205 | ||
1206 | enum wxFlexSizerGrowMode | |
1207 | { | |
1208 | // don't resize the cells in non-flexible direction at all | |
1209 | wxFLEX_GROWMODE_NONE, | |
1210 | ||
1211 | // uniformly resize only the specified ones (default) | |
1212 | wxFLEX_GROWMODE_SPECIFIED, | |
1213 | ||
1214 | // uniformly resize all cells | |
1215 | wxFLEX_GROWMODE_ALL | |
1216 | }; | |
1217 | ||
1218 | ||
1219 | ||
1220 | ||
1221 | ||
1222 | DocStr(wxFlexGridSizer, | |
1223 | "A flex grid sizer is a sizer which lays out its children in a | |
1224 | two-dimensional table with all table cells in one row having the same | |
1225 | height and all cells in one column having the same width, but all | |
1226 | rows or all columns are not necessarily the same height or width as in | |
1227 | the `wx.GridSizer`. | |
1228 | ||
1229 | wx.FlexGridSizer can also size items equally in one direction but | |
1230 | unequally (\"flexibly\") in the other. If the sizer is only flexible | |
1231 | in one direction (this can be changed using `SetFlexibleDirection`), it | |
1232 | needs to be decided how the sizer should grow in the other (\"non | |
1233 | flexible\") direction in order to fill the available space. The | |
1234 | `SetNonFlexibleGrowMode` method serves this purpose. | |
1235 | ||
1236 | ", ""); | |
1237 | ||
1238 | class wxFlexGridSizer: public wxGridSizer | |
1239 | { | |
1240 | public: | |
1241 | %pythonAppend wxFlexGridSizer "self._setOORInfo(self)" | |
1242 | ||
1243 | DocCtorStr( | |
1244 | wxFlexGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 ), | |
1245 | "Constructor for a wx.FlexGridSizer. *rows* and *cols* determine the | |
1246 | number of columns and rows in the sizer - if either of the parameters | |
1247 | is zero, it will be calculated to from the total number of children in | |
1248 | the sizer, thus making the sizer grow dynamically. *vgap* and *hgap* | |
1249 | define extra space between all children.", ""); | |
1250 | ||
1251 | ||
1252 | DocDeclStr( | |
1253 | void , AddGrowableRow( size_t idx, int proportion = 0 ), | |
1254 | "Specifies that row *idx* (starting from zero) should be grown if there | |
1255 | is extra space available to the sizer. | |
1256 | ||
1257 | The *proportion* parameter has the same meaning as the stretch factor | |
1258 | for the box sizers except that if all proportions are 0, then all | |
1259 | columns are resized equally (instead of not being resized at all).", ""); | |
1260 | ||
1261 | DocDeclStr( | |
1262 | void , RemoveGrowableRow( size_t idx ), | |
1263 | "Specifies that row *idx* is no longer growable.", ""); | |
1264 | ||
1265 | DocDeclStr( | |
1266 | void , AddGrowableCol( size_t idx, int proportion = 0 ), | |
1267 | "Specifies that column *idx* (starting from zero) should be grown if | |
1268 | there is extra space available to the sizer. | |
1269 | ||
1270 | The *proportion* parameter has the same meaning as the stretch factor | |
1271 | for the box sizers except that if all proportions are 0, then all | |
1272 | columns are resized equally (instead of not being resized at all).", ""); | |
1273 | ||
1274 | DocDeclStr( | |
1275 | void , RemoveGrowableCol( size_t idx ), | |
1276 | "Specifies that column *idx* is no longer growable.", ""); | |
1277 | ||
1278 | ||
1279 | DocDeclStr( | |
1280 | void , SetFlexibleDirection(int direction), | |
1281 | "Specifies whether the sizer should flexibly resize its columns, rows, | |
1282 | or both. Argument *direction* can be one of the following values. Any | |
1283 | other value is ignored. | |
1284 | ||
1285 | ============== ======================================= | |
1286 | wx.VERTICAL Rows are flexibly sized. | |
1287 | wx.HORIZONTAL Columns are flexibly sized. | |
1288 | wx.BOTH Both rows and columns are flexibly sized | |
1289 | (this is the default value). | |
1290 | ============== ======================================= | |
1291 | ||
1292 | Note that this method does not trigger relayout. | |
1293 | ", ""); | |
1294 | ||
1295 | DocDeclStr( | |
1296 | int , GetFlexibleDirection(), | |
1297 | "Returns a value that specifies whether the sizer | |
1298 | flexibly resizes its columns, rows, or both (default). | |
1299 | ||
1300 | :see: `SetFlexibleDirection`", ""); | |
1301 | ||
1302 | ||
1303 | ||
1304 | DocDeclStr( | |
1305 | void , SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode), | |
1306 | "Specifies how the sizer should grow in the non-flexible direction if | |
1307 | there is one (so `SetFlexibleDirection` must have been called | |
1308 | previously). Argument *mode* can be one of the following values: | |
1309 | ||
1310 | ========================== ================================================= | |
1311 | wx.FLEX_GROWMODE_NONE Sizer doesn't grow in the non flexible direction. | |
1312 | wx.FLEX_GROWMODE_SPECIFIED Sizer honors growable columns/rows set with | |
1313 | `AddGrowableCol` and `AddGrowableRow`. In this | |
1314 | case equal sizing applies to minimum sizes of | |
1315 | columns or rows (this is the default value). | |
1316 | wx.FLEX_GROWMODE_ALL Sizer equally stretches all columns or rows in | |
1317 | the non flexible direction, whether they are | |
1318 | growable or not in the flexbile direction. | |
1319 | ========================== ================================================= | |
1320 | ||
1321 | Note that this method does not trigger relayout. | |
1322 | ||
1323 | ", ""); | |
1324 | ||
1325 | DocDeclStr( | |
1326 | wxFlexSizerGrowMode , GetNonFlexibleGrowMode(), | |
1327 | "Returns the value that specifies how the sizer grows in the | |
1328 | non-flexible direction if there is one. | |
1329 | ||
1330 | :see: `SetNonFlexibleGrowMode`", ""); | |
1331 | ||
1332 | ||
1333 | // Read-only access to the row heights and col widths arrays | |
1334 | DocDeclAStr( | |
1335 | const wxArrayInt& , GetRowHeights() const, | |
1336 | "GetRowHeights(self) -> list", | |
1337 | "Returns a list of integers representing the heights of each of the | |
1338 | rows in the sizer.", ""); | |
1339 | ||
1340 | DocDeclAStr( | |
1341 | const wxArrayInt& , GetColWidths() const, | |
1342 | "GetColWidths(self) -> list", | |
1343 | "Returns a list of integers representing the widths of each of the | |
1344 | columns in the sizer.", ""); | |
1345 | ||
1346 | }; | |
1347 | ||
1348 | //--------------------------------------------------------------------------- | |
1349 | ||
1350 | DocStr(wxStdDialogButtonSizer, | |
1351 | "A special sizer that knows how to order and position standard buttons | |
1352 | in order to conform to the current platform's standards. You simply | |
1353 | need to add each `wx.Button` to the sizer, and be sure to create the | |
1354 | buttons using the standard ID's. Then call `Realize` and the sizer | |
1355 | will take care of the rest. | |
1356 | ", ""); | |
1357 | ||
1358 | class wxStdDialogButtonSizer: public wxBoxSizer | |
1359 | { | |
1360 | public: | |
1361 | DocCtorStr( | |
1362 | wxStdDialogButtonSizer(), | |
1363 | "", ""); | |
1364 | ||
1365 | DocDeclStr( | |
1366 | void , AddButton(wxButton *button), | |
1367 | "Use this to add the buttons to this sizer. Do not use the `Add` | |
1368 | method in the base class.", ""); | |
1369 | ||
1370 | DocDeclStr( | |
1371 | void , Realize(), | |
1372 | "This funciton needs to be called after all the buttons have been added | |
1373 | to the sizer. It will reorder them and position them in a platform | |
1374 | specifc manner.", ""); | |
1375 | ||
1376 | void SetAffirmativeButton( wxButton *button ); | |
1377 | void SetNegativeButton( wxButton *button ); | |
1378 | void SetCancelButton( wxButton *button ); | |
1379 | ||
1380 | wxButton* GetAffirmativeButton() const; | |
1381 | wxButton* GetApplyButton() const; | |
1382 | wxButton* GetNegativeButton() const; | |
1383 | wxButton* GetCancelButton() const; | |
1384 | wxButton* GetHelpButton() const; | |
1385 | }; | |
1386 | ||
1387 | ||
1388 | //--------------------------------------------------------------------------- |