29#include <wx/filename.h>
32#include <pybind11/eval.h>
39#include <python_scripting.h>
67 PyModuleDef_Slot* slots = def->m_slots;
69 PyObject* mod = PyModule_Create( def );
70 while( mod && slots->slot )
72 if( slots->slot == Py_mod_exec )
74 int ( *mod_exec )( PyObject* ) = (
int ( * )( PyObject* )) slots->value;
75 if( mod_exec( mod ) != 0 )
90 std::string pymodule(
"_pcbnew" );
92 if( !SCRIPTING::IsModuleLoaded( pymodule ) )
100 PyObject* module_or_module_def = pcbnew_init();
101 if( !module_or_module_def )
104 wxString::Format(
_(
"Failed first phase initializing Python module '%s', through Python C API." ),
106 _(
"Scripting init" ), wxOK | wxICON_ERROR );
110 PyObject* mod = NULL;
111 if( PyObject_TypeCheck( module_or_module_def, &PyModuleDef_Type ) )
116 wxMessageBox( wxString::Format(
117 _(
"Failed second phase initializing Python module '%s', through Python C API." ),
119 _(
"Scripting init" ), wxOK | wxICON_ERROR );
125 mod = module_or_module_def;
128 PyObject* sys_mod = PyImport_GetModuleDict();
129 PyDict_SetItemString( sys_mod,
"_pcbnew", mod );
173 if(
Pgm().GetCommonSettings()->m_Api.enable_server )
174 Pgm().GetPluginManager().ReloadPlugins();
180 frame()->ReCreateMenuBar();
182 frame()->ReCreateHToolbar();
184 frame()->PostSizeEvent();
194 using namespace pybind11::literals;
196 auto locals = pybind11::dict(
197 "sys_path"_a =
TO_UTF8( SCRIPTING::PyScriptingPath( SCRIPTING::PATH_TYPE::STOCK ) ),
198 "user_path"_a =
TO_UTF8( SCRIPTING::PyScriptingPath( SCRIPTING::PATH_TYPE::USER ) ),
199 "third_party_path"_a =
200 TO_UTF8( SCRIPTING::PyPluginsPath( SCRIPTING::PATH_TYPE::THIRDPARTY ) ) );
205pcbnew.LoadPlugins( sys_path, user_path, third_party_path )
207 pybind11::globals(), locals );
213 wxString pluginpath( SCRIPTING::PyPluginsPath( SCRIPTING::PATH_TYPE::USER ) );
215 if( wxFileName::DirExists( pluginpath ) )
219 wxMessageBox( wxString::Format(
_(
"Unable to open plugin directory '%s'." ), pluginpath ),
220 _(
"Plugin Directory" ), wxOK | wxICON_ERROR );
226 wxString msg = wxString::Format(
_(
"The plugin directory '%s' does not exist. Create it?" ), pluginpath );
228 wxMessageDialog dlg(
nullptr, msg,
_(
"Plugin Directory" ), wxYES_NO | wxICON_QUESTION );
230 if( dlg.ShowModal() == wxID_YES )
232 if( wxFileName::Mkdir( pluginpath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
236 wxMessageBox( wxString::Format(
_(
"Unable to open plugin directory '%s'." ), pluginpath ),
237 _(
"Plugin Directory" ), wxOK | wxICON_ERROR );
242 wxMessageBox( wxString::Format(
_(
"Unable to create plugin directory '%s'." ), pluginpath ),
243 _(
"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.
@ 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)