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-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 
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 
57 bool pcbnewInitPythonScripting( const char * aUserScriptingPath );
59 
66 void pcbnewGetUnloadableScriptNames( wxString& aNames );
67 
73 void pcbnewGetScriptsSearchPaths( wxString& aNames );
74 
80 void pcbnewGetWizardsBackTrace( wxString& aNames );
81 
82 #ifdef KICAD_SCRIPTING_WXPYTHON
83 void RedirectStdio();
84 wxWindow* CreatePythonShellWindow( wxWindow* parent, const wxString& aFramenameId );
85 #endif
86 
87 
88 #if 0 && defined (KICAD_SCRIPTING_WXPYTHON)
89 // This definition of PyLOCK crashed Pcbnew under some conditions (JPC),
90 // especially reloading plugins
91 class PyLOCK
92 {
93  wxPyBlock_t b;
94 public:
95 
96  // @todo, find out why these are wxPython specific. We need the GIL regardless.
97  // Should never assume python will only have one thread calling it.
98  PyLOCK() { b = wxPyBeginBlockThreads(); }
99  ~PyLOCK() { wxPyEndBlockThreads( b ); }
100 };
101 
102 
103 #else
104 class PyLOCK
105 {
106  PyGILState_STATE gil_state;
107 public:
108  PyLOCK() { gil_state = PyGILState_Ensure(); }
109  ~PyLOCK() { PyGILState_Release( gil_state ); }
110 };
111 
112 #endif
113 
114 wxString PyStringToWx( PyObject* str );
115 wxArrayString PyArrayStringToWx( PyObject* arr );
116 wxString PyErrStringWithTraceback();
117 
118 wxString PyScriptingPath();
119 wxString PyPluginsPath();
120 
121 #endif // __PYTHON_SCRIPTING_H
void pcbnewGetWizardsBackTrace(wxString &aNames)
Function pcbnewGetWizardsBackTrace returns the backtrace of errors (if any) when wizard python script...
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)
Function pcbnewInitPythonScripting Initializes the Python engine inside pcbnew.
void pcbnewGetUnloadableScriptNames(wxString &aNames)
Function pcbnewGetUnloadableScriptNames collects the list of python scripts which could not be loaded...
void pcbnewGetScriptsSearchPaths(wxString &aNames)
Function pcbnewGetScriptsSearchPaths collects the list of paths where python scripts are searched...