21 changed files with 1337 additions and 257 deletions
-
2CMakeLists.txt
-
2common/CMakeLists.txt
-
57common/eda_base_frame.cpp
-
8common/eda_dde.cpp
-
1common/eda_item.cpp
-
4common/kiway.cpp
-
7common/kiway_player.cpp
-
4common/single_top.cpp
-
7include/eda_base_frame.h
-
5include/eda_dde.h
-
13include/eda_draw_frame.h
-
21include/kiway_player.h
-
2include/pgm_base.h
-
4pcbnew/pcb_edit_frame.cpp
-
5scripting/CMakeLists.txt
-
40scripting/kicad_pyshell/__init__.py
-
1059scripting/kicad_pyshell/kicad_pyeditor.py
-
89scripting/kicad_scripting_main.cpp
-
91scripting/kipython_frame.cpp
-
63scripting/kipython_frame.h
-
110scripting/python_scripting.cpp
1059
scripting/kicad_pyshell/kicad_pyeditor.py
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,91 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2021 KiCad Developers, see CHANGELOG.TXT for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 3 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/gpl-3.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 3 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#include <frame_type.h>
|
|||
#include <kipython_frame.h>
|
|||
#include <kiway_player.h>
|
|||
#include <python_scripting.h>
|
|||
|
|||
#include <pybind11/embed.h>
|
|||
#include <sstream>
|
|||
#include <wx/wx.h>
|
|||
#include <pybind11/embed.h>
|
|||
|
|||
void KIPYTHON_FRAME::SetupPythonEditor() |
|||
{ |
|||
|
|||
// passing window ids instead of pointers is because wxPython is not
|
|||
// exposing the needed c++ apis to make that possible.
|
|||
std::stringstream pcbnew_pyshell_one_step; |
|||
pcbnew_pyshell_one_step << "import kicad_pyshell\n"; |
|||
pcbnew_pyshell_one_step << "newshell = kicad_pyshell.makePcbnewShellWindow( " << GetId() << " )\n"; |
|||
|
|||
// As always, first grab the GIL
|
|||
PyLOCK lock; |
|||
|
|||
// Execute the code to make the makeWindow function we defined above
|
|||
PyRun_SimpleString( pcbnew_pyshell_one_step.str().c_str() ); |
|||
} |
|||
|
|||
|
|||
void KIPYTHON_FRAME::redirectStdio() |
|||
{ |
|||
// This is a helpful little tidbit to help debugging and such. It
|
|||
// redirects Python's stdout and stderr to a window that will popup
|
|||
// only on demand when something is printed, like a traceback.
|
|||
|
|||
PyLOCK lock; |
|||
|
|||
using namespace pybind11::literals; |
|||
int id = GetId(); |
|||
auto locals = pybind11::dict( "parent_id"_a= id ); |
|||
|
|||
pybind11::exec( R"( |
|||
import sys |
|||
import wx |
|||
output = wx.PyOnDemandOutputWindow() |
|||
sys.stderr = output |
|||
parent = wx.Window.FindWindowById( parent_id ) |
|||
output.SetParent( parent ) |
|||
)", pybind11::globals(), locals ); |
|||
} |
|||
|
|||
KIPYTHON_FRAME::KIPYTHON_FRAME( KIWAY* aKiway, wxWindow* aParent ) : |
|||
KIWAY_PLAYER( aKiway, aParent, FRAME_PYTHON, wxT( "KiPython" ), wxDefaultPosition, |
|||
wxDefaultSize, KICAD_DEFAULT_DRAWFRAME_STYLE, wxT( "KiPython" ) ) |
|||
{ |
|||
m_stdio = 0; |
|||
|
|||
CallAfter( [&](){ SetupPythonEditor(); } ); |
|||
|
|||
redirectStdio(); |
|||
} |
|||
|
|||
|
|||
KIPYTHON_FRAME::~KIPYTHON_FRAME() |
|||
{ |
|||
wxWindow* stdio_window = wxWindow::FindWindowById( m_stdio ); |
|||
|
|||
if( stdio_window ) |
|||
stdio_window->Close( true ); |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2021 KiCad Developers, see CHANGELOG.TXT for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 3 |
|||
* of the License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, you may find one here: |
|||
* http://www.gnu.org/licenses/gpl-3.0.html |
|||
* or you may search the http://www.gnu.org website for the version 3 license, |
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#ifndef SCRIPTING_KIPYTHON_FRAME_H_ |
|||
#define SCRIPTING_KIPYTHON_FRAME_H_ |
|||
|
|||
#include <kiway_player.h> |
|||
|
|||
class wxWindow; |
|||
class APP_SETTINGS_BASE; |
|||
class KIWAY_EXPRESS; |
|||
|
|||
class KIPYTHON_FRAME : public KIWAY_PLAYER |
|||
{ |
|||
|
|||
|
|||
public: |
|||
KIPYTHON_FRAME( KIWAY* aKiway, wxWindow* aParent ); |
|||
~KIPYTHON_FRAME() override; |
|||
|
|||
void LoadSettings( APP_SETTINGS_BASE* aCfg ) override {} |
|||
void SaveSettings( APP_SETTINGS_BASE* aCfg ) override {} |
|||
|
|||
wxWindow* GetToolCanvas() const override { return nullptr;} |
|||
|
|||
void ExecuteRemoteCommand( const char* cmdline ) override {} |
|||
|
|||
void KiwayMailIn( KIWAY_EXPRESS& aEvent ) override {} |
|||
void ProjectChanged() override {} |
|||
|
|||
void SetupPythonEditor(); |
|||
private: |
|||
|
|||
void redirectStdio(); |
|||
bool canCloseWindow( wxCloseEvent& aCloseEvent ) override { return true; } |
|||
void doCloseWindow() override {} |
|||
|
|||
long m_stdio; |
|||
}; |
|||
|
|||
|
|||
|
|||
#endif /* SCRIPTING_KIPYTHON_FRAME_H_ */ |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue