Merge pull request #180 from YosysHQ/python_execute_gui
Add GUI for executing python file
This commit is contained in:
commit
7fa1329508
@ -153,3 +153,25 @@ void pyinterpreter_release()
|
|||||||
{
|
{
|
||||||
PyEval_ReleaseThread(m_threadState);
|
PyEval_ReleaseThread(m_threadState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string pyinterpreter_execute_file(const char *python_file, int *errorCode)
|
||||||
|
{
|
||||||
|
PyEval_AcquireThread(m_threadState);
|
||||||
|
*errorCode = 0;
|
||||||
|
std::string res;
|
||||||
|
FILE *fp = fopen(python_file, "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
*errorCode = 1;
|
||||||
|
res = "Fatal error: file not found " + std::string(python_file) + "\n";
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PyRun_SimpleFile(fp, python_file)==-1) {
|
||||||
|
*errorCode = 1;
|
||||||
|
PyErr_Print();
|
||||||
|
}
|
||||||
|
res = redirector_take_output(m_threadState);
|
||||||
|
|
||||||
|
PyEval_ReleaseThread(m_threadState);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
@ -33,4 +33,5 @@ void pyinterpreter_initialize();
|
|||||||
void pyinterpreter_finalize();
|
void pyinterpreter_finalize();
|
||||||
void pyinterpreter_aquire();
|
void pyinterpreter_aquire();
|
||||||
void pyinterpreter_release();
|
void pyinterpreter_release();
|
||||||
|
std::string pyinterpreter_execute_file(const char *python_file, int *errorCode);
|
||||||
#endif // PYINTERPRETER_H
|
#endif // PYINTERPRETER_H
|
||||||
|
@ -22,5 +22,6 @@
|
|||||||
<file>resources/route.png</file>
|
<file>resources/route.png</file>
|
||||||
<file>resources/time_add.png</file>
|
<file>resources/time_add.png</file>
|
||||||
<file>resources/open_json.png</file>
|
<file>resources/open_json.png</file>
|
||||||
|
<file>resources/py.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
@ -189,6 +189,12 @@ void BaseMainWindow::createMenusAndBars()
|
|||||||
actionRoute->setEnabled(false);
|
actionRoute->setEnabled(false);
|
||||||
connect(actionRoute, &QAction::triggered, task, &TaskManager::route);
|
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
|
// Worker control toolbar actions
|
||||||
actionPlay = new QAction("Play", this);
|
actionPlay = new QAction("Play", this);
|
||||||
actionPlay->setIcon(QIcon(":/icons/resources/control_play.png"));
|
actionPlay->setIcon(QIcon(":/icons/resources/control_play.png"));
|
||||||
@ -249,6 +255,8 @@ void BaseMainWindow::createMenusAndBars()
|
|||||||
menuDesign->addAction(actionAssignBudget);
|
menuDesign->addAction(actionAssignBudget);
|
||||||
menuDesign->addAction(actionPlace);
|
menuDesign->addAction(actionPlace);
|
||||||
menuDesign->addAction(actionRoute);
|
menuDesign->addAction(actionRoute);
|
||||||
|
menuDesign->addSeparator();
|
||||||
|
menuDesign->addAction(actionExecutePy);
|
||||||
|
|
||||||
// Add Help menu actions
|
// Add Help menu actions
|
||||||
menuHelp->addAction(actionAbout);
|
menuHelp->addAction(actionAbout);
|
||||||
@ -268,6 +276,7 @@ void BaseMainWindow::createMenusAndBars()
|
|||||||
mainActionBar->addAction(actionAssignBudget);
|
mainActionBar->addAction(actionAssignBudget);
|
||||||
mainActionBar->addAction(actionPlace);
|
mainActionBar->addAction(actionPlace);
|
||||||
mainActionBar->addAction(actionRoute);
|
mainActionBar->addAction(actionRoute);
|
||||||
|
mainActionBar->addAction(actionExecutePy);
|
||||||
|
|
||||||
// Add worker control toolbar
|
// Add worker control toolbar
|
||||||
QToolBar *workerControlToolBar = new QToolBar("Worker");
|
QToolBar *workerControlToolBar = new QToolBar("Worker");
|
||||||
@ -412,6 +421,7 @@ void BaseMainWindow::disableActions()
|
|||||||
actionAssignBudget->setEnabled(false);
|
actionAssignBudget->setEnabled(false);
|
||||||
actionPlace->setEnabled(false);
|
actionPlace->setEnabled(false);
|
||||||
actionRoute->setEnabled(false);
|
actionRoute->setEnabled(false);
|
||||||
|
actionExecutePy->setEnabled(true);
|
||||||
|
|
||||||
actionPlay->setEnabled(false);
|
actionPlay->setEnabled(false);
|
||||||
actionPause->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::notifyChangeContext() { Q_EMIT contextChanged(ctx.get()); }
|
||||||
void BaseMainWindow::save_proj()
|
void BaseMainWindow::save_proj()
|
||||||
{
|
{
|
||||||
|
@ -78,6 +78,8 @@ class BaseMainWindow : public QMainWindow
|
|||||||
void budget();
|
void budget();
|
||||||
void place();
|
void place();
|
||||||
|
|
||||||
|
void execute_python();
|
||||||
|
|
||||||
void pack_finished(bool status);
|
void pack_finished(bool status);
|
||||||
void budget_finish(bool status);
|
void budget_finish(bool status);
|
||||||
void place_finished(bool status);
|
void place_finished(bool status);
|
||||||
@ -122,6 +124,9 @@ class BaseMainWindow : public QMainWindow
|
|||||||
QAction *actionAssignBudget;
|
QAction *actionAssignBudget;
|
||||||
QAction *actionPlace;
|
QAction *actionPlace;
|
||||||
QAction *actionRoute;
|
QAction *actionRoute;
|
||||||
|
|
||||||
|
QAction *actionExecutePy;
|
||||||
|
|
||||||
QAction *actionPlay;
|
QAction *actionPlay;
|
||||||
QAction *actionPause;
|
QAction *actionPause;
|
||||||
QAction *actionStop;
|
QAction *actionStop;
|
||||||
|
@ -76,4 +76,21 @@ void PythonConsole::moveCursorToEnd()
|
|||||||
setTextCursor(cursor);
|
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
|
NEXTPNR_NAMESPACE_END
|
||||||
|
@ -43,6 +43,7 @@ class PythonConsole : public QTextEdit, public ParseListener
|
|||||||
void displayString(QString text);
|
void displayString(QString text);
|
||||||
void moveCursorToEnd();
|
void moveCursorToEnd();
|
||||||
virtual void parseEvent(const ParseMessage &message);
|
virtual void parseEvent(const ParseMessage &message);
|
||||||
|
void execute_python(std::string filename);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static const QColor NORMAL_COLOR;
|
static const QColor NORMAL_COLOR;
|
||||||
|
@ -114,4 +114,6 @@ void PythonTab::clearBuffer() { console->clear(); }
|
|||||||
|
|
||||||
void PythonTab::info(std::string str) { console->displayString(str.c_str()); }
|
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
|
NEXTPNR_NAMESPACE_END
|
||||||
|
@ -45,6 +45,7 @@ class PythonTab : public QWidget
|
|||||||
void newContext(Context *ctx);
|
void newContext(Context *ctx);
|
||||||
void info(std::string str);
|
void info(std::string str);
|
||||||
void clearBuffer();
|
void clearBuffer();
|
||||||
|
void execute_python(std::string filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PythonConsole *console;
|
PythonConsole *console;
|
||||||
|
BIN
gui/resources/py.png
Normal file
BIN
gui/resources/py.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
Loading…
Reference in New Issue
Block a user