KiCad PCB EDA Suite
python_scripting.h
Go to the documentation of this file.
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 
24 #ifndef __PYTHON_SCRIPTING_H
25 #define __PYTHON_SCRIPTING_H
26 
27 // undefs explained here: https://bugzilla.redhat.com/show_bug.cgi?id=427617
28 
29 #ifdef _POSIX_C_SOURCE
30  #undef _POSIX_C_SOURCE
31 #endif
32 #ifdef _XOPEN_SOURCE
33  #undef _XOPEN_SOURCE
34 #endif
35 
36 #undef HAVE_CLOCK_GETTIME // macro is defined in Python.h and causes redefine warning
37 #include <Python.h>
38 #undef HAVE_CLOCK_GETTIME
39 
40 #ifndef NO_WXPYTHON_EXTENSION_HEADERS
41 #ifdef KICAD_SCRIPTING_WXPYTHON
42  #ifdef KICAD_SCRIPTING_WXPYTHON_PHOENIX
43  #include <wx/window.h>
44  #else
45  #include <wx/wxPython/wxPython.h>
46  #endif
47 #endif
48 #endif
49 
50 #include <wx/string.h>
51 #include <wx/arrstr.h>
52 
53 
57 bool pcbnewInitPythonScripting( const char * aUserScriptingPath );
59 
65 void pcbnewGetUnloadableScriptNames( wxString& aNames );
66 
72 void pcbnewGetScriptsSearchPaths( wxString& aNames );
73 
79 void pcbnewGetWizardsBackTrace( wxString& aNames );
80 
81 #ifdef KICAD_SCRIPTING_WXPYTHON
82 void RedirectStdio();
83 wxWindow* CreatePythonShellWindow( wxWindow* parent, const wxString& aFramenameId );
84 #endif
85 
86 #if 0 && defined (KICAD_SCRIPTING_WXPYTHON)
87 // This definition of PyLOCK crashed Pcbnew under some conditions (JPC),
88 // especially reloading plugins
89 class PyLOCK
90 {
91  wxPyBlock_t b;
92 public:
93 
94  // @todo, find out why these are wxPython specific. We need the GIL regardless.
95  // Should never assume python will only have one thread calling it.
96  PyLOCK() { b = wxPyBeginBlockThreads(); }
97  ~PyLOCK() { wxPyEndBlockThreads( b ); }
98 };
99 #else
100 class PyLOCK
101 {
102  PyGILState_STATE gil_state;
103 public:
104  PyLOCK() { gil_state = PyGILState_Ensure(); }
105  ~PyLOCK() { PyGILState_Release( gil_state ); }
106 };
107 #endif
108 
109 wxString PyStringToWx( PyObject* str );
110 wxArrayString PyArrayStringToWx( PyObject* arr );
111 wxString PyErrStringWithTraceback();
112 
113 wxString PyScriptingPath();
114 wxString PyPluginsPath();
115 
116 #endif // __PYTHON_SCRIPTING_H
void pcbnewGetWizardsBackTrace(wxString &aNames)
Return the backtrace of errors (if any) when wizard python scripts are loaded.
wxString PyPluginsPath()
PyGILState_STATE gil_state
const string & str
Definition: json11.cpp:596
wxArrayString PyArrayStringToWx(PyObject *arr)
wxString PyStringToWx(PyObject *str)
wxString PyScriptingPath()
Find the Python scripting path.
void pcbnewFinishPythonScripting()
wxString PyErrStringWithTraceback()
bool pcbnewInitPythonScripting(const char *aUserScriptingPath)
Initialize the Python engine inside pcbnew.
void pcbnewGetUnloadableScriptNames(wxString &aNames)
Collect the list of python scripts which could not be loaded.
void pcbnewGetScriptsSearchPaths(wxString &aNames)
Collect the list of paths where python scripts are searched.