Split per widgets
This commit is contained in:
parent
8c46cc2fce
commit
9c0640240f
@ -79,18 +79,114 @@ class PipTreeItem : public ElementTreeItem
|
||||
IdString data;
|
||||
};
|
||||
|
||||
MainWindow::MainWindow(Design *_design, QWidget *parent)
|
||||
: QMainWindow(parent), ui(new Ui::MainWindow), design(_design)
|
||||
PythonTab::PythonTab(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
PyImport_ImportModule("emb");
|
||||
|
||||
// Add text area for Python output and input line
|
||||
plainTextEdit = new QPlainTextEdit();
|
||||
plainTextEdit->setReadOnly(true);
|
||||
plainTextEdit->setMinimumHeight(100);
|
||||
lineEdit = new QLineEdit();
|
||||
lineEdit->setMinimumHeight(30);
|
||||
lineEdit->setMaximumHeight(30);
|
||||
|
||||
QGridLayout *mainLayout = new QGridLayout();
|
||||
mainLayout->addWidget(plainTextEdit, 0, 0);
|
||||
mainLayout->addWidget(lineEdit, 1, 0);
|
||||
setLayout(mainLayout);
|
||||
|
||||
connect(lineEdit, SIGNAL(returnPressed()), this,
|
||||
SLOT(editLineReturnPressed()));
|
||||
|
||||
write = [this](std::string s) {
|
||||
plainTextEdit->moveCursor(QTextCursor::End);
|
||||
plainTextEdit->insertPlainText(s.c_str());
|
||||
plainTextEdit->moveCursor(QTextCursor::End);
|
||||
};
|
||||
emb::set_stdout(write);
|
||||
}
|
||||
|
||||
void handle_system_exit() { exit(-1); }
|
||||
|
||||
int PythonTab::executePython(std::string command)
|
||||
{
|
||||
PyObject *m, *d, *v;
|
||||
m = PyImport_AddModule("__main__");
|
||||
if (m == NULL)
|
||||
return -1;
|
||||
d = PyModule_GetDict(m);
|
||||
v = PyRun_StringFlags(command.c_str(),
|
||||
(command.empty() ? Py_file_input : Py_single_input),
|
||||
d, d, NULL);
|
||||
if (v == NULL) {
|
||||
PyObject *exception, *v, *tb;
|
||||
|
||||
if (PyErr_ExceptionMatches(PyExc_SystemExit)) {
|
||||
handle_system_exit();
|
||||
}
|
||||
PyErr_Fetch(&exception, &v, &tb);
|
||||
if (exception == NULL)
|
||||
return 0;
|
||||
PyErr_NormalizeException(&exception, &v, &tb);
|
||||
if (tb == NULL) {
|
||||
tb = Py_None;
|
||||
Py_INCREF(tb);
|
||||
}
|
||||
PyException_SetTraceback(v, tb);
|
||||
if (exception == NULL)
|
||||
return 0;
|
||||
PyErr_Clear();
|
||||
|
||||
PyObject *objectsRepresentation = PyObject_Str(v);
|
||||
std::string errorStr =
|
||||
PyUnicode_AsUTF8(objectsRepresentation) + std::string("\n");
|
||||
plainTextEdit->moveCursor(QTextCursor::End);
|
||||
plainTextEdit->insertPlainText(errorStr.c_str());
|
||||
plainTextEdit->moveCursor(QTextCursor::End);
|
||||
Py_DECREF(objectsRepresentation);
|
||||
Py_XDECREF(exception);
|
||||
Py_XDECREF(v);
|
||||
Py_XDECREF(tb);
|
||||
return -1;
|
||||
}
|
||||
Py_DECREF(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PythonTab::editLineReturnPressed()
|
||||
{
|
||||
std::string input = lineEdit->text().toStdString();
|
||||
plainTextEdit->moveCursor(QTextCursor::End);
|
||||
plainTextEdit->insertPlainText(std::string(">>> " + input + "\n").c_str());
|
||||
plainTextEdit->moveCursor(QTextCursor::End);
|
||||
plainTextEdit->update();
|
||||
lineEdit->clear();
|
||||
int error = executePython(input);
|
||||
}
|
||||
|
||||
InfoTab::InfoTab(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
// Add text area for Python output and input line
|
||||
plainTextEdit = new QPlainTextEdit();
|
||||
plainTextEdit->setReadOnly(true);
|
||||
|
||||
QGridLayout *mainLayout = new QGridLayout();
|
||||
mainLayout->addWidget(plainTextEdit);
|
||||
setLayout(mainLayout);
|
||||
}
|
||||
|
||||
void InfoTab::info(std::string str)
|
||||
{
|
||||
plainTextEdit->moveCursor(QTextCursor::End);
|
||||
plainTextEdit->insertPlainText(str.c_str());
|
||||
plainTextEdit->moveCursor(QTextCursor::End);
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(Design *_design, QWidget *parent)
|
||||
: QMainWindow(parent), ui(new Ui::MainWindow), design(_design)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
std::string title = "nextpnr-ice40 - " + design->chip.getChipName();
|
||||
setWindowTitle(title.c_str());
|
||||
|
||||
@ -150,18 +246,11 @@ MainWindow::MainWindow(Design *_design, QWidget *parent)
|
||||
connect(ui->treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
|
||||
SLOT(onItemClicked(QTreeWidgetItem *, int)));
|
||||
|
||||
// Add text area for Python output and input line
|
||||
plainTextEdit = new QPlainTextEdit();
|
||||
plainTextEdit->setReadOnly(true);
|
||||
plainTextEdit->setMinimumHeight(50);
|
||||
plainTextEdit->setMaximumHeight(200);
|
||||
ui->splitter->addWidget(plainTextEdit);
|
||||
lineEdit = new QLineEdit();
|
||||
lineEdit->setMinimumHeight(30);
|
||||
lineEdit->setMaximumHeight(30);
|
||||
ui->splitter->addWidget(lineEdit);
|
||||
connect(lineEdit, SIGNAL(returnPressed()), this,
|
||||
SLOT(editLineReturnPressed()));
|
||||
tabWidget = new QTabWidget();
|
||||
tabWidget->addTab(new PythonTab(), "Python");
|
||||
info = new InfoTab();
|
||||
tabWidget->addTab(info, "Info");
|
||||
ui->splitter->addWidget(tabWidget);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -237,68 +326,5 @@ void MainWindow::prepareMenu(const QPoint &pos)
|
||||
|
||||
void MainWindow::selectObject()
|
||||
{
|
||||
plainTextEdit->moveCursor(QTextCursor::End);
|
||||
plainTextEdit->insertPlainText(
|
||||
std::string("selected " + itemContextMenu->text(0).toStdString() +
|
||||
"\n")
|
||||
.c_str());
|
||||
plainTextEdit->moveCursor(QTextCursor::End);
|
||||
}
|
||||
|
||||
void handle_system_exit() { exit(-1); }
|
||||
|
||||
int MainWindow::executePython(std::string command)
|
||||
{
|
||||
PyObject *m, *d, *v;
|
||||
m = PyImport_AddModule("__main__");
|
||||
if (m == NULL)
|
||||
return -1;
|
||||
d = PyModule_GetDict(m);
|
||||
v = PyRun_StringFlags(command.c_str(),
|
||||
(command.empty() ? Py_file_input : Py_single_input),
|
||||
d, d, NULL);
|
||||
if (v == NULL) {
|
||||
PyObject *exception, *v, *tb;
|
||||
|
||||
if (PyErr_ExceptionMatches(PyExc_SystemExit)) {
|
||||
handle_system_exit();
|
||||
}
|
||||
PyErr_Fetch(&exception, &v, &tb);
|
||||
if (exception == NULL)
|
||||
return 0;
|
||||
PyErr_NormalizeException(&exception, &v, &tb);
|
||||
if (tb == NULL) {
|
||||
tb = Py_None;
|
||||
Py_INCREF(tb);
|
||||
}
|
||||
PyException_SetTraceback(v, tb);
|
||||
if (exception == NULL)
|
||||
return 0;
|
||||
PyErr_Clear();
|
||||
|
||||
PyObject *objectsRepresentation = PyObject_Str(v);
|
||||
std::string errorStr =
|
||||
PyUnicode_AsUTF8(objectsRepresentation) + std::string("\n");
|
||||
plainTextEdit->moveCursor(QTextCursor::End);
|
||||
plainTextEdit->insertPlainText(errorStr.c_str());
|
||||
plainTextEdit->moveCursor(QTextCursor::End);
|
||||
Py_DECREF(objectsRepresentation);
|
||||
Py_XDECREF(exception);
|
||||
Py_XDECREF(v);
|
||||
Py_XDECREF(tb);
|
||||
return -1;
|
||||
}
|
||||
Py_DECREF(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MainWindow::editLineReturnPressed()
|
||||
{
|
||||
std::string input = lineEdit->text().toStdString();
|
||||
plainTextEdit->moveCursor(QTextCursor::End);
|
||||
plainTextEdit->insertPlainText(std::string(">>> " + input + "\n").c_str());
|
||||
plainTextEdit->moveCursor(QTextCursor::End);
|
||||
plainTextEdit->update();
|
||||
lineEdit->clear();
|
||||
int error = executePython(input);
|
||||
info->info("selected " + itemContextMenu->text(0).toStdString() + "\n");
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <QLineEdit>
|
||||
#include <QMainWindow>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QTabWidget>
|
||||
|
||||
// FIXME
|
||||
USING_NEXTPNR_NAMESPACE
|
||||
@ -18,6 +19,36 @@ namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class PythonTab : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PythonTab(QWidget *parent = 0);
|
||||
|
||||
private:
|
||||
int executePython(std::string command);
|
||||
private Q_SLOTS:
|
||||
void editLineReturnPressed();
|
||||
|
||||
private:
|
||||
QPlainTextEdit *plainTextEdit;
|
||||
QLineEdit *lineEdit;
|
||||
emb::stdout_write_type write;
|
||||
};
|
||||
|
||||
class InfoTab : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InfoTab(QWidget *parent = 0);
|
||||
void info(std::string str);
|
||||
|
||||
private:
|
||||
QPlainTextEdit *plainTextEdit;
|
||||
};
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -28,18 +59,15 @@ class MainWindow : public QMainWindow
|
||||
Design *getDesign() { return design; }
|
||||
|
||||
private:
|
||||
int executePython(std::string command);
|
||||
void addProperty(QtVariantProperty *property, const QString &id);
|
||||
|
||||
private Q_SLOTS:
|
||||
void editLineReturnPressed();
|
||||
void prepareMenu(const QPoint &pos);
|
||||
void selectObject();
|
||||
void onItemClicked(QTreeWidgetItem *item, int);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
emb::stdout_write_type write;
|
||||
Design *design;
|
||||
QtVariantPropertyManager *variantManager;
|
||||
QtVariantEditorFactory *variantFactory;
|
||||
@ -49,8 +77,8 @@ class MainWindow : public QMainWindow
|
||||
QMap<QtProperty *, QString> propertyToId;
|
||||
QMap<QString, QtVariantProperty *> idToProperty;
|
||||
|
||||
QPlainTextEdit *plainTextEdit;
|
||||
QLineEdit *lineEdit;
|
||||
QTabWidget *tabWidget;
|
||||
InfoTab *info;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
Loading…
Reference in New Issue
Block a user