PageRenderTime 27ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/evince/evincemodule.c

https://github.com/dieterv/gnome-python-desktop
C | 66 lines | 43 code | 18 blank | 5 comment | 2 complexity | 5da4a28678c9a32ed406f6f29e0763d0 MD5 | raw file
  1. #ifdef HAVE_CONFIG_H
  2. #include "config.h"
  3. #endif
  4. /* include this first, before NO_IMPORT_PYGOBJECT is defined */
  5. #include <pygobject.h>
  6. #include <pygtk/pygtk.h>
  7. #include <evince-document.h>
  8. #include <pycairo/pycairo.h>
  9. Pycairo_CAPI_t *Pycairo_CAPI;
  10. void pyevince_register_classes (PyObject *d);
  11. void pyevince_add_constants(PyObject *module, const gchar *strip_prefix);
  12. extern PyMethodDef pyevince_functions[];
  13. PyObject *
  14. _wrap_ev_shutdown (void)
  15. {
  16. /* g_message("ev_shutdown();"); */
  17. ev_shutdown();
  18. Py_INCREF(Py_None);
  19. return Py_None;
  20. }
  21. DL_EXPORT(void)
  22. initevince(void)
  23. {
  24. PyObject *m, *d;
  25. /* Init glib threads asap */
  26. if (!g_thread_supported ())
  27. g_thread_init (NULL);
  28. init_pygobject ();
  29. pyg_enable_threads ();
  30. Pycairo_IMPORT;
  31. ev_init ();
  32. m = Py_InitModule ("evince", pyevince_functions);
  33. d = PyModule_GetDict (m);
  34. pyevince_register_classes (d);
  35. pyevince_add_constants(m, "EV_");
  36. if (PyErr_Occurred ()) {
  37. return;
  38. }
  39. /* Call ev_shutdown() on an atexit handler (bug #570622) */
  40. {
  41. // note: py_atexit_method_def has to be static, since python keeps a pointer to it
  42. static PyMethodDef py_atexit_method_def = {NULL, (PyCFunction)_wrap_ev_shutdown, METH_NOARGS, NULL};
  43. PyObject *py_atexit_func = PyCFunction_NewEx(&py_atexit_method_def, NULL, NULL);
  44. PyObject *atexit = PyImport_ImportModule("atexit");
  45. PyObject_CallMethod(atexit, "register", "N", py_atexit_func);
  46. Py_DECREF(atexit);
  47. }
  48. }