29#include <wx/filename.h>
32#include <pybind11/eval.h>
39#include <python_scripting.h>
68 PyModuleDef_Slot* slots = def->m_slots;
70 PyObject* mod = PyModule_Create( def );
71 while( mod && slots->slot )
73 if( slots->slot == Py_mod_exec )
75 int ( *mod_exec )( PyObject* ) = (
int ( * )( PyObject* )) slots->value;
76 if( mod_exec( mod ) != 0 )
91 std::string pymodule(
"_pcbnew" );
93 if( !SCRIPTING::IsModuleLoaded( pymodule ) )
101 PyObject* module_or_module_def = pcbnew_init();
102 if( !module_or_module_def )
105 wxString::Format(
_(
"Failed first phase initializing Python module '%s', through Python C API." ),
107 _(
"Scripting init" ), wxOK | wxICON_ERROR );
111 PyObject* mod = NULL;
112 if( PyObject_TypeCheck( module_or_module_def, &PyModuleDef_Type ) )
117 wxMessageBox( wxString::Format(
118 _(
"Failed second phase initializing Python module '%s', through Python C API." ),
120 _(
"Scripting init" ), wxOK | wxICON_ERROR );
126 mod = module_or_module_def;
129 PyObject* sys_mod = PyImport_GetModuleDict();
130 PyDict_SetItemString( sys_mod,
"_pcbnew", mod );
174 if(
Pgm().GetCommonSettings()->m_Api.enable_server )
175 Pgm().GetPluginManager().ReloadPlugins();
181 frame()->ReCreateMenuBar();
183 frame()->RecreateToolbars();
185 frame()->PostSizeEvent();
195 using namespace pybind11::literals;
197 auto locals = pybind11::dict(
198 "sys_path"_a =
TO_UTF8( SCRIPTING::PyScriptingPath( SCRIPTING::PATH_TYPE::STOCK ) ),
199 "user_path"_a =
TO_UTF8( SCRIPTING::PyScriptingPath( SCRIPTING::PATH_TYPE::USER ) ),
200 "third_party_path"_a =
201 TO_UTF8( SCRIPTING::PyPluginsPath( SCRIPTING::PATH_TYPE::THIRDPARTY ) ) );
206pcbnew.LoadPlugins( sys_path, user_path, third_party_path )
208 pybind11::globals(), locals );
214 wxString pluginpath( SCRIPTING::PyPluginsPath( SCRIPTING::PATH_TYPE::USER ) );
216 if( wxFileName::DirExists( pluginpath ) )
220 wxMessageBox( wxString::Format(
_(
"Unable to open plugin directory '%s'." ), pluginpath ),
221 _(
"Plugin Directory" ), wxOK | wxICON_ERROR );
227 wxString msg = wxString::Format(
_(
"The plugin directory '%s' does not exist. Create it?" ), pluginpath );
231 if( dlg.ShowModal() == wxID_YES )
233 if( wxFileName::Mkdir( pluginpath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
237 wxMessageBox( wxString::Format(
_(
"Unable to open plugin directory '%s'." ), pluginpath ),
238 _(
"Plugin Directory" ), wxOK | wxICON_ERROR );
243 wxMessageBox( wxString::Format(
_(
"Unable to create plugin directory '%s'." ), pluginpath ),
244 _(
"Plugin Directory" ), wxOK | wxICON_ERROR );
Class PCBNEW_ACTION_PLUGINS.
static TOOL_ACTION pluginsReload
static void UnloadAll()
Unload (deregister) all action plugins.
static TOOL_ACTION pluginsShowFolder
Scripting Actions.
This file is part of the common library.
#define KICAD_MESSAGE_DIALOG
@ KIFACE_SCRIPTING_LEGACY
bool LaunchExternal(const wxString &aPath)
Launches the given file or folder in the host OS.
This file contains miscellaneous commonly used macros and functions.
PGM_BASE & Pgm()
The global program "get" accessor.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Implement a participant in the KIWAY alchemy.
IFACE KIFACE_BASE kiface("pcb_test_frame", KIWAY::FACE_PCB)