]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_gbsizer.i
log wxChoice events in the same format as wxComboBox ones to make it simpler to compa...
[wxWidgets.git] / wxPython / src / _gbsizer.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _gbsizer.i
3 // Purpose: SWIG interface stuff for wxGBGridBagSizer and etc.
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 05-Nov-2003
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
23 %typemap(in) wxGBPosition& (wxGBPosition temp) {
24 $1 = &temp;
25 if ( ! wxGBPosition_helper($input, &$1)) SWIG_fail;
26 }
27 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGBPosition& {
28 $1 = wxPySimple_typecheck($input, wxT("wxGBPosition"), 2);
29 }
30
31 %typemap(in) wxGBSpan& (wxGBSpan temp) {
32 $1 = &temp;
33 if ( ! wxGBSpan_helper($input, &$1)) SWIG_fail;
34 }
35 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGBSpan& {
36 $1 = wxPySimple_typecheck($input, wxT("wxGBSpan"), 2);
37 }
38
39
40 %{
41 bool wxGBPosition_helper(PyObject* source, wxGBPosition** obj)
42 {
43 if (source == Py_None) {
44 **obj = wxGBPosition(-1,-1);
45 return true;
46 }
47 return wxPyTwoIntItem_helper(source, obj, wxT("wxGBPosition"));
48 }
49
50 bool wxGBSpan_helper(PyObject* source, wxGBSpan** obj)
51 {
52 if (source == Py_None) {
53 **obj = wxGBSpan(-1,-1);
54 return true;
55 }
56 return wxPyTwoIntItem_helper(source, obj, wxT("wxGBSpan"));
57 }
58
59 %}
60
61
62 //---------------------------------------------------------------------------
63 %newgroup;
64
65 DocStr(wxGBPosition,
66 "This class represents the position of an item in a virtual grid of
67 rows and columns managed by a `wx.GridBagSizer`. wxPython has
68 typemaps that will automatically convert from a 2-element sequence of
69 integers to a wx.GBPosition, so you can use the more pythonic
70 representation of the position nearly transparently in Python code.", "");
71
72 class wxGBPosition
73 {
74 public:
75 wxGBPosition(int row=0, int col=0);
76 ~wxGBPosition();
77
78 int GetRow() const;
79 int GetCol() const;
80 void SetRow(int row);
81 void SetCol(int col);
82
83 // %extend {
84 // bool __eq__(const wxGBPosition* other) { return other ? (*self == *other) : false; }
85 // bool __ne__(const wxGBPosition* other) { return other ? (*self != *other) : true; }
86 // }
87
88 bool operator==(const wxGBPosition& other);
89 bool operator!=(const wxGBPosition& other);
90
91 %extend {
92 void Set(int row=0, int col=0) {
93 self->SetRow(row);
94 self->SetCol(col);
95 }
96
97 PyObject* Get() {
98 wxPyBlock_t blocked = wxPyBeginBlockThreads();
99 PyObject* tup = PyTuple_New(2);
100 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
101 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
102 wxPyEndBlockThreads(blocked);
103 return tup;
104 }
105 }
106 %pythoncode {
107 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
108 def __str__(self): return str(self.Get())
109 def __repr__(self): return 'wx.GBPosition'+str(self.Get())
110 def __len__(self): return len(self.Get())
111 def __getitem__(self, index): return self.Get()[index]
112 def __setitem__(self, index, val):
113 if index == 0: self.SetRow(val)
114 elif index == 1: self.SetCol(val)
115 else: raise IndexError
116 def __nonzero__(self): return self.Get() != (0,0)
117 __safe_for_unpickling__ = True
118 def __reduce__(self): return (wx.GBPosition, self.Get())
119 }
120
121 %pythoncode {
122 row = property(GetRow, SetRow)
123 col = property(GetCol, SetCol)
124 }
125 };
126
127
128
129
130 DocStr(wxGBSpan,
131 "This class is used to hold the row and column spanning attributes of
132 items in a `wx.GridBagSizer`. wxPython has typemaps that will
133 automatically convert from a 2-element sequence of integers to a
134 wx.GBSpan, so you can use the more pythonic representation of the span
135 nearly transparently in Python code.
136 ", "");
137
138 class wxGBSpan
139 {
140 public:
141 DocCtorStr(
142 wxGBSpan(int rowspan=1, int colspan=1),
143 "Construct a new wxGBSpan, optionally setting the rowspan and
144 colspan. The default is (1,1). (Meaning that the item occupies one
145 cell in each direction.", "");
146
147 ~wxGBSpan();
148
149 int GetRowspan() const;
150 int GetColspan() const;
151 void SetRowspan(int rowspan);
152 void SetColspan(int colspan);
153
154 // %extend {
155 // bool __eq__(const wxGBSpan* other) { return other ? (*self == *other) : false; }
156 // bool __ne__(const wxGBSpan* other) { return other ? (*self != *other) : true; }
157 // }
158 bool operator==(const wxGBSpan& other);
159 bool operator!=(const wxGBSpan& other);
160
161
162 %extend {
163 void Set(int rowspan=1, int colspan=1) {
164 self->SetRowspan(rowspan);
165 self->SetColspan(colspan);
166 }
167
168 PyObject* Get() {
169 wxPyBlock_t blocked = wxPyBeginBlockThreads();
170 PyObject* tup = PyTuple_New(2);
171 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRowspan()));
172 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetColspan()));
173 wxPyEndBlockThreads(blocked);
174 return tup;
175 }
176 }
177 %pythoncode {
178 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
179 def __str__(self): return str(self.Get())
180 def __repr__(self): return 'wx.GBSpan'+str(self.Get())
181 def __len__(self): return len(self.Get())
182 def __getitem__(self, index): return self.Get()[index]
183 def __setitem__(self, index, val):
184 if index == 0: self.SetRowspan(val)
185 elif index == 1: self.SetColspan(val)
186 else: raise IndexError
187 def __nonzero__(self): return self.Get() != (0,0)
188 __safe_for_unpickling__ = True
189 def __reduce__(self): return (wx.GBSpan, self.Get())
190 }
191
192 %pythoncode {
193 rowspan = property(GetRowspan, SetRowspan)
194 colspan = property(GetColspan, SetColspan)
195 }
196 };
197
198
199 %immutable;
200 const wxGBSpan wxDefaultSpan;
201 %mutable;
202
203
204 //---------------------------------------------------------------------------
205
206
207 DocStr(wxGBSizerItem,
208 "The wx.GBSizerItem class is used to track the additional data about
209 items in a `wx.GridBagSizer` such as the item's position in the grid
210 and how many rows or columns it spans.
211 ", "");
212 class wxGBSizerItem : public wxSizerItem
213 {
214 public:
215 DocCtorStr(
216 wxGBSizerItem(),
217 "Constructs an empty wx.GBSizerItem. Either a window, sizer or spacer
218 size will need to be set, as well as a position and span before this
219 item can be used in a Sizer.
220
221 You will probably never need to create a wx.GBSizerItem directly as they
222 are created automatically when the sizer's Add method is called.", "");
223
224 ~wxGBSizerItem();
225
226
227 %extend {
228 DocStr(wxGBSizerItem( wxWindow *window, const wxGBPosition& pos,const wxGBSpan& span,int flag,int border,PyObject* userData=NULL ),
229 "Construct a `wx.GBSizerItem` for a window.", "");
230
231 %RenameCtor(GBSizerItemWindow, wxGBSizerItem( wxWindow *window,
232 const wxGBPosition& pos,
233 const wxGBSpan& span,
234 int flag,
235 int border,
236 PyObject* userData=NULL ))
237 {
238 wxPyUserData* data = NULL;
239 if ( userData ) {
240 wxPyBlock_t blocked = wxPyBeginBlockThreads();
241 data = new wxPyUserData(userData);
242 wxPyEndBlockThreads(blocked);
243 }
244 return new wxGBSizerItem(window, pos, span, flag, border, data);
245 }
246
247
248 DocStr(wxGBSizerItem( wxSizer *sizer,const wxGBPosition& pos,const wxGBSpan& span,int flag,int border,PyObject* userData=NULL ),
249 "Construct a `wx.GBSizerItem` for a sizer", "");
250 %disownarg( wxSizer *sizer );
251 %RenameCtor(GBSizerItemSizer, wxGBSizerItem( wxSizer *sizer,
252 const wxGBPosition& pos,
253 const wxGBSpan& span,
254 int flag,
255 int border,
256 PyObject* userData=NULL ))
257 {
258 wxPyUserData* data = NULL;
259 if ( userData ) {
260 wxPyBlock_t blocked = wxPyBeginBlockThreads();
261 data = new wxPyUserData(userData);
262 wxPyEndBlockThreads(blocked);
263 }
264 return new wxGBSizerItem(sizer, pos, span, flag, border, data);
265 }
266 %cleardisown( wxSizer *sizer );
267
268
269 DocStr(wxGBSizerItem( int width,int height,const wxGBPosition& pos,const wxGBSpan& span,int flag,int border,PyObject* userData=NULL),
270 "Construct a `wx.GBSizerItem` for a spacer.", "");
271 %RenameCtor(GBSizerItemSpacer, wxGBSizerItem( int width,
272 int height,
273 const wxGBPosition& pos,
274 const wxGBSpan& span,
275 int flag,
276 int border,
277 PyObject* userData=NULL))
278 {
279 wxPyUserData* data = NULL;
280 if ( userData ) {
281 wxPyBlock_t blocked = wxPyBeginBlockThreads();
282 data = new wxPyUserData(userData);
283 wxPyEndBlockThreads(blocked);
284 }
285 return new wxGBSizerItem(width, height, pos, span, flag, border, data);
286 }
287 }
288
289
290 DocDeclStr(
291 wxGBPosition , GetPos() const,
292 "Get the grid position of the item", "");
293
294 %pythoncode { def GetPosTuple(self): return self.GetPos().Get() }
295
296
297
298 DocDeclStr(
299 wxGBSpan , GetSpan() const,
300 "Get the row and column spanning of the item", "");
301
302 %pythoncode { def GetSpanTuple(self): return self.GetSpan().Get() }
303
304
305
306 DocDeclStr(
307 bool , SetPos( const wxGBPosition& pos ),
308 "If the item is already a member of a sizer then first ensure that
309 there is no other item that would intersect with this one at the new
310 position, then set the new position. Returns True if the change is
311 successful and after the next Layout() the item will be moved.", "");
312
313
314 DocDeclStr(
315 bool , SetSpan( const wxGBSpan& span ),
316 "If the item is already a member of a sizer then first ensure that
317 there is no other item that would intersect with this one with its new
318 spanning size, then set the new spanning. Returns True if the change
319 is successful and after the next Layout() the item will be resized.
320 ", "");
321
322
323
324 DocDeclStr(
325 bool , Intersects(const wxGBSizerItem& other),
326 "Returns True if this item and the other item instersect.", "");
327
328
329 DocDeclStrName(
330 bool , Intersects(const wxGBPosition& pos, const wxGBSpan& span),
331 "Returns True if the given pos/span would intersect with this item.", "",
332 IntersectsPos);
333
334
335 %extend {
336 DocStr(GetEndPos,
337 "Get the row and column of the endpoint of this item.", "");
338 wxGBPosition GetEndPos() {
339 int row, col;
340 self->GetEndPos(row, col);
341 return wxGBPosition(row, col);
342 }
343 }
344
345
346 DocDeclStr(
347 wxGridBagSizer* , GetGBSizer() const,
348 "Get the sizer this item is a member of.", "");
349
350 DocDeclStr(
351 void , SetGBSizer(wxGridBagSizer* sizer),
352 "Set the sizer this item is a member of.", "");
353
354 };
355
356
357 //---------------------------------------------------------------------------
358
359 DocStr(wxGridBagSizer,
360 "A `wx.Sizer` that can lay out items in a virtual grid like a
361 `wx.FlexGridSizer` but in this case explicit positioning of the items
362 is allowed using `wx.GBPosition`, and items can optionally span more
363 than one row and/or column using `wx.GBSpan`. The total size of the
364 virtual grid is determined by the largest row and column that items are
365 positioned at, adjusted for spanning.
366 ", "");
367
368 class wxGridBagSizer : public wxFlexGridSizer
369 {
370 public:
371 %pythonAppend wxGridBagSizer "self._setOORInfo(self)"
372
373 DocCtorStr(
374 wxGridBagSizer(int vgap = 0, int hgap = 0 ),
375 "Constructor, with optional parameters to specify the gap between the
376 rows and columns.", "");
377
378
379 %extend {
380 DocAStr(Add,
381 "Add(self, item, GBPosition pos, GBSpan span=DefaultSpan, int flag=0,
382 int border=0, userData=None) -> wx.GBSizerItem",
383
384 "Adds an item to the sizer at the grid cell *pos*, optionally spanning
385 more than one row or column as specified with *span*. The remaining
386 args behave similarly to `wx.Sizer.Add`.
387
388 Returns True if the item was successfully placed at the given cell
389 position, False if something was already there.
390 ", "");
391 wxGBSizerItem* Add( PyObject* item,
392 const wxGBPosition& pos,
393 const wxGBSpan& span = wxDefaultSpan,
394 int flag = 0,
395 int border = 0,
396 PyObject* userData = NULL ) {
397
398 wxPyUserData* data = NULL;
399 wxPyBlock_t blocked = wxPyBeginBlockThreads();
400 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false);
401 if ( userData && (info.window || info.sizer || info.gotSize) )
402 data = new wxPyUserData(userData);
403 if ( info.sizer )
404 PyObject_SetAttrString(item,"thisown",Py_False);
405 wxPyEndBlockThreads(blocked);
406
407 // Now call the real Add method if a valid item type was found
408 if ( info.window )
409 return (wxGBSizerItem*)self->Add(info.window, pos, span, flag, border, data);
410 else if ( info.sizer )
411 return (wxGBSizerItem*)self->Add(info.sizer, pos, span, flag, border, data);
412 else if (info.gotSize)
413 return (wxGBSizerItem*)self->Add(info.size.GetWidth(), info.size.GetHeight(),
414 pos, span, flag, border, data);
415 return NULL;
416 }
417 }
418
419 %disownarg( wxGBSizerItem *item );
420 DocDeclAStrName(
421 wxGBSizerItem* , Add( wxGBSizerItem *item ),
422 "Add(self, GBSizerItem item) -> wx.GBSizerItem",
423 "Add an item to the sizer using a `wx.GBSizerItem`. Returns True if
424 the item was successfully placed at its given cell position, False if
425 something was already there.", "",
426 AddItem);
427 %cleardisown( wxGBSizerItem *item );
428
429 DocDeclStr(
430 wxSize , GetCellSize(int row, int col) const,
431 "Get the size of the specified cell, including hgap and
432 vgap. Only valid after a Layout.", "");
433
434 DocDeclStr(
435 wxSize , GetEmptyCellSize() const,
436 "Get the size used for cells in the grid with no item.", "");
437
438 DocDeclStr(
439 void , SetEmptyCellSize(const wxSize& sz),
440 "Set the size used for cells in the grid with no item.", "");
441
442
443
444 %nokwargs GetItemPosition;
445 %noautodoc GetItemPosition;
446 DocStr(GetItemPosition,
447 "GetItemPosition(self, item) -> GBPosition
448
449 Get the grid position of the specified *item* where *item* is either a
450 window or subsizer that is a member of this sizer, or a zero-based
451 index of an item.", "");
452 wxGBPosition GetItemPosition(wxWindow *window);
453 wxGBPosition GetItemPosition(wxSizer *sizer);
454 wxGBPosition GetItemPosition(size_t index);
455
456
457 %nokwargs SetItemPosition;
458 %noautodoc SetItemPosition;
459 DocStr(SetItemPosition,
460 "SetItemPosition(self, item, GBPosition pos) -> bool
461
462 Set the grid position of the specified *item* where *item* is either a
463 window or subsizer that is a member of this sizer, or a zero-based
464 index of an item. Returns True on success. If the move is not
465 allowed (because an item is already there) then False is returned.
466 ", "");
467 bool SetItemPosition(wxWindow *window, const wxGBPosition& pos);
468 bool SetItemPosition(wxSizer *sizer, const wxGBPosition& pos);
469 bool SetItemPosition(size_t index, const wxGBPosition& pos);
470
471
472
473 %nokwargs GetItemSpan;
474 %noautodoc GetItemSpan;
475 DocStr(GetItemSpan,
476 "GetItemSpan(self, item) -> GBSpan
477
478 Get the row/col spanning of the specified *item* where *item* is
479 either a window or subsizer that is a member of this sizer, or a
480 zero-based index of an item.", "");
481 wxGBSpan GetItemSpan(wxWindow *window);
482 wxGBSpan GetItemSpan(wxSizer *sizer);
483 wxGBSpan GetItemSpan(size_t index);
484
485
486
487 %nokwargs SetItemSpan;
488 %noautodoc SetItemSpan;
489 DocStr(SetItemSpan,
490 "SetItemSpan(self, item, GBSpan span) -> bool
491
492 Set the row/col spanning of the specified *item* where *item* is
493 either a window or subsizer that is a member of this sizer, or a
494 zero-based index of an item. Returns True on success. If the move is
495 not allowed (because an item is already there) then False is returned.", "");
496 bool SetItemSpan(wxWindow *window, const wxGBSpan& span);
497 bool SetItemSpan(wxSizer *sizer, const wxGBSpan& span);
498 bool SetItemSpan(size_t index, const wxGBSpan& span);
499
500
501
502 %nokwargs FindItem;
503 %noautodoc FindItem;
504 DocStr(FindItem,
505 "FindItem(self, item) -> GBSizerItem
506
507 Find the sizer item for the given window or subsizer, returns None if
508 not found. (non-recursive)", "");
509 wxGBSizerItem* FindItem(wxWindow* window);
510 wxGBSizerItem* FindItem(wxSizer* sizer);
511
512
513 DocDeclStr(
514 wxGBSizerItem* , FindItemAtPosition(const wxGBPosition& pos),
515 "Return the sizer item for the given grid cell, or None if there is no
516 item at that position. (non-recursive)", "");
517
518
519
520 DocDeclStr(
521 wxGBSizerItem* , FindItemAtPoint(const wxPoint& pt),
522 "Return the sizer item located at the point given in *pt*, or None if
523 there is no item at that point. The (x,y) coordinates in pt correspond
524 to the client coordinates of the window using the sizer for
525 layout. (non-recursive)", "");
526
527
528
529 // DocDeclStr(
530 // wxGBSizerItem* , FindItemWithData(const wxObject* userData),
531 // "Return the sizer item that has a matching user data (it only compares
532 // pointer values) or None if not found. (non-recursive)", "");
533
534
535
536 // Look at all items and see if any intersect (or would overlap) the given
537 // item. Returns True if so, False if there would be no overlap. If an
538 // excludeItem is given then it will not be checked for intersection, for
539 // example it may be the item we are checking the position of.
540
541
542 DocDeclStr(
543 bool , CheckForIntersection(wxGBSizerItem* item, wxGBSizerItem* excludeItem = NULL),
544 "Look at all items and see if any intersect (or would overlap) the
545 given *item*. Returns True if so, False if there would be no overlap.
546 If an *excludeItem* is given then it will not be checked for
547 intersection, for example it may be the item we are checking the
548 position of.
549 ", "");
550
551 DocDeclStrName(
552 bool , CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span, wxGBSizerItem* excludeItem = NULL),
553 "Look at all items and see if any intersect (or would overlap) the
554 given position and span. Returns True if so, False if there would be
555 no overlap. If an *excludeItem* is given then it will not be checked
556 for intersection, for example it may be the item we are checking the
557 position of.", "",
558 CheckForIntersectionPos);
559
560
561 };
562
563
564 //---------------------------------------------------------------------------