1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface for wxEventHandler
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
19 // wxEvtHandler: the base class for all objects handling wxWindows events
20 class wxEvtHandler : public wxObject {
22 // turn off this typemap
23 %typemap(out) wxEvtHandler*;
27 // Turn it back on again
28 %typemap(out) wxEvtHandler* { $result = wxPyMake_wxObject($1, $owner); }
30 wxEvtHandler* GetNextHandler();
31 wxEvtHandler* GetPreviousHandler();
32 void SetNextHandler(wxEvtHandler* handler);
33 void SetPreviousHandler(wxEvtHandler* handler);
35 bool GetEvtHandlerEnabled();
36 void SetEvtHandlerEnabled(bool enabled);
39 // process an event right now
40 bool ProcessEvent(wxEvent& event);
42 // add an event to be processed later
43 void AddPendingEvent(wxEvent& event);
45 // process all pending events
46 void ProcessPendingEvents();
49 // Dynamic association of a member function handler with the event handler
50 void Connect( int id, int lastId, int eventType, PyObject* func) {
51 if (PyCallable_Check(func)) {
52 self->Connect(id, lastId, eventType,
53 (wxObjectEventFunction) &wxPyCallback::EventThunker,
54 new wxPyCallback(func));
56 else if (func == Py_None) {
57 self->Disconnect(id, lastId, eventType,
58 (wxObjectEventFunction)
59 &wxPyCallback::EventThunker);
63 PyErr_SetString(PyExc_TypeError, "Expected callable object or None."));
67 bool Disconnect(int id, int lastId = -1,
68 wxEventType eventType = wxEVT_NULL) {
69 return self->Disconnect(id, lastId, eventType,
70 (wxObjectEventFunction)
71 &wxPyCallback::EventThunker);
75 %pythonAppend _setOORInfo "args[0].thisown = 0";
77 void _setOORInfo(PyObject* _self, bool incref=true) {
78 if (_self && _self != Py_None) {
79 self->SetClientObject(new wxPyOORClientData(_self, incref));
82 wxPyOORClientData* data = (wxPyOORClientData*)self->GetClientObject();
84 self->SetClientObject(NULL); // This will delete it too
91 def Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY):
93 Bind an event to an event handler.
95 :param event: One of the EVT_* objects that specifies the
96 type of event to bind,
98 :param handler: A callable object to be invoked when the
99 event is delivered to self. Pass None to
100 disconnect an event handler.
102 :param source: Sometimes the event originates from a
103 different window than self, but you still
104 want to catch it in self. (For example, a
105 button event delivered to a frame.) By
106 passing the source of the event, the event
107 handling system is able to differentiate
108 between the same event type from different
111 :param id: Used to spcify the event source by ID instead
114 :param id2: Used when it is desirable to bind a handler
115 to a range of IDs, such as with EVT_MENU_RANGE.
117 if source is not None:
119 event.Bind(self, id, id2, handler)
121 def Unbind(self, event, source=None, id=wx.ID_ANY, id2=wx.ID_ANY):
123 Disconencts the event handler binding for event from self.
124 Returns True if successful.
126 if source is not None:
128 return event.Unbind(self, id, id2)
134 //---------------------------------------------------------------------------