]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/src/_pen.i
Doh! I changed the AddPane parameter names but didn't change their usage.
[wxWidgets.git] / wxPython / src / _pen.i
index 6f0afd99c333205c82070dcd6035fb0043e998f6..e0fca1cb17ca0907d1ff6b6cc25cb7cd3ac1a8d1 100644 (file)
@@ -29,6 +29,8 @@
 %newgroup
 
 
+MustHaveApp(wxPen);
+
 class wxPen : public wxGDIObject {
 public:
     wxPen(wxColour& colour, int width=1, int style=wxSOLID);
@@ -54,59 +56,62 @@ public:
         PyObject* GetDashes() {
             wxDash* dashes;
             int count = self->GetDashes(&dashes);
-            wxPyBeginBlockThreads();
+            wxPyBlock_t blocked = wxPyBeginBlockThreads();
             PyObject* retval = PyList_New(0);
-            for (int x=0; x<count; x++)
-                PyList_Append(retval, PyInt_FromLong(dashes[x]));
-            wxPyEndBlockThreads();
+            for (int x=0; x<count; x++) {
+                PyObject* pyint = PyInt_FromLong(dashes[x]);
+                PyList_Append(retval, pyint);
+                Py_DECREF(pyint);
+            }
+            wxPyEndBlockThreads(blocked);
             return retval;
         }
+
+        void _SetDashes(PyObject* _self, PyObject* pyDashes) {
+            wxPyBlock_t blocked = wxPyBeginBlockThreads();
+            int size = PyList_Size(pyDashes);
+            wxDash* dashes = (wxDash*)byte_LIST_helper(pyDashes);
+
+            // black magic warning!  The array of wxDashes needs to exist as
+            // long as the pen does because wxPen does not copy the array.  So
+            // stick a copy in a Python string object and attach it to _self,
+            // and then call SetDashes with a pointer to that array.  Then
+            // when the Python pen object is destroyed the array will be
+            // cleaned up too.
+            PyObject* strDashes = PyString_FromStringAndSize((char*)dashes, size*sizeof(wxDash));
+            PyObject_SetAttrString(_self, "_dashes", strDashes);
+                        
+            self->SetDashes(size, (wxDash*)PyString_AS_STRING(strDashes));
+            delete [] dashes;
+            Py_DECREF(strDashes);
+            wxPyEndBlockThreads(blocked);
+        }
+    }
+    %pythoncode {
+    def SetDashes(self, dashes):
+        """
+        Associate a list of dash lengths with the Pen.
+        """
+        self._SetDashes(self, dashes)
     }
 
-//  wxDash* GetDash() const { return (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*)NULL); };
+    
+#ifndef __WXMAC__
     int GetDashCount() const;
-
+#endif
+    
 #ifdef __WXMSW__
     wxBitmap* GetStipple();
     void SetStipple(wxBitmap& stipple);
 #endif
 
-    %pythoncode { def __nonzero__(self): return self.Ok() }
-};
-
-
-// The list of ints for the dashes needs to exist for the life of the pen
-// so we make it part of the class to save it.  See pyclasses.h
-
-%{
-wxPyPen::~wxPyPen()
-{
-    if (m_dash)
-        delete [] m_dash;
-}
-
-void wxPyPen::SetDashes(int nb_dashes, const wxDash *dash)
-{
-    if (m_dash)
-        delete [] m_dash;
-    m_dash = new wxDash[nb_dashes];
-    for (int i=0; i<nb_dashes; i++) {
-        m_dash[i] = dash[i];
+    
+    %extend {
+        bool __eq__(const wxPen* other) { return other ? (*self == *other) : false; }
+        bool __ne__(const wxPen* other) { return other ? (*self != *other) : true;  }
     }
-    wxPen::SetDashes(nb_dashes, m_dash);
-} 
-%}
-
-
-class wxPyPen : public wxPen {
-public:
-    wxPyPen(wxColour& colour, int width=1, int style=wxSOLID);
-    ~wxPyPen();
-
-    void SetDashes(int dashes, wxDash* dashes_array);
+    %pythoncode { def __nonzero__(self): return self.Ok() }
 };
 
-// wxPyPen is aliased to wxPen
-%pythoncode { Pen = PyPen };
 
 //---------------------------------------------------------------------------