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.

113 lines
3.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2016 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. #include <Python.h>
  33. #ifndef NO_WXPYTHON_EXTENSION_HEADERS
  34. #ifdef KICAD_SCRIPTING_WXPYTHON
  35. #include <wx/wxPython/wxPython.h>
  36. #endif
  37. #endif
  38. #include <wx/string.h>
  39. #include <wx/arrstr.h>
  40. /**
  41. * Function pcbnewInitPythonScripting
  42. * Initializes the Python engine inside pcbnew
  43. */
  44. bool pcbnewInitPythonScripting( const char * aUserScriptingPath );
  45. void pcbnewFinishPythonScripting();
  46. /**
  47. * Function pcbnewGetUnloadableScriptNames
  48. * collects the list of python scripts which could not be loaded because
  49. * some error (synthax error) happened
  50. * @param aNames is a wxString which will contain the filenames (separated by '\n')
  51. */
  52. void pcbnewGetUnloadableScriptNames( wxString& aNames );
  53. /**
  54. * Function pcbnewGetScriptsSearchPaths
  55. * collects the list of paths where python scripts are searched
  56. * @param aNames is a wxString which will contain the paths (separated by '\n')
  57. */
  58. void pcbnewGetScriptsSearchPaths( wxString& aNames );
  59. /**
  60. * Function pcbnewGetWizardsBackTrace
  61. * returns the backtrace of errors (if any) when wizard python scripts are loaded
  62. * @param aNames is a wxString which will contain the trace
  63. */
  64. void pcbnewGetWizardsBackTrace( wxString& aNames );
  65. #ifdef KICAD_SCRIPTING_WXPYTHON
  66. void RedirectStdio();
  67. wxWindow* CreatePythonShellWindow( wxWindow* parent, const wxString& aFramenameId );
  68. #endif
  69. #if 0 && defined (KICAD_SCRIPTING_WXPYTHON)
  70. // This definition of PyLOCK crashed Pcbnew under some conditions (JPC),
  71. // especially reloading plugins
  72. class PyLOCK
  73. {
  74. wxPyBlock_t b;
  75. public:
  76. // @todo, find out why these are wxPython specific. We need the GIL regardless.
  77. // Should never assume python will only have one thread calling it.
  78. PyLOCK() { b = wxPyBeginBlockThreads(); }
  79. ~PyLOCK() { wxPyEndBlockThreads( b ); }
  80. };
  81. #else
  82. class PyLOCK
  83. {
  84. PyGILState_STATE gil_state;
  85. public:
  86. PyLOCK() { gil_state = PyGILState_Ensure(); }
  87. ~PyLOCK() { PyGILState_Release( gil_state ); }
  88. };
  89. #endif
  90. wxArrayString PyArrayStringToWx( PyObject* arr );
  91. wxString PyErrStringWithTraceback();
  92. wxString PyScriptingPath();
  93. wxString PyPluginsPath();
  94. #endif // __PYTHON_SCRIPTING_H