aboutsummaryrefslogtreecommitdiffstats
path: root/gui/pythontab.cc
diff options
context:
space:
mode:
authorMiodrag Milanovic <mmicko@gmail.com>2018-06-27 11:45:19 +0200
committerMiodrag Milanovic <mmicko@gmail.com>2018-06-27 11:45:19 +0200
commitbafb4702c7176a08e4a9b2088297071a7bed6656 (patch)
treea59132f64cba845f2b65c02441229fa26a00aa9e /gui/pythontab.cc
parent9bb489936078980e98fc873845b2ca64ddb490fb (diff)
downloadnextpnr-bafb4702c7176a08e4a9b2088297071a7bed6656.tar.gz
nextpnr-bafb4702c7176a08e4a9b2088297071a7bed6656.tar.bz2
nextpnr-bafb4702c7176a08e4a9b2088297071a7bed6656.zip
reinit python tab
Diffstat (limited to 'gui/pythontab.cc')
-rw-r--r--gui/pythontab.cc33
1 files changed, 27 insertions, 6 deletions
diff --git a/gui/pythontab.cc b/gui/pythontab.cc
index 397920d9..816039ba 100644
--- a/gui/pythontab.cc
+++ b/gui/pythontab.cc
@@ -25,10 +25,8 @@
NEXTPNR_NAMESPACE_BEGIN
-PythonTab::PythonTab(QWidget *parent) : QWidget(parent)
+PythonTab::PythonTab(QWidget *parent) : QWidget(parent),initialized(false)
{
- PyImport_ImportModule("emb");
-
// Add text area for Python output and input line
plainTextEdit = new QPlainTextEdit();
plainTextEdit->setReadOnly(true);
@@ -57,7 +55,25 @@ PythonTab::PythonTab(QWidget *parent) : QWidget(parent)
setLayout(mainLayout);
connect(lineEdit, SIGNAL(textLineInserted(QString)), this, SLOT(editLineReturnPressed(QString)));
+}
+
+PythonTab::~PythonTab()
+{
+ if (initialized)
+ deinit_python();
+}
+void PythonTab::newContext(Context *ctx)
+{
+ if (initialized)
+ deinit_python();
+
+ plainTextEdit->clear();
+
+ init_python("nextpnr", !initialized);
+ python_export_global("ctx", ctx);
+
+ PyImport_ImportModule("emb");
write = [this](std::string s) {
plainTextEdit->moveCursor(QTextCursor::End);
plainTextEdit->insertPlainText(s.c_str());
@@ -65,6 +81,8 @@ PythonTab::PythonTab(QWidget *parent) : QWidget(parent)
};
emb::set_stdout(write);
+ initialized = true;
+
char buff[1024];
sprintf(buff, "Python %s on %s\n", Py_GetVersion(), Py_GetPlatform());
print(buff);
@@ -121,9 +139,12 @@ int PythonTab::executePython(std::string &command)
void PythonTab::editLineReturnPressed(QString text)
{
- std::string input = text.toStdString();
- print(std::string(">>> " + input + "\n"));
- executePython(input);
+ if (initialized)
+ {
+ std::string input = text.toStdString();
+ print(std::string(">>> " + input + "\n"));
+ executePython(input);
+ }
}
void PythonTab::showContextMenu(const QPoint &pt) { contextMenu->exec(mapToGlobal(pt)); }