7 #include <QPlainTextEdit>
12 #include <QFileDialog>
29 QStringList _inputList;
36 qDebug() <<
"ui.script";
39 b->setCanvas((
void*)parent);
41 b->_editor->setContext(pyWrapper::inst().withCanvas((QObject*)parent));
43 QString data1 = b->properties()->extractFromPdFileString(objectData);
46 b->setObjectData(
"ui.script");
49 QString data = b->properties()->get(
"Script")->asQString().split(
"\\n ").join(
"\n");
50 b->_editor->document()->setPlainText(data);
53 std::string message =
"ui.script";
58 qDebug(
"bad pd canvas instance");
60 QPoint pos = QPoint(0, 0);
61 new_obj = cmp_create_object(pdCanvas, message, pos.x(), pos.y());
65 qDebug(
"created ui.script %s | ptr %lu\n", message.c_str(), (long)new_obj);
68 b->_editor->setContext(pyWrapper::inst().withCanvasPdObjectAndInput((UIObject*)parent, new_obj, &b->_inputList));
74 qDebug(
"Error: no such object %s", message.c_str());
84 UIObject::initProperties();
87 properties()->create(
"Script",
"Data",
"0.1", list);
90 virtual void paint(QPainter* p,
const QStyleOptionGraphicsItem* option, QWidget*)
92 p->setClipRect(option->exposedRect);
94 QBrush brush(bgColor());
96 p->drawRect(boundingRect());
97 p->setBrush(QBrush());
101 p->setPen(QPen(QColor(0, 192, 255), 1, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin));
102 }
else if (_clicked) {
103 p->setPen(QPen(QColor(0, 192, 255), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
105 p->setPen(QPen(QColor(128, 128, 128), 1, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin));
108 p->drawRect(0, 0, width(), height());
114 UIObject::resizeEvent();
115 _editor->setFixedWidth(width() - 5);
116 _editor->setFixedHeight(height() - 25);
124 emit selectBox(
this, ev);
125 dragOffset = ev->pos().toPoint();
136 if (event->buttons() & Qt::LeftButton) {
137 emit moveBox(
this, event);
143 setCursor(QCursor(Qt::PointingHandCursor));
145 setCursor(QCursor(Qt::ArrowCursor));
153 setObjectData(message);
160 qDebug(
"script << pd message");
161 qDebug() << (long)uiobj << msg.
size();
167 for (
size_t i = 0; i < msg.
size(); i++) {
171 x->_inputList = list;
178 return _editor->document()->toPlainText().split(QRegExp(
"[\r\n]"), QString::SkipEmptyParts);
183 UIObject::setPdObject(obj);
189 qDebug() <<
"connect ui: uiobj " << (long)
this <<
" pdobj " << (
long)pdObject();
197 qDebug() <<
"btnRun";
201 PythonQtObjectPtr context =
_editor->context();
202 QString _stdOut =
"";
203 QString _stdErr =
"";
205 PyObject* dict = NULL;
206 if (PyModule_Check(context)) {
207 dict = PyModule_GetDict(context);
208 }
else if (PyDict_Check(context)) {
214 QString line = list.join(
"\r\n");
216 if (!line.isNull()) {
219 context.evalScript(line);
221 qDebug() <<
"line: " << line;
225 PythonQt::self()->handleError();
230 cmp_post((std::string)
"Python: " + _stdOut.toStdString());
233 cmp_post((std::string)
"Python error: " + _stdOut.toStdString());
239 void editorChanged();
243 QString fname = QFileDialog::getOpenFileName(0, QString(
"Open Python script"), QString(
"~/"), QString(
"*.py"), 0, 0);
247 file.open(QFile::ReadOnly | QFile::Text);
249 QTextStream ReadFile(&file);
250 _editor->document()->setPlainText(ReadFile.readAll());
257 QString fname = QFileDialog::getSaveFileName(0, QString(
"Save Python script"), QString(
"~/"), QString(
"*.py"), 0, 0);
261 file.open(QFile::WriteOnly | QFile::Text);
263 QTextStream WriteFile(&file);
264 WriteFile <<
_editor->document()->toPlainText();
gui object: script editor box (ui.script)
Definition: UIScript copy.h:23
QStringList getEditorData()
Definition: UIScript copy.h:176
static UIObject * createObject(QString objectData, t_canvas *pdCanvas, QGraphicsView *parent=0)
Definition: UIScript copy.h:34
static void updateUI(void *uiobj, ceammc::AtomList msg)
Definition: UIScript copy.h:158
void setPdMessage(QString message)
Definition: UIScript copy.h:151
void resizeEvent()
Definition: UIScript copy.h:112
virtual void paint(QPainter *p, const QStyleOptionGraphicsItem *option, QWidget *)
Definition: UIScript copy.h:90
#define t_canvas
Definition: m_pd.h:205
Definition: CommonTypes.h:14
void setPdObject(void *obj)
Definition: UIScript copy.h:181
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Definition: UIScript copy.h:134
Atom & at(size_t pos)
returns reference to element at specified position
Definition: ceammc_atomlist.h:29
void btnRun()
Definition: UIScript copy.h:195
t_class * t_pd
Definition: m_pd.h:207
void initProperties()
Definition: UIScript copy.h:82
void mousePressEvent(QGraphicsSceneMouseEvent *ev)
Definition: UIScript copy.h:121
UIScript()
Definition: UIScript copy.cpp:13
void mouseReleaseEvent(QGraphicsSceneMouseEvent *ev)
Definition: UIScript copy.h:129
std::string asString() const
Definition: g_canvas.h:89