graphicsWindow_ext.cxx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file graphicsWindow_ext.cxx
  10. * @author CFSworks
  11. * @date 2014-10-11
  12. */
  13. #include "graphicsWindow_ext.h"
  14. #ifdef HAVE_PYTHON
  15. /**
  16. * Adds a python event handler to be called when a window event occurs.
  17. */
  18. void Extension<GraphicsWindow>::
  19. add_python_event_handler(PyObject* handler, PyObject* name){
  20. PythonGraphicsWindowProc* pgwp = new PythonGraphicsWindowProc(handler, name);
  21. _this->_python_window_proc_classes.insert(pgwp);
  22. _this->add_window_proc(pgwp);
  23. }
  24. /**
  25. * Removes the specified python event handler.
  26. */
  27. void Extension<GraphicsWindow>::
  28. remove_python_event_handler(PyObject* name){
  29. std::list<PythonGraphicsWindowProc*> toRemove;
  30. GraphicsWindow::PythonWinProcClasses::iterator iter;
  31. for (iter = _this->_python_window_proc_classes.begin(); iter != _this->_python_window_proc_classes.end(); ++iter) {
  32. PythonGraphicsWindowProc* pgwp = (PythonGraphicsWindowProc*)*iter;
  33. if (PyObject_RichCompareBool(pgwp->get_name(), name, Py_EQ) == 1) {
  34. toRemove.push_back(pgwp);
  35. }
  36. }
  37. std::list<PythonGraphicsWindowProc*>::iterator iter2;
  38. for (iter2 = toRemove.begin(); iter2 != toRemove.end(); ++iter2) {
  39. PythonGraphicsWindowProc* pgwp = *iter2;
  40. _this->remove_window_proc(pgwp);
  41. _this->_python_window_proc_classes.erase(pgwp);
  42. delete pgwp;
  43. }
  44. }
  45. #endif // HAVE_PYTHON