You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.3 KiB

  1. #ifndef __PYTHON_SCRIPTING_H
  2. #define __PYTHON_SCRIPTING_H
  3. // undefs explained here: https://bugzilla.redhat.com/show_bug.cgi?id=427617
  4. #ifdef _POSIX_C_SOURCE
  5. #undef _POSIX_C_SOURCE
  6. #endif
  7. #ifdef _XOPEN_SOURCE
  8. #undef _XOPEN_SOURCE
  9. #endif
  10. #include <Python.h>
  11. #ifndef NO_WXPYTHON_EXTENSION_HEADERS
  12. #ifdef KICAD_SCRIPTING_WXPYTHON
  13. #include <wx/wxPython/wxPython.h>
  14. #endif
  15. #endif
  16. #include <wx/string.h>
  17. #include <wx/arrstr.h>
  18. /* Function pcbnewInitPythonScripting
  19. * Initializes the Python engine inside pcbnew
  20. */
  21. bool pcbnewInitPythonScripting( const char * aUserPluginsPath );
  22. void pcbnewFinishPythonScripting();
  23. #ifdef KICAD_SCRIPTING_WXPYTHON
  24. void RedirectStdio();
  25. wxWindow* CreatePythonShellWindow( wxWindow* parent );
  26. class PyLOCK
  27. {
  28. wxPyBlock_t b;
  29. public:
  30. // @todo, find out why these are wxPython specific. We need the GIL regardless.
  31. // Should never assume python will only have one thread calling it.
  32. PyLOCK() { b = wxPyBeginBlockThreads(); }
  33. ~PyLOCK() { wxPyEndBlockThreads( b ); }
  34. };
  35. #else
  36. class PyLOCK
  37. {
  38. PyGILState_STATE gil_state;
  39. public:
  40. PyLOCK() { gil_state = PyGILState_Ensure(); }
  41. ~PyLOCK() { PyGILState_Release( gil_state ); }
  42. };
  43. #endif
  44. wxArrayString PyArrayStringToWx( PyObject* arr );
  45. wxString PyErrStringWithTraceback();
  46. #endif // __PYTHON_SCRIPTING_H