]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/wxPython/src/events.i
code cleanup
[wxWidgets.git] / utils / wxPython / src / events.i
index 90aaa54017865fcf6ea7d7a6dd372a81bbe31612..a5f08b2eec9907a40e82d187e407352fbfe82f04 100644 (file)
@@ -401,120 +401,34 @@ public:
 
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
-//---------------------------------------------------------------------------
-// This one can be derived from in Python and passed through the event
-// system without loosing anything so long as the Python data is saved with
-// SetPyData...
-
-%{
-class wxPyEvent : public wxEvent {
-    DECLARE_DYNAMIC_CLASS(wxPyEvent)
-public:
-    wxPyEvent(int id=0, PyObject* userData = Py_None)
-        : wxEvent(id) {
-        m_userData = userData;
-        Py_INCREF(m_userData);
-    }
-
-    ~wxPyEvent() {
-        bool doSave = wxPyRestoreThread();
-        Py_DECREF(m_userData);
-        wxPySaveThread(doSave);
-    }
-
-    void SetPyData(PyObject* userData) {
-        bool doSave = wxPyRestoreThread();
-        Py_DECREF(m_userData);
-        m_userData = userData;
-        Py_INCREF(m_userData);
-        wxPySaveThread(doSave);
-    }
-
-    PyObject* GetPyData() const {
-        Py_INCREF(m_userData);
-        return m_userData;
-    }
-
-    // This one is so the event object can be Cloned...
-    void CopyObject(wxObject& dest) const {
-        wxEvent::CopyObject(dest);
-        ((wxPyEvent*)&dest)->SetPyData(m_userData);
-    }
-
-private:
-    PyObject* m_userData;
-};
-
-IMPLEMENT_DYNAMIC_CLASS(wxPyEvent, wxEvent)
-
-%}
-
+// These classes can be derived from in Python and passed through the event
+// system without loosing anything.  They do this by keeping a reference to
+// themselves and some special case handling in wxPyCallback::EventThunker.
 
 class wxPyEvent : public wxEvent {
 public:
-    wxPyEvent(int id=0, PyObject* userData = Py_None);
+    wxPyEvent(int id=0);
     ~wxPyEvent();
 
-    void SetPyData(PyObject* userData);
-    PyObject* GetPyData();
+    %pragma(python) addtomethod = "__init__:self.SetSelf(self)"
+
+    void SetSelf(PyObject* self);
+    PyObject* GetSelf();
 };
 
-//---------------------------------------------------------------------------
-// Same for this one except it is a wxCommandEvent and so will get passed up the
-// containment heirarchy.
 
-%{
 class wxPyCommandEvent : public wxCommandEvent {
-    DECLARE_DYNAMIC_CLASS(wxPyCommandEvent)
 public:
-    wxPyCommandEvent(wxEventType commandType = wxEVT_NULL, int id=0, PyObject* userData = Py_None)
-        : wxCommandEvent(commandType, id) {
-        m_userData = userData;
-        Py_INCREF(m_userData);
-    }
-
-    ~wxPyCommandEvent() {
-        bool doSave = wxPyRestoreThread();
-        Py_DECREF(m_userData);
-        wxPySaveThread(doSave);
-    }
-
-    void SetPyData(PyObject* userData) {
-        bool doSave = wxPyRestoreThread();
-        Py_DECREF(m_userData);
-        m_userData = userData;
-        Py_INCREF(m_userData);
-        wxPySaveThread(doSave);
-    }
-
-    PyObject* GetPyData() const {
-        Py_INCREF(m_userData);
-        return m_userData;
-    }
+    wxPyCommandEvent(wxEventType commandType = wxEVT_NULL, int id=0);
+    ~wxPyCommandEvent();
 
-    // This one is so the event object can be Cloned...
-    void CopyObject(wxObject& dest) const {
-        wxCommandEvent::CopyObject(dest);
-        ((wxPyCommandEvent*)&dest)->SetPyData(m_userData);
-    }
+    %pragma(python) addtomethod = "__init__:self.SetSelf(self)"
 
-private:
-    PyObject* m_userData;
+    void SetSelf(PyObject* self);
+    PyObject* GetSelf();
 };
 
-IMPLEMENT_DYNAMIC_CLASS(wxPyCommandEvent, wxCommandEvent)
-
-%}
-
 
-class wxPyCommandEvent : public wxCommandEvent {
-public:
-    wxPyCommandEvent(wxEventType commandType = wxEVT_NULL, int id=0, PyObject* userData = Py_None);
-    ~wxPyCommandEvent();
-
-    void SetPyData(PyObject* userData);
-    PyObject* GetPyData();
-};
 
 
 //---------------------------------------------------------------------------