diff options
author | Miodrag Milanovic <mmicko@gmail.com> | 2018-06-27 11:45:19 +0200 |
---|---|---|
committer | Miodrag Milanovic <mmicko@gmail.com> | 2018-06-27 11:45:19 +0200 |
commit | bafb4702c7176a08e4a9b2088297071a7bed6656 (patch) | |
tree | a59132f64cba845f2b65c02441229fa26a00aa9e /gui | |
parent | 9bb489936078980e98fc873845b2ca64ddb490fb (diff) | |
download | nextpnr-bafb4702c7176a08e4a9b2088297071a7bed6656.tar.gz nextpnr-bafb4702c7176a08e4a9b2088297071a7bed6656.tar.bz2 nextpnr-bafb4702c7176a08e4a9b2088297071a7bed6656.zip |
reinit python tab
Diffstat (limited to 'gui')
-rw-r--r-- | gui/basewindow.cc | 4 | ||||
-rw-r--r-- | gui/pythontab.cc | 33 | ||||
-rw-r--r-- | gui/pythontab.h | 5 |
3 files changed, 34 insertions, 8 deletions
diff --git a/gui/basewindow.cc b/gui/basewindow.cc index 69f4f622..2e8d7c85 100644 --- a/gui/basewindow.cc +++ b/gui/basewindow.cc @@ -74,7 +74,9 @@ BaseMainWindow::BaseMainWindow(QWidget *parent) : QMainWindow(parent), ctx(nullp tabWidget = new QTabWidget();
#ifndef NO_PYTHON
- tabWidget->addTab(new PythonTab(), "Python");
+ PythonTab *pythontab = new PythonTab();
+ tabWidget->addTab(pythontab, "Python");
+ connect(this, SIGNAL(contextChanged(Context*)), pythontab, SLOT(newContext(Context*)));
#endif
info = new InfoTab();
tabWidget->addTab(info, "Info");
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)); }
diff --git a/gui/pythontab.h b/gui/pythontab.h index 40de0ebe..871d2450 100644 --- a/gui/pythontab.h +++ b/gui/pythontab.h @@ -37,6 +37,7 @@ class PythonTab : public QWidget public:
explicit PythonTab(QWidget *parent = 0);
+ ~PythonTab();
private:
void print(std::string line);
@@ -45,12 +46,14 @@ class PythonTab : public QWidget void editLineReturnPressed(QString text);
void showContextMenu(const QPoint &pt);
void clearBuffer();
-
+ public Q_SLOTS:
+ void newContext(Context *ctx);
private:
QPlainTextEdit *plainTextEdit;
LineEditor *lineEdit;
QMenu *contextMenu;
emb::stdout_write_type write;
+ bool initialized;
};
NEXTPNR_NAMESPACE_END
|