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.

104 lines
3.0 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. #include <wx/window.h>
  39. #include <wx/string.h>
  40. #include <wx/arrstr.h>
  41. class SCRIPTING
  42. {
  43. public:
  44. SCRIPTING();
  45. ~SCRIPTING();
  46. /// We do not allow secondary creation of the scripting system
  47. SCRIPTING( SCRIPTING const& ) = delete;
  48. void operator= ( SCRIPTING const& ) = delete;
  49. static bool IsWxAvailable();
  50. static bool IsModuleLoaded( std::string& aModule );
  51. enum PATH_TYPE
  52. {
  53. STOCK,
  54. USER,
  55. THIRDPARTY
  56. };
  57. static wxString PyScriptingPath( PATH_TYPE aPathType = STOCK );
  58. static wxString PyPluginsPath( PATH_TYPE aPathType = STOCK );
  59. private:
  60. bool scriptingSetup();
  61. PyThreadState* m_python_thread_state;
  62. };
  63. /**
  64. * Set an environment variable in the current Python interpreter.
  65. *
  66. * @param aVar is the variable to set
  67. * @param aValue is the value to give it
  68. */
  69. void UpdatePythonEnvVar( const wxString& aVar, const wxString& aValue );
  70. void RedirectStdio();
  71. wxWindow* CreatePythonShellWindow( wxWindow* parent, const wxString& aFramenameId );
  72. bool InitPythonScripting( const char* aStockScriptingPath, const char* aUserScriptingPath );
  73. bool IsWxPythonLoaded();
  74. class PyLOCK
  75. {
  76. PyGILState_STATE gil_state;
  77. public:
  78. PyLOCK() { gil_state = PyGILState_Ensure(); }
  79. ~PyLOCK() { PyGILState_Release( gil_state ); }
  80. };
  81. wxString PyStringToWx( PyObject* str );
  82. wxArrayString PyArrayStringToWx( PyObject* arr );
  83. wxString PyErrStringWithTraceback();
  84. #endif // __PYTHON_SCRIPTING_H