aboutsummaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
authorMiodrag Milanovic <mmicko@gmail.com>2018-12-14 17:20:25 +0100
committerMiodrag Milanovic <mmicko@gmail.com>2018-12-14 17:20:25 +0100
commite0b4a2eeab91696e54d9ff3acc319d99ab9b96f9 (patch)
tree79b6bc1d50c75b6b7bb78b5d842d9c75178c4a09 /gui
parent19cffde375fe63e36bfd880727bdc0a04a2ccf32 (diff)
downloadnextpnr-e0b4a2eeab91696e54d9ff3acc319d99ab9b96f9.tar.gz
nextpnr-e0b4a2eeab91696e54d9ff3acc319d99ab9b96f9.tar.bz2
nextpnr-e0b4a2eeab91696e54d9ff3acc319d99ab9b96f9.zip
Add GUI for executing python file
Diffstat (limited to 'gui')
-rw-r--r--gui/base.qrc1
-rw-r--r--gui/basewindow.cc18
-rw-r--r--gui/basewindow.h5
-rw-r--r--gui/pyconsole.cc17
-rw-r--r--gui/pyconsole.h1
-rw-r--r--gui/pythontab.cc2
-rw-r--r--gui/pythontab.h1
-rw-r--r--gui/resources/py.pngbin0 -> 2277 bytes
8 files changed, 45 insertions, 0 deletions
diff --git a/gui/base.qrc b/gui/base.qrc
index 8f58f585..644b16a6 100644
--- a/gui/base.qrc
+++ b/gui/base.qrc
@@ -22,5 +22,6 @@
<file>resources/route.png</file>
<file>resources/time_add.png</file>
<file>resources/open_json.png</file>
+ <file>resources/py.png</file>
</qresource>
</RCC>
diff --git a/gui/basewindow.cc b/gui/basewindow.cc
index 49c2d8d5..346efb88 100644
--- a/gui/basewindow.cc
+++ b/gui/basewindow.cc
@@ -189,6 +189,12 @@ void BaseMainWindow::createMenusAndBars()
actionRoute->setEnabled(false);
connect(actionRoute, &QAction::triggered, task, &TaskManager::route);
+ actionExecutePy = new QAction("Execute Python", this);
+ actionExecutePy->setIcon(QIcon(":/icons/resources/py.png"));
+ actionExecutePy->setStatusTip("Execute Python script");
+ actionExecutePy->setEnabled(true);
+ connect(actionExecutePy, &QAction::triggered, this, &BaseMainWindow::execute_python);
+
// Worker control toolbar actions
actionPlay = new QAction("Play", this);
actionPlay->setIcon(QIcon(":/icons/resources/control_play.png"));
@@ -249,6 +255,8 @@ void BaseMainWindow::createMenusAndBars()
menuDesign->addAction(actionAssignBudget);
menuDesign->addAction(actionPlace);
menuDesign->addAction(actionRoute);
+ menuDesign->addSeparator();
+ menuDesign->addAction(actionExecutePy);
// Add Help menu actions
menuHelp->addAction(actionAbout);
@@ -268,6 +276,7 @@ void BaseMainWindow::createMenusAndBars()
mainActionBar->addAction(actionAssignBudget);
mainActionBar->addAction(actionPlace);
mainActionBar->addAction(actionRoute);
+ mainActionBar->addAction(actionExecutePy);
// Add worker control toolbar
QToolBar *workerControlToolBar = new QToolBar("Worker");
@@ -412,6 +421,7 @@ void BaseMainWindow::disableActions()
actionAssignBudget->setEnabled(false);
actionPlace->setEnabled(false);
actionRoute->setEnabled(false);
+ actionExecutePy->setEnabled(true);
actionPlay->setEnabled(false);
actionPause->setEnabled(false);
@@ -454,6 +464,14 @@ void BaseMainWindow::open_proj()
}
}
+void BaseMainWindow::execute_python()
+{
+ QString fileName = QFileDialog::getOpenFileName(this, QString("Execute Python"), QString(), QString("*.py"));
+ if (!fileName.isEmpty()) {
+ console->execute_python(fileName.toStdString());
+ }
+}
+
void BaseMainWindow::notifyChangeContext() { Q_EMIT contextChanged(ctx.get()); }
void BaseMainWindow::save_proj()
{
diff --git a/gui/basewindow.h b/gui/basewindow.h
index eb32033a..0b2d3fbc 100644
--- a/gui/basewindow.h
+++ b/gui/basewindow.h
@@ -78,6 +78,8 @@ class BaseMainWindow : public QMainWindow
void budget();
void place();
+ void execute_python();
+
void pack_finished(bool status);
void budget_finish(bool status);
void place_finished(bool status);
@@ -122,6 +124,9 @@ class BaseMainWindow : public QMainWindow
QAction *actionAssignBudget;
QAction *actionPlace;
QAction *actionRoute;
+
+ QAction *actionExecutePy;
+
QAction *actionPlay;
QAction *actionPause;
QAction *actionStop;
diff --git a/gui/pyconsole.cc b/gui/pyconsole.cc
index 0ee393ce..d015aea2 100644
--- a/gui/pyconsole.cc
+++ b/gui/pyconsole.cc
@@ -76,4 +76,21 @@ void PythonConsole::moveCursorToEnd()
setTextCursor(cursor);
}
+void PythonConsole::execute_python(std::string filename)
+{
+ int errorCode = 0;
+ std::string res;
+ res = pyinterpreter_execute_file(filename.c_str(), &errorCode);
+ if (res.size()) {
+ if (errorCode) {
+ setTextColor(ERROR_COLOR);
+ } else {
+ setTextColor(OUTPUT_COLOR);
+ }
+ append(res.c_str());
+ setTextColor(NORMAL_COLOR);
+ moveCursorToEnd();
+ }
+}
+
NEXTPNR_NAMESPACE_END
diff --git a/gui/pyconsole.h b/gui/pyconsole.h
index 9dbd3b95..977242f3 100644
--- a/gui/pyconsole.h
+++ b/gui/pyconsole.h
@@ -43,6 +43,7 @@ class PythonConsole : public QTextEdit, public ParseListener
void displayString(QString text);
void moveCursorToEnd();
virtual void parseEvent(const ParseMessage &message);
+ void execute_python(std::string filename);
protected:
static const QColor NORMAL_COLOR;
diff --git a/gui/pythontab.cc b/gui/pythontab.cc
index 80d731e9..827f1907 100644
--- a/gui/pythontab.cc
+++ b/gui/pythontab.cc
@@ -114,4 +114,6 @@ void PythonTab::clearBuffer() { console->clear(); }
void PythonTab::info(std::string str) { console->displayString(str.c_str()); }
+void PythonTab::execute_python(std::string filename) { console->execute_python(filename); }
+
NEXTPNR_NAMESPACE_END
diff --git a/gui/pythontab.h b/gui/pythontab.h
index 134874b6..860bf1c3 100644
--- a/gui/pythontab.h
+++ b/gui/pythontab.h
@@ -45,6 +45,7 @@ class PythonTab : public QWidget
void newContext(Context *ctx);
void info(std::string str);
void clearBuffer();
+ void execute_python(std::string filename);
private:
PythonConsole *console;
diff --git a/gui/resources/py.png b/gui/resources/py.png
new file mode 100644
index 00000000..9cc6e522
--- /dev/null
+++ b/gui/resources/py.png
Binary files differ