Adonthell  0.4
win_event.cc
1 /*
2  (C) Copyright 2001 Joel Vennin
3  Part of the Adonthell Project <http://adonthell.nongnu.org>
4 
5  Adonthell is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  Adonthell is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Adonthell. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 
20 #include "win_event.h"
21 #include "py_callback.h"
22 
23 
24 void win_event::py_signal_connect (PyObject *pyfunc, int signal, PyObject *args)
25 {
26  // create the callback
27  py_callback *callback = new py_callback (pyfunc, args);
28  py_callbacks.push_back (callback);
29 
30  // connect the signal
31  switch (signal)
32  {
33  case CLOSE:
34  {
35  set_callback_quit (makeFunctor (*callback, &py_callback::callback_func1));
36  break;
37  }
38 
39  case DESTROY:
40  {
41  Functor0wRet<bool> func0ret;
42  set_callback_destroy (
43  makeFunctor (&func0ret, *callback, &py_callback::callback_func0ret));
44  break;
45  }
46 
47  default:
48  {
49  set_signal_connect (makeFunctor (*callback, &py_callback::callback_func0), signal);
50  }
51  }
52 }
53 
54 
55 bool win_event::update()
56 {
57  if(callback_destroy_ && !callback_destroy_()) return false;
58  return true;
59 }
60 
61 
62 win_event::~win_event()
63 {
64  //notify that window is closing
65  if (callback_quit_) (callback_quit_) (return_code_);
66 
67  //delete any python callbacks
68  for (vector<py_callback *>::iterator i = py_callbacks.begin (); i != py_callbacks.end (); i++)
69  delete *i;
70 }
71 
72 
73 
74 
75 
76 
void callback_func1(int arg)
Calls the python function with an integer.
Definition: py_callback.cc:82
Declares the py_callback class.
bool callback_func0ret()
Calls the python function and returns bool.
Definition: py_callback.cc:68
void callback_func0()
Calls the python function without arguments.
Definition: py_callback.cc:60
Stores the C++ <-> Python callback binding.
Definition: py_callback.h:41