29#include <wx/filename.h>
32#include <pybind11/eval.h>
40#include <python_scripting.h>
69 PyModuleDef_Slot* slots = def->m_slots;
71 PyObject* mod = PyModule_Create( def );
72 while( mod && slots->slot )
74 if( slots->slot == Py_mod_exec )
76 int ( *mod_exec )( PyObject* ) = (
int ( * )( PyObject* )) slots->value;
77 if( mod_exec( mod ) != 0 )
92 std::string pymodule(
"_pcbnew" );
94 if( !SCRIPTING::IsModuleLoaded( pymodule ) )
102 PyObject* module_or_module_def = pcbnew_init();
103 if( !module_or_module_def )
106 wxString::Format(
_(
"Failed first phase initializing Python module '%s', through Python C API." ),
108 _(
"Scripting init" ), wxOK | wxICON_ERROR );
112 PyObject* mod = NULL;
113 if( PyObject_TypeCheck( module_or_module_def, &PyModuleDef_Type ) )
118 wxMessageBox( wxString::Format(
119 _(
"Failed second phase initializing Python module '%s', through Python C API." ),
121 _(
"Scripting init" ), wxOK | wxICON_ERROR );
127 mod = module_or_module_def;
130 PyObject* sys_mod = PyImport_GetModuleDict();
131 PyDict_SetItemString( sys_mod,
"_pcbnew", mod );
175 if(
Pgm().GetCommonSettings()->m_Api.enable_server )
176 Pgm().GetPluginManager().ReloadPlugins();
182 frame()->ReCreateMenuBar();
184 frame()->RecreateToolbars();
186 frame()->PostSizeEvent();
196 using namespace pybind11::literals;
198 auto locals = pybind11::dict(
199 "sys_path"_a =
TO_UTF8( SCRIPTING::PyScriptingPath( SCRIPTING::PATH_TYPE::STOCK ) ),
200 "user_path"_a =
TO_UTF8( SCRIPTING::PyScriptingPath( SCRIPTING::PATH_TYPE::USER ) ),
201 "third_party_path"_a =
202 TO_UTF8( SCRIPTING::PyPluginsPath( SCRIPTING::PATH_TYPE::THIRDPARTY ) ) );
207pcbnew.LoadPlugins( sys_path, user_path, third_party_path )
209 pybind11::globals(), locals );
215 wxString pluginpath( SCRIPTING::PyPluginsPath( SCRIPTING::PATH_TYPE::USER ) );
217 if( wxFileName::DirExists( pluginpath ) )
221 wxMessageBox( wxString::Format(
_(
"Unable to open plugin directory '%s'." ), pluginpath ),
222 _(
"Plugin Directory" ), wxOK | wxICON_ERROR );
228 wxString msg = wxString::Format(
_(
"The plugin directory '%s' does not exist. Create it?" ), pluginpath );
232 if( dlg.ShowModal() == wxID_YES )
234 if( wxFileName::Mkdir( pluginpath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
238 wxMessageBox( wxString::Format(
_(
"Unable to open plugin directory '%s'." ), pluginpath ),
239 _(
"Plugin Directory" ), wxOK | wxICON_ERROR );
244 wxMessageBox( wxString::Format(
_(
"Unable to create plugin directory '%s'." ), pluginpath ),
245 _(
"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)