22 #include "Sample/Multilayer/MultiLayer.h"
23 #include "Sim/Export/ExportToPython.h"
26 #include <QStackedWidget>
28 #include <QVBoxLayout>
32 const int accumulateUpdatesDuringMsec = 20.;
37 , m_textEdit(new QTextEdit)
38 , m_highlighter(nullptr)
39 , m_updateTimer(new
UpdateTimer(accumulateUpdatesDuringMsec, this))
41 , m_currentMultiLayerItem(nullptr)
43 setWindowTitle(
"Python Script");
44 setObjectName(
"ScriptPanel");
46 m_textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
48 auto* mainLayout =
new QVBoxLayout(
this);
49 mainLayout->setContentsMargins(0, 0, 0, 0);
53 QFont textFont(
"Monospace");
58 Qt::UniqueConnection);
77 m_textEdit->setLineWrapMode(QTextEdit::NoWrap);
80 const int oldScrollbarValue =
m_textEdit->verticalScrollBar()->value();
83 if (!codeSnippet.isEmpty())
88 m_textEdit->verticalScrollBar()->setValue(oldScrollbarValue);
111 result.append(QString::fromStdString(Py::Export::sampleCode(*sample)));
112 }
catch (
const std::exception& ex) {
114 QString(
"Generation of Python Script failed. Code is not complete.\n\n"
115 "It can happen if sample requires further assembling or some of sample "
116 "parameters are not valid. See details below.\n\n%1")
117 .arg(QString::fromStdString(ex.what()));
Defines class CautionSign.
Defines class DesignerHelper.
Defines class MultiLayerItem.
Defines class PythonSyntaxHighlighter.
Defines namespace GUI::Transform::ToCore.
Defines class SampleDesigner.
Defines class UpdateTimer.
The CautionSign controls appearance of CautionSignWidget on top of parent widget.
void clear()
Clears caution message;.
void setCautionMessage(const QString &cautionMessage)
Shows caution sign on the screen. If clear of previous caution sign had happened just few msec ago,...
static int getPythonEditorFontSize()
Implementation of highlighting for Python code.
UpdateTimer * m_updateTimer
ScriptPanel(QWidget *parent)
void updateEditor()
Update the editor with the script content.
void showEvent(QShowEvent *) override
QString generateCodeSnippet()
generates string representing code snippet for all multi layers in the model
MultiLayerItem * m_currentMultiLayerItem
void hideEvent(QHideEvent *) override
CautionSign * m_cautionSign
void setCurrentSample(MultiLayerItem *sampleItem)
PythonSyntaxHighlighter * m_highlighter
The UpdateTimer class accumulates update requests during certain period of time, and at the end of th...