]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
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 | wxEvtHandler(); | |
23 | ||
24 | wxEvtHandler* GetNextHandler(); | |
25 | wxEvtHandler* GetPreviousHandler(); | |
26 | void SetNextHandler(wxEvtHandler* handler); | |
27 | void SetPreviousHandler(wxEvtHandler* handler); | |
28 | ||
29 | bool GetEvtHandlerEnabled(); | |
30 | void SetEvtHandlerEnabled(bool enabled); | |
31 | ||
32 | ||
33 | // process an event right now | |
34 | bool ProcessEvent(wxEvent& event); | |
35 | ||
36 | // add an event to be processed later | |
37 | void AddPendingEvent(wxEvent& event); | |
38 | ||
39 | // process all pending events | |
40 | void ProcessPendingEvents(); | |
41 | ||
42 | %extend { | |
43 | // Dynamic association of a member function handler with the event handler | |
44 | void Connect( int id, int lastId, int eventType, PyObject* func) { | |
45 | if (PyCallable_Check(func)) { | |
46 | self->Connect(id, lastId, eventType, | |
47 | (wxObjectEventFunction) &wxPyCallback::EventThunker, | |
48 | new wxPyCallback(func)); | |
49 | } | |
50 | else if (func == Py_None) { | |
51 | self->Disconnect(id, lastId, eventType, | |
52 | (wxObjectEventFunction) | |
53 | &wxPyCallback::EventThunker); | |
54 | } | |
55 | else { | |
a51dff73 RD |
56 | wxPyBLOCK_THREADS( |
57 | PyErr_SetString(PyExc_TypeError, "Expected callable object or None.")); | |
d14a1e28 RD |
58 | } |
59 | } | |
60 | ||
61 | bool Disconnect(int id, int lastId = -1, | |
62 | wxEventType eventType = wxEVT_NULL) { | |
63 | return self->Disconnect(id, lastId, eventType, | |
64 | (wxObjectEventFunction) | |
65 | &wxPyCallback::EventThunker); | |
66 | } | |
67 | } | |
68 | ||
69 | %extend { | |
70 | void _setOORInfo(PyObject* _self) { | |
71 | if (_self && _self != Py_None) { | |
72 | self->SetClientObject(new wxPyOORClientData(_self)); | |
73 | } | |
74 | else { | |
75 | wxPyOORClientData* data = (wxPyOORClientData*)self->GetClientObject(); | |
76 | if (data) { | |
77 | self->SetClientObject(NULL); // This will delete it too | |
78 | } | |
79 | } | |
80 | } | |
81 | } | |
82 | ||
83 | %pythoncode { | |
84 | def Bind(self, event, handler, source=None, id=wx.ID_ANY, id2=wx.ID_ANY): | |
85 | """ | |
86 | Bind an event to an event handler. | |
87 | ||
88 | event One of the EVT_* objects that specifies the | |
89 | type of event to bind, | |
90 | ||
91 | handler A callable object to be invoked when the event | |
92 | is delivered to self. Pass None to disconnect an | |
93 | event handler. | |
94 | ||
95 | source Sometimes the event originates from a different window | |
96 | than self, but you still want to catch it in self. (For | |
97 | example, a button event delivered to a frame.) By | |
98 | passing the source of the event, the event handling | |
99 | system is able to differentiate between the same event | |
100 | type from different controls. | |
101 | ||
102 | id,id2 Used for menu IDs or for event types that require a | |
103 | range of IDs | |
104 | """ | |
105 | if source is not None: | |
106 | id = source.GetId() | |
107 | event.Bind(self, id, id2, handler) | |
108 | ||
109 | } | |
110 | ||
111 | ||
112 | }; | |
113 | ||
114 | //--------------------------------------------------------------------------- |