]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/sizers.i
added functions to read/write several elements at once (patch 754986)
[wxWidgets.git] / wxPython / src / sizers.i
index b841dd758ce01fd5bb06004ef5a91cb3bcfef9b3..ffa534b533d8035dcc9ac4f29b941d1527f45c7a 100644 (file)
@@ -101,6 +101,7 @@ public:
 
 //---------------------------------------------------------------------------
 
 
 //---------------------------------------------------------------------------
 
+
 class wxSizer : public wxObject {
 public:
     // wxSizer();      ****  abstract, can't instantiate
 class wxSizer : public wxObject {
 public:
     // wxSizer();      ****  abstract, can't instantiate
@@ -115,168 +116,192 @@ public:
     %addmethods {
         void Destroy() { delete self; }
 
     %addmethods {
         void Destroy() { delete self; }
 
-        void AddWindow(wxWindow *window, int proportion=0, int flag=0, int border=0,
-                       PyObject* userData=NULL) {
-            wxPyUserData* data = NULL;
-            if (userData) data = new wxPyUserData(userData);
-            self->Add(window, proportion, flag, border, data);
-        }
-        void AddSizer(wxSizer *sizer, int proportion=0, int flag=0, int border=0,
-                      PyObject* userData=NULL) {
-            wxPyUserData* data = NULL;
-            if (userData) data = new wxPyUserData(userData);
-            self->Add(sizer, proportion, flag, border, data);
-        }
-        void AddSpacer(int width, int height, int proportion=0, int flag=0,
-                       int border=0, PyObject* userData=NULL) {
-            wxPyUserData* data = NULL;
-            if (userData) data = new wxPyUserData(userData);
-            self->Add(width, height, proportion, flag, border, data);
-        }
 
 
-        void InsertWindow(int before, wxWindow *window, int proportion=0, int flag=0,
-                          int border=0, PyObject* userData=NULL) {
-            wxPyUserData* data = NULL;
-            if (userData) data = new wxPyUserData(userData);
-            self->Insert(before, window, proportion, flag, border, data);
-        }
-        void InsertSizer(int before, wxSizer *sizer, int proportion=0, int flag=0,
-                         int border=0, PyObject* userData=NULL) {
-            wxPyUserData* data = NULL;
-            if (userData) data = new wxPyUserData(userData);
-            self->Insert(before, sizer, proportion, flag, border, data);
-        }
-        void InsertSpacer(int before, int width, int height, int proportion=0, int flag=0,
-                          int border=0, PyObject* userData=NULL) {
+        void _Add(PyObject* item, int proportion=0, int flag=0, int border=0,
+                  PyObject* userData=NULL, int option=-1) {
+            // The option parameter is only for backwards compatibility
+            // with keyword args, all new code should use "proportion"
+            // instead.  This can be removed eventually.
+            if (option != -1) proportion = option;
+
+            wxWindow* window;
+            wxSizer*  sizer;
+            wxSize    size;
+            wxSize*   sizePtr = &size;
             wxPyUserData* data = NULL;
             if (userData) data = new wxPyUserData(userData);
             wxPyUserData* data = NULL;
             if (userData) data = new wxPyUserData(userData);
-            self->Insert(before, width, height, proportion, flag, border, data);
+
+            // Find out what type the item is and call the real Add method
+            if (! SWIG_GetPtrObj(item, (void**)&window, "_wxWindow_p"))
+                self->Add(window, proportion, flag, border, data);
+
+            else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
+                self->Add(sizer, proportion, flag, border, data);
+
+            else if (wxSize_helper(item, &sizePtr))
+                self->Add(sizePtr->GetWidth(), sizePtr->GetHeight(),
+                          proportion, flag, border, data);
+            else {
+                if (data) delete data;
+                PyErr_SetString(PyExc_TypeError,
+                                "wxWindow, wxSizer, wxSize, or (w,h) expected for item");
+            }
         }
 
 
         }
 
 
-        void PrependWindow(wxWindow *window, int proportion=0, int flag=0, int border=0,
-                           PyObject* userData=NULL) {
+        void _Insert(int before, PyObject* item, int proportion=0, int flag=0,
+                     int border=0, PyObject* userData=NULL, int option=-1) {
+            // The option parameter is only for backwards compatibility
+            // with keyword args, all new code should use "proportion"
+            // instead.  This can be removed eventually.
+            if (option != -1) proportion = option;
+
+            wxWindow* window;
+            wxSizer*  sizer;
+            wxSize    size;
+            wxSize*   sizePtr = &size;
             wxPyUserData* data = NULL;
             if (userData) data = new wxPyUserData(userData);
             wxPyUserData* data = NULL;
             if (userData) data = new wxPyUserData(userData);
-            self->Prepend(window, proportion, flag, border, data);
+
+            // Find out what type the item is and call the real Insert method
+            if (! SWIG_GetPtrObj(item, (void**)&window, "_wxWindow_p"))
+                self->Insert(before, window, proportion, flag, border, data);
+
+            else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
+                self->Insert(before, sizer, proportion, flag, border, data);
+
+            else if (wxSize_helper(item, &sizePtr))
+                self->Insert(before, sizePtr->GetWidth(), sizePtr->GetHeight(),
+                          proportion, flag, border, data);
+            else {
+                if (data) delete data;
+                PyErr_SetString(PyExc_TypeError,
+                                "wxWindow, wxSizer, wxSize, or (w,h) expected for item");
+            }
         }
         }
-        void PrependSizer(wxSizer *sizer, int proportion=0, int flag=0, int border=0,
-                          PyObject* userData=NULL) {
+
+
+
+        void _Prepend(PyObject* item, int proportion=0, int flag=0, int border=0,
+                           PyObject* userData=NULL, int option=-1) {
+            // The option parameter is only for backwards compatibility
+            // with keyword args, all new code should use "proportion"
+            // instead.  This can be removed eventually.
+            if (option != -1) proportion = option;
+
+            wxWindow* window;
+            wxSizer*  sizer;
+            wxSize    size;
+            wxSize*   sizePtr = &size;
             wxPyUserData* data = NULL;
             if (userData) data = new wxPyUserData(userData);
             wxPyUserData* data = NULL;
             if (userData) data = new wxPyUserData(userData);
-            self->Prepend(sizer, proportion, flag, border, data);
+
+            // Find out what type the item is and call the real Prepend method
+            if (! SWIG_GetPtrObj(item, (void**)&window, "_wxWindow_p"))
+                self->Prepend(window, proportion, flag, border, data);
+
+            else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
+                self->Prepend(sizer, proportion, flag, border, data);
+
+            else if (wxSize_helper(item, &sizePtr))
+                self->Prepend(sizePtr->GetWidth(), sizePtr->GetHeight(),
+                              proportion, flag, border, data);
+            else {
+                if (data) delete data;
+                PyErr_SetString(PyExc_TypeError,
+                                "wxWindow, wxSizer, wxSize, or (w,h) expected for item");
+            }
         }
         }
-        void PrependSpacer(int width, int height, int proportion=0, int flag=0,
-                           int border=0, PyObject* userData=NULL) {
-            wxPyUserData* data = NULL;
-            if (userData) data = new wxPyUserData(userData);
-            self->Prepend(width, height, proportion, flag, border, data);
+
+        bool Remove(PyObject* item) {
+            wxWindow* window;
+            wxSizer*  sizer;
+
+            // Find out what type the item is and call the real Remove method
+            if (! SWIG_GetPtrObj(item, (void**)&window, "_wxWindow_p"))
+                return self->Remove(window);
+
+            else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
+                return self->Remove(sizer);
+
+            else if (PyInt_Check(item)) {
+                int pos = PyInt_AsLong(item);
+                return self->Remove(pos);
+            }
+            else {
+                PyErr_SetString(PyExc_TypeError,
+                                "wxWindow, wxSizer or int (position) expected.");
+                return FALSE;
+            }
         }
 
         }
 
-        // TODO:  AddItem, InsertItem, PrependItem
+        void _SetItemMinSize(PyObject* item, wxSize size) {
+            wxWindow* window;
+            wxSizer*  sizer;
 
 
-    }
+            // Find out what type the item is and call the real Remove method
+            if (! SWIG_GetPtrObj(item, (void**)&window, "_wxWindow_p"))
+                self->SetItemMinSize(window, size);
+
+            else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
+                self->SetItemMinSize(sizer, size);
 
 
-    %name(RemoveWindow)bool Remove( wxWindow *window );  // TODO: This is DEPRECATED.  Should all be removed?
-    %name(RemoveSizer)bool Remove( wxSizer *sizer );
-    %name(RemovePos)bool Remove( int pos );
+            else if (PyInt_Check(item)) {
+                int pos = PyInt_AsLong(item);
+                self->SetItemMinSize(pos, size);
+            }
+            else
+                PyErr_SetString(PyExc_TypeError,
+                                "wxWindow, wxSizer or int (position) expected.");
+        }
 
 
-    %name(DetachWindow)bool Detach( wxWindow *window );
-    %name(DetachSizer)bool Detach( wxSizer *sizer );
-    %name(DetachPos)bool Detach( int pos );
+    }
 
 
     %pragma(python) addtoclass = "
 
 
     %pragma(python) addtoclass = "
-    def Add(self, *args, **kw):
-        if type(args[0]) == type(1):
-            apply(self.AddSpacer, args, kw)
-        elif isinstance(args[0], wxSizerPtr):
-            apply(self.AddSizer, args, kw)
-        elif isinstance(args[0], wxWindowPtr):
-            apply(self.AddWindow, args, kw)
-        else:
-            raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
-
-    def Insert(self, *args, **kw):
-        if type(args[1]) == type(1):
-            apply(self.InsertSpacer, args, kw)
-        elif isinstance(args[1], wxSizerPtr):
-            apply(self.InsertSizer, args, kw)
-        elif isinstance(args[1], wxWindowPtr):
-            apply(self.InsertWindow, args, kw)
-        else:
-            raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
-
-    def Prepend(self, *args, **kw):
-        if type(args[0]) == type(1):
-            apply(self.PrependSpacer, args, kw)
-        elif isinstance(args[0], wxSizerPtr):
-            apply(self.PrependSizer, args, kw)
-        elif isinstance(args[0], wxWindowPtr):
-            apply(self.PrependWindow, args, kw)
-        else:
-            raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
-
-    def Remove(self, *args, **kw):
-        if type(args[0]) == type(1):
-            return apply(self.RemovePos, args, kw)
-        elif isinstance(args[0], wxSizerPtr):
-            return apply(self.RemoveSizer, args, kw)
-        elif isinstance(args[0], wxWindowPtr):
-            return apply(self.RemoveWindow, args, kw)
-        else:
-            raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
-
-    def Detach(self, *args, **kw):
-        if type(args[0]) == type(1):
-            return apply(self.DetachPos, args, kw)
-        elif isinstance(args[0], wxSizerPtr):
-            return apply(self.DetachSizer, args, kw)
-        elif isinstance(args[0], wxWindowPtr):
-            return apply(self.DetachWindow, args, kw)
-        else:
-            raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
+    def Add(self, item, *args, **kw):
+        if type(item) == type(1):
+            item = (item, args[0])  # backwards compatibility, args are width, height
+            args = args[1:]
+        self._Add(item, *args, **kw)
 
     def AddMany(self, widgets):
         for childinfo in widgets:
             if type(childinfo) != type(()):
                 childinfo = (childinfo, )
 
     def AddMany(self, widgets):
         for childinfo in widgets:
             if type(childinfo) != type(()):
                 childinfo = (childinfo, )
-            apply(self.Add, childinfo)
-"
+            self.Add(*childinfo)
 
 
-    void Clear( bool delete_windows = false );
-    void DeleteWindows();
+    def Prepend(self, item, *args, **kw):
+        if type(item) == type(1):
+            item = (item, args[0])  # backwards compatibility, args are width, height
+            args = args[1:]
+        self._Prepend(item, *args, **kw)
 
 
-    void SetMinSize(wxSize size);
+    def Insert(self, before, item, *args, **kw):
+        if type(item) == type(1):
+            item = (item, args[0])  # backwards compatibility, args are width, height
+            args = args[1:]
+        self._Insert(before, item, *args, **kw)
 
 
-    %name(SetItemMinSizeWindow) void SetItemMinSize(wxWindow* window, wxSize size);
-    %name(SetItemMinSizeSizer) void SetItemMinSize(wxSizer* sizer, wxSize size);
-    %name(SetItemMinSizePos) void SetItemMinSize(int pos, wxSize size);
-    %name(SetItemMinSizeWindowWH) void SetItemMinSize(wxWindow* window, int width, int height);
-    %name(SetItemMinSizeSizerWH) void SetItemMinSize(wxSizer* sizer, int width, int height);
-    %name(SetItemMinSizePosWH) void SetItemMinSize(int pos, int width, int height);
 
 
-    %pragma(python) addtoclass = "
-    def SetItemMinSize(self, *args):
-        if type(args[0]) == type(1):
-            apply(self.SetItemMinSizePos, args)
-        elif isinstance(args[0], wxSizerPtr):
-            apply(self.SetItemMinSizeSizer, args)
-        elif isinstance(args[0], wxWindowPtr):
-            apply(self.SetItemMinSizeWindow, args)
-        else:
-            raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
-
-    def SetItemMinSizeWH(self, *args):
-        if type(args[0]) == type(1):
-            apply(self.SetItemMinSizePosWH, args)
-        elif isinstance(args[0], wxSizerPtr):
-            apply(self.SetItemMinSizeSizerWH, args)
-        elif isinstance(args[0], wxWindowPtr):
-            apply(self.SetItemMinSizeWindowWH, args)
+    # for backwards compatibility only
+    AddWindow = AddSizer = AddSpacer = Add
+    PrependWindow = PrependSizer = PrependSpacer = Prepend
+    InsertWindow = InsertSizer = InsertSpacer = Insert
+    RemoveWindow = RemoveSizer = RemovePos = Remove
+
+
+    def SetItemMinSize(self, item, *args):
+        if len(args) == 2:
+            return self._SetItemMinSize(item, args)
         else:
         else:
-            raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
-     "
+            return self._SetItemMinSize(item, args[0])
+
+"
+
+
+    void SetDimension( int x, int y, int width, int height );
+    void SetMinSize(wxSize size);
 
     wxSize GetSize();
     wxPoint GetPosition();
 
     wxSize GetSize();
     wxPoint GetPosition();
@@ -302,63 +327,65 @@ public:
     void SetSizeHints( wxWindow *window );
     void SetVirtualSizeHints( wxWindow *window );
 
     void SetSizeHints( wxWindow *window );
     void SetVirtualSizeHints( wxWindow *window );
 
+    void Clear( bool delete_windows=FALSE );
+    void DeleteWindows();
+
 
     // wxList& GetChildren();
     %addmethods {
         PyObject* GetChildren() {
 
     // wxList& GetChildren();
     %addmethods {
         PyObject* GetChildren() {
-            wxSizerItemList& list = self->GetChildren();
+            wxList& list = self->GetChildren();
             return wxPy_ConvertList(&list, "wxSizerItem");
         }
     }
 
             return wxPy_ConvertList(&list, "wxSizerItem");
         }
     }
 
-    void SetDimension( int x, int y, int width, int height );
 
     // Manage whether individual windows or sub-sizers are considered
     // in the layout calculations or not.
 
     // Manage whether individual windows or sub-sizers are considered
     // in the layout calculations or not.
-    %name(ShowWindow)void Show( wxWindow *window, bool show = TRUE );
-    %name(ShowSizer)void Show( wxSizer *sizer, bool show = TRUE );
-    %name(ShowPos)void Show( size_t index, bool show = TRUE );
-    %name(HideWindow)void Hide( wxWindow *window );
-    %name(HideSizer)void Hide( wxSizer *sizer );
-    %name(HidePos)void Hide( size_t index );
-    %name(IsShownWindow)bool IsShown( wxWindow *window );
-    %name(IsShownSizer)bool IsShown( wxSizer *sizer );
-    %name(IsShownPos)bool IsShown( size_t index );
 
 
-    %pragma(python) addtoclass = "
-    def Show(self, *args):
-        if type(args[0]) == type(1):
-            apply(self.ShowPos, args)
-        elif isinstance(args[0], wxSizerPtr):
-            apply(self.ShowSizer, args)
-        elif isinstance(args[0], wxWindowPtr):
-            apply(self.ShowWindow, args)
-        else:
-            raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
-
-    def Hide(self, *args):
-        if type(args[0]) == type(1):
-            apply(self.HidePos, args)
-        elif isinstance(args[0], wxSizerPtr):
-            apply(self.HideSizer, args)
-        elif isinstance(args[0], wxWindowPtr):
-            apply(self.HideWindow, args)
-        else:
-            raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
-
-    def IsShown(self, *args):
-        if type(args[0]) == type(1):
-            return apply(self.IsShownPos, args)
-        elif isinstance(args[0], wxSizerPtr):
-            return apply(self.IsShownSizer, args)
-        elif isinstance(args[0], wxWindowPtr):
-            return apply(self.IsShownWindow, args)
-        else:
-            raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
-"
+    %addmethods {
+        void Show(PyObject* item, bool show = TRUE) {
+            wxWindow* window;
+            wxSizer*  sizer;
+            // Find out what type the item is and call the real method
+            if (! SWIG_GetPtrObj(item, (void**)&window, "_wxWindow_p"))
+                self->Show(window, show);
+            else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
+                self->Show(sizer, show);
+            else
+                PyErr_SetString(PyExc_TypeError, "wxWindow or wxSizer expected.");
+        }
+
+        void Hide(PyObject* item) {
+            wxWindow* window;
+            wxSizer*  sizer;
+            // Find out what type the item is and call the real method
+            if (! SWIG_GetPtrObj(item, (void**)&window, "_wxWindow_p"))
+                self->Hide(window);
+            else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
+                self->Hide(sizer);
+            else
+                PyErr_SetString(PyExc_TypeError, "wxWindow or wxSizer expected.");
+        }
+
+        bool IsShown(PyObject* item) {
+            wxWindow* window;
+            wxSizer*  sizer;
+            // Find out what type the item is and call the real method
+            if (! SWIG_GetPtrObj(item, (void**)&window, "_wxWindow_p"))
+                return self->IsShown(window);
+            else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
+                return self->IsShown(sizer);
+            else {
+                PyErr_SetString(PyExc_TypeError, "wxWindow or wxSizer expected.");
+                return FALSE;
+            }
+        }
+    }
+
 
 
-    // Recursively call wxWindow::Show () on all sizer items.
-    void ShowItems (bool show);
+    // Recursively call wxWindow::Show() on all sizer items.
+    void ShowItems(bool show);
 
 };
 
 
 };