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 #include <Python.h>
37 #ifndef NO_WXPYTHON_EXTENSION_HEADERS
38 #ifdef KICAD_SCRIPTING_WXPYTHON
39  #include <wx/wxPython/wxPython.h>
40 #endif
41 #endif
42 
43 #include <wx/string.h>
44 #include <wx/arrstr.h>
45 
50 bool pcbnewInitPythonScripting( const char * aUserScriptingPath );
52 
59 void pcbnewGetUnloadableScriptNames( wxString& aNames );
60 
66 void pcbnewGetScriptsSearchPaths( wxString& aNames );
67 
73 void pcbnewGetWizardsBackTrace( wxString& aNames );
74 
75 #ifdef KICAD_SCRIPTING_WXPYTHON
76 void RedirectStdio();
77 wxWindow* CreatePythonShellWindow( wxWindow* parent, const wxString& aFramenameId );
78 #endif
79 
80 
81 #if 0 && defined (KICAD_SCRIPTING_WXPYTHON)
82 // This definition of PyLOCK crashed Pcbnew under some conditions (JPC),
83 // especially reloading plugins
84 class PyLOCK
85 {
86  wxPyBlock_t b;
87 public:
88 
89  // @todo, find out why these are wxPython specific. We need the GIL regardless.
90  // Should never assume python will only have one thread calling it.
91  PyLOCK() { b = wxPyBeginBlockThreads(); }
92  ~PyLOCK() { wxPyEndBlockThreads( b ); }
93 };
94 
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 
105 #endif
106 
107 wxArrayString PyArrayStringToWx( PyObject* arr );
108 wxString PyErrStringWithTraceback();
109 
110 wxString PyScriptingPath();
111 wxString PyPluginsPath();
112 
113 #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
wxArrayString PyArrayStringToWx(PyObject *arr)
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...