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.

131 lines
3.9 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifndef __PYTHON_SCRIPTING_H
  24. #define __PYTHON_SCRIPTING_H
  25. // undefs explained here: https://bugzilla.redhat.com/show_bug.cgi?id=427617
  26. #ifdef _POSIX_C_SOURCE
  27. #undef _POSIX_C_SOURCE
  28. #endif
  29. #ifdef _XOPEN_SOURCE
  30. #undef _XOPEN_SOURCE
  31. #endif
  32. #if defined(WIN32)
  33. #undef pid_t // wxWidgets defines this, python typedefs, result is a conflict
  34. #endif
  35. #undef HAVE_CLOCK_GETTIME // macro is defined in Python.h and causes redefine warning
  36. #include <Python.h>
  37. #undef HAVE_CLOCK_GETTIME
  38. #ifndef NO_WXPYTHON_EXTENSION_HEADERS
  39. #ifdef KICAD_SCRIPTING_WXPYTHON
  40. #ifdef KICAD_SCRIPTING_WXPYTHON_PHOENIX
  41. #include <wx/window.h>
  42. #else
  43. #include <wx/wxPython/wxPython.h>
  44. #endif
  45. #endif
  46. #endif
  47. #include <wx/string.h>
  48. #include <wx/arrstr.h>
  49. /**
  50. * Initialize the Python engine inside pcbnew.
  51. */
  52. bool pcbnewInitPythonScripting( const char * aUserScriptingPath );
  53. void pcbnewFinishPythonScripting();
  54. /**
  55. * Collect the list of python scripts which could not be loaded.
  56. *
  57. * @param aNames is a wxString which will contain the filenames (separated by '\n')
  58. */
  59. void pcbnewGetUnloadableScriptNames( wxString& aNames );
  60. /**
  61. * Collect the list of paths where python scripts are searched.
  62. *
  63. * @param aNames is a wxString which will contain the paths (separated by '\n')
  64. */
  65. void pcbnewGetScriptsSearchPaths( wxString& aNames );
  66. /**
  67. * Return the backtrace of errors (if any) when wizard python scripts are loaded.
  68. *
  69. * @param aNames is a wxString which will contain the trace
  70. */
  71. void pcbnewGetWizardsBackTrace( wxString& aNames );
  72. /**
  73. * Set an environment variable in the current Python interpreter.
  74. *
  75. * @param aVar is the variable to set
  76. * @param aValue is the value to give it
  77. */
  78. void pcbnewUpdatePythonEnvVar( const wxString& aVar, const wxString& aValue );
  79. #ifdef KICAD_SCRIPTING_WXPYTHON
  80. void RedirectStdio();
  81. wxWindow* CreatePythonShellWindow( wxWindow* parent, const wxString& aFramenameId );
  82. #endif
  83. bool IsWxPythonLoaded();
  84. #if 0 && defined (KICAD_SCRIPTING_WXPYTHON)
  85. // This definition of PyLOCK crashed Pcbnew under some conditions (JPC),
  86. // especially reloading plugins
  87. class PyLOCK
  88. {
  89. wxPyBlock_t b;
  90. public:
  91. // @todo, find out why these are wxPython specific. We need the GIL regardless.
  92. // Should never assume python will only have one thread calling it.
  93. PyLOCK() { b = wxPyBeginBlockThreads(); }
  94. ~PyLOCK() { wxPyEndBlockThreads( b ); }
  95. };
  96. #else
  97. class PyLOCK
  98. {
  99. PyGILState_STATE gil_state;
  100. public:
  101. PyLOCK() { gil_state = PyGILState_Ensure(); }
  102. ~PyLOCK() { PyGILState_Release( gil_state ); }
  103. };
  104. #endif
  105. wxString PyStringToWx( PyObject* str );
  106. wxArrayString PyArrayStringToWx( PyObject* arr );
  107. wxString PyErrStringWithTraceback();
  108. wxString PyScriptingPath( bool aUserPath = false );
  109. wxString PyPluginsPath( bool aUserPath = false );
  110. #endif // __PYTHON_SCRIPTING_H