]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_evthandler.i
Bug fix.
[wxWidgets.git] / wxPython / src / _evthandler.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _evthandler.i
3 // Purpose: SWIG interface for wxEventHandler
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 9-Aug-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 %newgroup
18
19 // wxEvtHandler: the base class for all objects handling wxWindows events
20 class wxEvtHandler : public wxObject {
21 public:
22 // turn off this typemap
23 %typemap(out) wxEvtHandler*;
24
25 %pythonAppend wxEvtHandler "self._setOORInfo(self)"
26 wxEvtHandler();
27
28 // Turn it back on again
29 %typemap(out) wxEvtHandler* { $result = wxPyMake_wxObject($1, $owner); }
30
31 wxEvtHandler* GetNextHandler();
32 wxEvtHandler* GetPreviousHandler();
33 void SetNextHandler(wxEvtHandler* handler);
34 void SetPreviousHandler(wxEvtHandler* handler);
35
36 bool GetEvtHandlerEnabled();
37 void SetEvtHandlerEnabled(bool enabled);
38
39
40 // process an event right now
41 bool ProcessEvent(wxEvent& event);
42
43 // add an event to be processed later
44 void AddPendingEvent(wxEvent& event);
45
46 // process all pending events
47 void ProcessPendingEvents();
48
49 // reentrance guard
50 void AllowReentrance( bool allow = true );
51 bool IsReentranceAllowed();
52 bool IsEventHandlingInProgress();
53
54 %extend {
55 // Dynamic association of a member function handler with the event handler
56 void Connect( int id, int lastId, int eventType, PyObject* func) {
57 if (PyCallable_Check(func)) {
58 self->Connect(id, lastId, eventType,
59 (wxObjectEventFunction) &wxPyCallback::EventThunker,
60 new wxPyCallback(func));
61 }
62 else if (func == Py_None) {
63 self->Disconnect(id, lastId, eventType,
64 (wxObjectEventFunction)
65 &wxPyCallback::EventThunker);
66 }
67 else {
68 wxPyBLOCK_THREADS(
69 PyErr_SetString(PyExc_TypeError, "Expected callable object or None."));
70 }
71 }
72
73 bool Disconnect(int id, int lastId = -1,
74 wxEventType eventType = wxEVT_NULL) {
75 return self->Disconnect(id, lastId, eventType,
76 (wxObjectEventFunction)
77 &wxPyCallback::EventThunker);
78 }
79 }
80
81 %pythonAppend _setOORInfo "args[0].thisown = 0";
82 %extend {
83 void _setOORInfo(PyObject* _self, bool incref=true) {
84 if (_self && _self != Py_None) {
85 self->SetClientObject(new wxPyOORClientData(_self, incref));
86 }
87 else {
88 wxPyOORClientData* data = (wxPyOORClientData*)self->GetClientObject();
89 if (data) {
90 self->SetClientObject(NULL); // This will delete it too
91 }
92 }
93 }
94 }
95
96 %pythoncode {
97 def Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY):
98 """
99 Bind an event to an event handler.
100
101 :param event: One of the EVT_* objects that specifies the
102 type of event to bind,
103
104 :param handler: A callable object to be invoked when the
105 event is delivered to self. Pass None to
106 disconnect an event handler.
107
108 :param source: Sometimes the event originates from a
109 different window than self, but you still
110 want to catch it in self. (For example, a
111 button event delivered to a frame.) By
112 passing the source of the event, the event
113 handling system is able to differentiate
114 between the same event type from different
115 controls.
116
117 :param id: Used to spcify the event source by ID instead
118 of instance.
119
120 :param id2: Used when it is desirable to bind a handler
121 to a range of IDs, such as with EVT_MENU_RANGE.
122 """
123 if source is not None:
124 id = source.GetId()
125 event.Bind(self, id, id2, handler)
126
127 def Unbind(self, event, source=None, id=wx.ID_ANY, id2=wx.ID_ANY):
128 """
129 Disconencts the event handler binding for event from self.
130 Returns True if successful.
131 """
132 if source is not None:
133 id = source.GetId()
134 return event.Unbind(self, id, id2)
135 }
136
137 %property(EvtHandlerEnabled, GetEvtHandlerEnabled, SetEvtHandlerEnabled, doc="See `GetEvtHandlerEnabled` and `SetEvtHandlerEnabled`");
138 %property(NextHandler, GetNextHandler, SetNextHandler, doc="See `GetNextHandler` and `SetNextHandler`");
139 %property(PreviousHandler, GetPreviousHandler, SetPreviousHandler, doc="See `GetPreviousHandler` and `SetPreviousHandler`");
140
141 };
142
143 //---------------------------------------------------------------------------