1,904 changes: 265 additions & 1,639 deletions pyKst/pykst.py

Large diffs are not rendered by default.

2,478 changes: 2,478 additions & 0 deletions pyKst/pykst_old.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/datasources/dirfilesource/dirfilesource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ bool DirFileSource::init() {
Kst::Object::UpdateType DirFileSource::internalDataSourceUpdate() {
int newNF = _dirfile->NFrames();
bool isnew = newNF != _frameCount;

_resetNeeded |= (_frameCount>newNF);

_frameCount = newNF;
Expand Down
1 change: 0 additions & 1 deletion src/kst/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ if(WIN32)
endif()

kst_add_resources(src/images/icons.qrc)
kst_add_resources(src/libkstapp/script.qrc)

kst_find_info_files(KstCMakeFiles ${kst_dir}/cmake/*)
kst_find_info_files(KstCMakeFiles ${kst_dir}/cmake/modules/*)
Expand Down
11 changes: 10 additions & 1 deletion src/libkst/datamatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "datacollection.h"
#include "debug.h"
#include "objectstore.h"
#include "matrixscriptinterface.h"


// xStart, yStart < 0 count from end
Expand Down Expand Up @@ -85,6 +86,10 @@ void DataMatrix::save(QXmlStreamWriter &xml) {
DataMatrix::~DataMatrix() {
}

ScriptInterface* DataMatrix::createScriptInterface() {
return new MatrixDataSI(this);
}


void DataMatrix::change(DataSourcePtr file, const QString &field,
int xStart, int yStart,
Expand Down Expand Up @@ -677,7 +682,11 @@ QString DataMatrix::descriptionTip() const {
}

QString DataMatrix::propertyString() const {
return tr("%1 of %2", "field %1 from file %2").arg(field()).arg(dataSource()->fileName());
if (dataSource().isPtrValid()) {
return tr("%1 of %2", "field %1 from file %2").arg(field()).arg(dataSource()->fileName());
} else {
return QString();
}
}


Expand Down
2 changes: 2 additions & 0 deletions src/libkst/datamatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class KSTCORE_EXPORT DataMatrix : public Matrix, public DataPrimitive
virtual LabelInfo yLabelInfo() const;
virtual LabelInfo titleInfo() const;

virtual ScriptInterface* createScriptInterface();

protected:
DataMatrix(ObjectStore *store);
virtual ~DataMatrix();
Expand Down
5 changes: 5 additions & 0 deletions src/libkst/datascalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "debug.h"
#include "objectstore.h"
#include "scalarscriptinterface.h"

namespace Kst {

Expand Down Expand Up @@ -57,6 +58,10 @@ const QString& DataScalar::typeString() const {
return staticTypeString;
}

ScriptInterface* DataScalar::createScriptInterface() {
return new ScalarDataSI(this);
}


/** return true if it has a valid file and field, or false otherwise */
bool DataScalar::isValid() const {
Expand Down
2 changes: 2 additions & 0 deletions src/libkst/datascalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class KSTCORE_EXPORT DataScalar : public Scalar, public DataPrimitive
virtual void reset();
void reload();

virtual ScriptInterface* createScriptInterface();

private:
/** make a copy of the DataScalar */
virtual PrimitivePtr makeDuplicate() const;
Expand Down
5 changes: 5 additions & 0 deletions src/libkst/datastring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* *
***************************************************************************/
#include "datastring.h"
#include "stringscriptinterface.h"

#include <QDebug>
#include <QTextDocument>
Expand All @@ -39,6 +40,10 @@ DataString::DataString(ObjectStore *store)
DataString::~DataString() {
}

ScriptInterface* DataString::createScriptInterface() {
return new StringDataSI(this);
}


QString DataString::_automaticDescriptiveName() const {
QString name = _field;
Expand Down
1 change: 1 addition & 0 deletions src/libkst/datastring.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class KSTCORE_EXPORT DataString : public String, public DataPrimitive

bool isValid() const;

virtual ScriptInterface* createScriptInterface();
private:
/** make a copy of the DataString */
virtual PrimitivePtr makeDuplicate() const;
Expand Down
6 changes: 6 additions & 0 deletions src/libkst/datavector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "math_kst.h"
#include "objectstore.h"
#include "updatemanager.h"
#include "vectorscriptinterface.h"

// ReqNF <=0 means read from ReqF0 to end of File
// ReqF0 < means start at EndOfFile-ReqNF.
Expand Down Expand Up @@ -102,6 +103,11 @@ bool DataVector::isValid() const {
}


ScriptInterface* DataVector::createScriptInterface() {
return new VectorDataSI(this);
}


bool DataVector::checkValidity(const DataSourcePtr& ds) const {
if (ds) {
ds->readLock();
Expand Down
2 changes: 2 additions & 0 deletions src/libkst/datavector.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class KSTCORE_EXPORT DataVector : public Vector, public DataPrimitive
/** does the vector represent time? */
virtual bool isTime() const;

virtual ScriptInterface* createScriptInterface();

protected:
DataVector(ObjectStore *store);
virtual ~DataVector();
Expand Down
6 changes: 6 additions & 0 deletions src/libkst/generatedvector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* *
***************************************************************************/
#include "generatedvector.h"
#include "vectorscriptinterface.h"

#include <QDebug>
#include <QXmlStreamWriter>
Expand All @@ -37,6 +38,11 @@ const QString& GeneratedVector::typeString() const {
}


ScriptInterface* GeneratedVector::createScriptInterface() {
return new VectorGenSI(this);
}


void GeneratedVector::save(QXmlStreamWriter &s) {
s.writeStartElement("generatedvector");
s.writeAttribute("min", QString::number(min()));
Expand Down
2 changes: 2 additions & 0 deletions src/libkst/generatedvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class KSTCORE_EXPORT GeneratedVector : public Vector {
virtual QString descriptionTip() const;
virtual QString propertyString() const;

virtual ScriptInterface* createScriptInterface();

protected:
GeneratedVector(ObjectStore *store);

Expand Down
132 changes: 132 additions & 0 deletions src/libkst/matrixscriptinterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/***************************************************************************
* *
* copyright : (C) 2014 Barth Netterfield *
* netterfield@astro.utoronto.ca *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "matrixscriptinterface.h"

#include "objectstore.h"
#include "datasourcepluginmanager.h"
#include "updatemanager.h"
#include "updateserver.h"

#include <QStringBuilder>


namespace Kst {

QString doMatrixScriptCommand(QString command,Matrix *matrix) {

QString v=ScriptInterface::doNamedObjectCommand(command, matrix);
if (!v.isEmpty()) {
return v;
}

if (command.startsWith("value(")) {
command.remove("value(").chop(1);
QStringList p = command.split(',');
return QString::number(matrix->value(p[0].toDouble(), p[1].toDouble()));
} else if (command.startsWith("length(")) {
return QString::number(matrix->sampleCount());
} else if (command.startsWith("min(")) {
return QString::number(matrix->minValue());
} else if (command.startsWith("max(")) {
return QString::number(matrix->maxValue());
} else if (command.startsWith("mean(")) {
return QString::number(matrix->meanValue());
} else if (command.startsWith("width(")) {
return QString::number(matrix->xNumSteps());
} else if (command.startsWith("height(")) {
return QString::number(matrix->yNumSteps());
} else if (command.startsWith("dX(")) {
return QString::number(matrix->xStepSize());
} else if (command.startsWith("dY(")) {
return QString::number(matrix->yStepSize());
} else if (command.startsWith("minX(")) {
return QString::number(matrix->minX());
} else if (command.startsWith("minY(")) {
return QString::number(matrix->minY());
} else if (command.startsWith("descriptionTip(")) {
return matrix->descriptionTip();
}

return QString();
}


/******************************************************/
/* Data Matrixs */
/******************************************************/
MatrixDataSI::MatrixDataSI(DataMatrixPtr it) {
matrix=it;
}

QString MatrixDataSI::doCommand(QString command) {

QString v=doMatrixScriptCommand(command, matrix);
if (!v.isEmpty()) {
return v;
}


if (command.startsWith(QLatin1String("change("))) {
command.remove("change(").remove(')');
QStringList p = command.split(',');
DataSourcePtr ds = DataSourcePluginManager::findOrLoadSource(
matrix->store(), p.at(0));

matrix->writeLock();
matrix->change(ds,
p.at(1), // field
p.at(2).toInt(), // x start
p.at(3).toInt(), // y start
p.at(4).toInt(), // num x steps
p.at(5).toInt(), // num y steps

false, false, 0,

p.at(6).toDouble(), // min x
p.at(7).toDouble(), // min y
p.at(8).toDouble(), // step x
p.at(9).toDouble() // step y
);
matrix->unlock();
return "Done";
} else if (command.startsWith("field(")) {
return matrix->field();
} else if (command.startsWith("filename(")) {
return matrix->filename();
} else if (command.startsWith("startX(")) {
return QString::number(matrix->reqXStart());
} else if (command.startsWith("startY(")) {
return QString::number(matrix->reqYStart());
}

return "No such command";
}

bool MatrixDataSI::isValid() {
return matrix.isPtrValid();
}

ScriptInterface* MatrixDataSI::newMatrix(ObjectStore *store) {
DataMatrixPtr matrix;
matrix = store->createObject<DataMatrix>();
return new MatrixDataSI(matrix);
}

QByteArray MatrixDataSI::endEditUpdate() {
matrix->registerChange();
UpdateManager::self()->doUpdates(true);
UpdateServer::self()->requestUpdateSignal();
return ("Finished editing "+matrix->Name()).toLatin1();
}

}
37 changes: 37 additions & 0 deletions src/libkst/matrixscriptinterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/***************************************************************************
* *
* copyright : (C) 2014 Barth Netterfield *
* netterfield@astro.utoronto.ca *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef MATRIXSCRIPTINTERFACE_H
#define MATRIXSCRIPTINTERFACE_H

#include <QString>

#include "scriptinterface.h"
#include "datamatrix.h"

namespace Kst {

class MatrixDataSI : public ScriptInterface
{
Q_OBJECT
DataMatrixPtr matrix;
public:
explicit MatrixDataSI(DataMatrixPtr it);
QString doCommand(QString);
bool isValid();
QByteArray endEditUpdate();

static ScriptInterface* newMatrix(ObjectStore *store);
};

}
#endif // MATRIXSCRIPTINTERFACE_H
14 changes: 13 additions & 1 deletion src/libkst/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "object.h"

class ScriptInterface;

#include "objectstore.h"

Expand All @@ -26,7 +27,7 @@ const QString Object::staticTypeString = "Object";

Object::Object() :
Shared(), KstRWLock(), NamedObject(),
_store(0L), _serial(0), _serialOfLastChange(0)
_store(0L), _serial(0), _serialOfLastChange(0), _interface(0)
{
}

Expand All @@ -47,6 +48,17 @@ const QString& Object::typeString() const {
return staticTypeString;
}

ScriptInterface* Object::createScriptInterface() {
return NULL;
}

ScriptInterface* Object::scriptInterface() {
if (!_interface) {
_interface = createScriptInterface();
}
return _interface;
}


// Returns count - 1 to account for "this" and the list pointer, therefore
// you MUST have a reference-counted pointer to call this function
Expand Down
7 changes: 7 additions & 0 deletions src/libkst/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace Kst {

class ObjectStore;
class Object;
class ScriptInterface;

typedef SharedPtr<Object> ObjectPtr;

Expand Down Expand Up @@ -77,6 +78,9 @@ class KSTCORE_EXPORT Object : public QObject, public Shared, public KstRWLock, p

virtual bool uses(ObjectPtr p) const;

virtual ScriptInterface* createScriptInterface();
ScriptInterface *scriptInterface();

protected:
Object();
virtual ~Object();
Expand All @@ -90,6 +94,9 @@ class KSTCORE_EXPORT Object : public QObject, public Shared, public KstRWLock, p
qint64 _serial;
qint64 _serialOfLastChange;
bool _used;
private:
ScriptInterface *_interface;

signals:
void dirty();
};
Expand Down
5 changes: 5 additions & 0 deletions src/libkst/scalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
***************************************************************************/

#include "scalar.h"
#include "scalarscriptinterface.h"

#include <QDebug>
#include <QTextDocument>
Expand Down Expand Up @@ -52,6 +53,10 @@ const QString& Scalar::typeString() const {
return staticTypeString;
}

ScriptInterface* Scalar::createScriptInterface() {
return new ScalarGenSI(this);
}


void Scalar::internalUpdate() {
// do nothing
Expand Down
1 change: 1 addition & 0 deletions src/libkst/scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class KSTCORE_EXPORT Scalar : public Primitive

virtual ObjectList<Primitive> outputPrimitives() const { return ObjectList<Primitive>(); }
virtual PrimitiveMap metas() const { return PrimitiveMap(); }
virtual ScriptInterface* createScriptInterface();

public slots:
double value() const;
Expand Down
170 changes: 170 additions & 0 deletions src/libkst/scalarscriptinterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/***************************************************************************
* *
* copyright : (C) 2014 Barth Netterfield *
* netterfield@astro.utoronto.ca *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "scalarscriptinterface.h"

#include "objectstore.h"
#include "datasourcepluginmanager.h"
#include "updatemanager.h"
#include "updateserver.h"

#include <QStringBuilder>


namespace Kst {

/******************************************************/
/* Generated Scalars */
/******************************************************/
ScalarGenSI::ScalarGenSI(ScalarPtr it) {
scalar=it;
}

QString ScalarGenSI::doCommand(QString x) {

QString v=doNamedObjectCommand(x, scalar);
if (!v.isEmpty()) {
return v;
}

if (x.startsWith(QLatin1String("setValue("))) {
scalar->writeLock();
scalar->setValue(x.remove("setValue(").remove(')').toDouble());
scalar->unlock();
return "Done";
} else if (x.startsWith(QLatin1String("value()"))) {
return QString::number(scalar->value());
}
return "No such command";
}

bool ScalarGenSI::isValid() {
return scalar.isPtrValid();
}

ScriptInterface* ScalarGenSI::newScalar(ObjectStore *store) {
ScalarPtr scalar;
scalar = store->createObject<Scalar>();
scalar->setOrphan(true);
scalar->setEditable(true);
return new ScalarGenSI(scalar);
}

QByteArray ScalarGenSI::endEditUpdate() {
UpdateManager::self()->doUpdates(true);
UpdateServer::self()->requestUpdateSignal();
return ("Finished editing "+scalar->Name()).toLatin1();
}

/******************************************************/
/* Data Scalars */
/******************************************************/
ScalarDataSI::ScalarDataSI(DataScalarPtr it) {
scalar=it;
}

QString ScalarDataSI::doCommand(QString x) {

QString v=doNamedObjectCommand(x, scalar);
if (!v.isEmpty()) {
return v;
}

if (x.startsWith(QLatin1String("change("))) {
x.remove("change(").remove(')');
QStringList p = x.split(',');
DataSourcePtr ds = DataSourcePluginManager::findOrLoadSource(
scalar->store(), p.at(0));
scalar->writeLock();
scalar->change(ds,p.at(1));
scalar->unlock();
return "Done";
} else if (x.startsWith(QLatin1String("file()"))) {
return scalar->filename();
} else if (x.startsWith(QLatin1String("field()"))) {
return scalar->field();
} else if (x.startsWith(QLatin1String("value()"))) {
return QString::number(scalar->value());
}
return "No such command";
}

bool ScalarDataSI::isValid() {
return scalar.isPtrValid();
}

ScriptInterface* ScalarDataSI::newScalar(ObjectStore *store) {
DataScalarPtr scalar;
scalar = store->createObject<DataScalar>();
return new ScalarDataSI(scalar);
}

QByteArray ScalarDataSI::endEditUpdate() {
scalar->registerChange();
UpdateManager::self()->doUpdates(true);
UpdateServer::self()->requestUpdateSignal();
return ("Finished editing "+scalar->Name()).toLatin1();
}

/******************************************************/
/* Vector Scalars */
/******************************************************/
ScalarVectorSI::ScalarVectorSI(VScalarPtr it) {
scalar=it;
}

QString ScalarVectorSI::doCommand(QString x) {

QString v=doNamedObjectCommand(x, scalar);
if (!v.isEmpty()) {
return v;
}

if (x.startsWith(QLatin1String("change("))) {
x.remove("change(").remove(')');
QStringList p = x.split(',');
DataSourcePtr ds = DataSourcePluginManager::findOrLoadSource(
scalar->store(), p.at(0));
scalar->writeLock();
scalar->change(ds,p.at(1), p.at(2).toInt());
scalar->unlock();
return "Done";
} else if (x.startsWith(QLatin1String("value()"))) {
return QString::number(scalar->value());
} else if (x.startsWith(QLatin1String("file()"))) {
return scalar->filename();
} else if (x.startsWith(QLatin1String("field()"))) {
return scalar->field();
} else if (x.startsWith(QLatin1String("frame()"))) {
return QString::number(scalar->F0());
}
return "No such command";
}

bool ScalarVectorSI::isValid() {
return scalar.isPtrValid();
}

ScriptInterface* ScalarVectorSI::newScalar(ObjectStore *store) {
VScalarPtr scalar;
scalar = store->createObject<VScalar>();
return new ScalarVectorSI(scalar);
}

QByteArray ScalarVectorSI::endEditUpdate() {
scalar->registerChange();
UpdateManager::self()->doUpdates(true);
UpdateServer::self()->requestUpdateSignal();
return ("Finished editing "+scalar->Name()).toLatin1();
}

}
69 changes: 69 additions & 0 deletions src/libkst/scalarscriptinterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/***************************************************************************
* *
* copyright : (C) 2014 Barth Netterfield *
* netterfield@astro.utoronto.ca *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef SCALARSCRIPTINTERFACE_H
#define SCALARSCRIPTINTERFACE_H

#include <QString>

#include "scriptinterface.h"
#include "datascalar.h"
#include "vscalar.h"

namespace Kst {

class ScalarGenSI : public ScriptInterface
{
Q_OBJECT
ScalarPtr scalar;
public:
explicit ScalarGenSI(ScalarPtr it);
QString doCommand(QString);
bool isValid();
QByteArray endEditUpdate();

static ScriptInterface* newScalar(ObjectStore *store);

};


class ScalarDataSI : public ScriptInterface
{
Q_OBJECT
DataScalarPtr scalar;
public:
explicit ScalarDataSI(DataScalarPtr it);
QString doCommand(QString);
bool isValid();
QByteArray endEditUpdate();

static ScriptInterface* newScalar(ObjectStore *store);

};


class ScalarVectorSI : public ScriptInterface
{
Q_OBJECT
VScalarPtr scalar;
public:
explicit ScalarVectorSI(VScalarPtr it);
QString doCommand(QString);
bool isValid();
QByteArray endEditUpdate();

static ScriptInterface* newScalar(ObjectStore *store);

};

}
#endif // SCALARSCRIPTINTERFACE_H
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@

#include "scriptinterface.h"

#include "namedobject.h"

namespace Kst {

QString ScriptInterface::doNamedObjectCommand(QString command, NamedObject *n) {
if (command.startsWith("setName(")) {
command.remove("setName(").chop(1);
n->setDescriptiveName(command);
return QString("Done");
} else if (command.startsWith("name(")) {
return n->Name();
}

return QString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,19 @@ typedef QList<QByteArray> QByteArrayList;

namespace Kst {

class NamedObject;

/** A script interface represents an object exposed through the scripting interface.
* (ex., dialog, primitive, etc.)
*/
class ScriptInterface : public QObject
{
Q_OBJECT
public:
virtual QByteArrayList commands()=0;
virtual QString doCommand(QString)=0;
virtual bool isValid()=0;
virtual QByteArray getHandle()=0;
virtual void endEditUpdate()=0;
};

/** Enables recursive if statements in scripting. The syntax for if statements is 'if(...)' to begin a statement and 'fi()' to end.*/
struct IfSI {
IfSI* parent;
bool on;
int recurse;
IfSI(IfSI*p,bool isTrue) : parent(p),on(isTrue),recurse(0) {}
};

/** Enables variables in scripting. Variables begin with the prefix '$' */
struct VarSI {
QByteArray handle;
QByteArray val;
VarSI(QByteArray v,QByteArray e) : handle(v), val(e) {}
};

/** Enables macros (lists of commands to be executed) in scripting. Macro names begin with the prefix '#' */
struct MacroSI {
MacroSI* parent;
QByteArray handle;
QByteArrayList args;
QByteArrayList commands;
MacroSI(MacroSI*p,QByteArray h,QByteArrayList v,QByteArrayList c) : parent(p), handle(h), args(v), commands(c) {}
virtual QByteArray endEditUpdate()=0;
static QString doNamedObjectCommand(QString command, NamedObject *n);
};

}
Expand Down
7 changes: 7 additions & 0 deletions src/libkst/string_kst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
***************************************************************************/

#include "string_kst.h"
#include "stringscriptinterface.h"

#include <QTextDocument>
#include <QXmlStreamWriter>
Expand All @@ -34,6 +35,12 @@ String::String(ObjectStore *store)

}


ScriptInterface* String::createScriptInterface() {
return new StringGenSI(this);
}


void String::_initializeShortName() {
_shortName = 'T'+QString::number(_tnum);
if (_tnum>max_tnum)
Expand Down
4 changes: 4 additions & 0 deletions src/libkst/string_kst.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class QXmlStreamWriter;

namespace Kst {

class ScriptInterface;

class KSTCORE_EXPORT String : public Primitive
{
Q_OBJECT
Expand All @@ -38,6 +40,8 @@ class KSTCORE_EXPORT String : public Primitive
virtual QString sizeString() const;
virtual QString propertyString() const;

virtual ScriptInterface* createScriptInterface();

protected:
String(ObjectStore *store);

Expand Down
109 changes: 109 additions & 0 deletions src/libkst/stringscriptinterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/***************************************************************************
* *
* copyright : (C) 2014 Barth Netterfield *
* netterfield@astro.utoronto.ca *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "stringscriptinterface.h"

#include "objectstore.h"
#include "datasourcepluginmanager.h"
#include "updatemanager.h"
#include "updateserver.h"

#include <QStringBuilder>

namespace Kst {

StringGenSI::StringGenSI(StringPtr it) {
str=it;
}

QString StringGenSI::doCommand(QString x) {

QString v=doNamedObjectCommand(x, str);
if (!v.isEmpty()) {
return v;
}

if (x.startsWith(QLatin1String("setValue("))) {
str->writeLock();
str->setValue(x.remove("setValue(").remove(')'));
str->unlock();
return "Done";
} else if (x.startsWith(QLatin1String("value()"))) {
return str->value();
}
return "No such command";
}

bool StringGenSI::isValid() {
return str.isPtrValid();
}

ScriptInterface* StringGenSI::newString(ObjectStore *store) {
StringPtr string;
string = store->createObject<String>();
string->setOrphan(true);
string->setEditable(true);
return new StringGenSI(string);
}

QByteArray StringGenSI::endEditUpdate() {
UpdateManager::self()->doUpdates(true);
UpdateServer::self()->requestUpdateSignal();
return ("Finished editing "+str->Name()).toLatin1();
}

/////////////////////////////////////////////////////////////////////////////////////

StringDataSI::StringDataSI(DataStringPtr it) {
str=it;
}

QString StringDataSI::doCommand(QString x) {

QString v=doNamedObjectCommand(x, str);
if (!v.isEmpty()) {
return v;
}

if(x.startsWith(QLatin1String("change("))) {
x.remove("change(").remove(')');
QStringList p = x.split(',');
DataSourcePtr ds = DataSourcePluginManager::findOrLoadSource(
str->store(), p.at(0));
str->writeLock();
str->change(ds,p.at(1));
str->unlock();
return "Done";
} else if (x.startsWith(QLatin1String("value()"))) {
return str->value();
}
return "No such command";
}

bool StringDataSI::isValid() {
return str.isPtrValid();
}

ScriptInterface* StringDataSI::newString(ObjectStore *store) {
DataStringPtr string;
string = store->createObject<DataString>();

return new StringDataSI(string);
}

QByteArray StringDataSI::endEditUpdate() {
UpdateManager::self()->doUpdates(true);
UpdateServer::self()->requestUpdateSignal();
return ("Finished editing "+str->Name()).toLatin1();
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/***************************************************************************
* *
* copyright : (C) 2011 Joshua Netterfield *
* joshua.netterfield@gmail.com *
* copyright : (C) 2014 Barth Netterfield *
* netterfield@astro.utoronto.ca *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
Expand All @@ -13,16 +13,10 @@
#ifndef STRINGSCRIPTINTERFACE_H
#define STRINGSCRIPTINTERFACE_H

#include <QByteArray>
#include <QString>
#include <QList>
#include <QObject>

#include "scriptinterface.h"
#include "string_kst.h"
#include "updatemanager.h"
#include "updateserver.h"
typedef QList<QByteArray> QByteArrayList;
#include "datastring.h"

namespace Kst {

Expand All @@ -32,11 +26,26 @@ class StringGenSI : public ScriptInterface
StringPtr str;
public:
explicit StringGenSI(StringPtr it);
QByteArrayList commands();
QString doCommand(QString);
bool isValid();
QByteArray getHandle();
void endEditUpdate() { UpdateManager::self()->doUpdates(true); UpdateServer::self()->requestUpdateSignal();}
QByteArray endEditUpdate();

static ScriptInterface* newString(ObjectStore *store);

};

class StringDataSI : public ScriptInterface
{
Q_OBJECT
DataStringPtr str;
public:
explicit StringDataSI(DataStringPtr it);
QString doCommand(QString);
bool isValid();
QByteArray endEditUpdate();

static ScriptInterface* newString(ObjectStore *store);

};

}
Expand Down
165 changes: 165 additions & 0 deletions src/libkst/vectorscriptinterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/***************************************************************************
* *
* copyright : (C) 2014 Barth Netterfield *
* netterfield@astro.utoronto.ca *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "vectorscriptinterface.h"

#include "objectstore.h"
#include "datasourcepluginmanager.h"
#include "updatemanager.h"
#include "updateserver.h"

#include <QStringBuilder>


namespace Kst {

QString doVectorScriptCommand(QString command,Vector *vector) {

QString v=ScriptInterface::doNamedObjectCommand(command, vector);
if (!v.isEmpty()) {
return v;
}

if (command.startsWith("value(")) {
command.remove("value(").chop(1);
return QString::number(vector->value(command.toInt()));
} else if (command.startsWith("length(")) {
return QString::number(vector->length());
} else if (command.startsWith("min(")) {
return QString::number(vector->min());
} else if (command.startsWith("max(")) {
return QString::number(vector->max());
} else if (command.startsWith("mean(")) {
return QString::number(vector->mean());
} else if (command.startsWith("descriptionTip(")) {
return vector->descriptionTip();
}

return QString();
}


/******************************************************/
/* Data Vectors */
/******************************************************/
VectorDataSI::VectorDataSI(DataVectorPtr it) {
vector=it;
}

QString VectorDataSI::doCommand(QString command) {

QString v=doVectorScriptCommand(command, vector);
if (!v.isEmpty()) {
return v;
}

if (command.startsWith(QLatin1String("change("))) {
command.remove("change(").remove(')');
QStringList p = command.split(',');
DataSourcePtr ds = DataSourcePluginManager::findOrLoadSource(
vector->store(), p.at(0));
vector->writeLock();
vector->change(ds,
p.at(1), // field
p.at(2).toInt(), // f0
p.at(3).toInt(), // n
p.at(4).toInt(), // skip
p.at(4).toInt() > 0, // do skip
p.at(5) == "True" // do average
);
vector->unlock();
return "Done";
} else if (command.startsWith("field(")) {
return vector->field();
} else if (command.startsWith("filename(")) {
return vector->filename();
} else if (command.startsWith("start(")) {
return QString::number(vector->startFrame());
} else if (command.startsWith("NFrames(")) {
return QString::number(vector->numFrames());
} else if (command.startsWith("skip(")) {
return QString::number(vector->skip());
} else if (command.startsWith("boxcarFirst(")) {
return vector->doAve()?"True":"False";
}

return "No such command";
}

bool VectorDataSI::isValid() {
return vector.isPtrValid();
}

ScriptInterface* VectorDataSI::newVector(ObjectStore *store) {
DataVectorPtr vector;
vector = store->createObject<DataVector>();
return new VectorDataSI(vector);
}

QByteArray VectorDataSI::endEditUpdate() {
vector->registerChange();
UpdateManager::self()->doUpdates(true);
UpdateServer::self()->requestUpdateSignal();
return ("Finished editing "+vector->Name()).toLatin1();
}

/******************************************************/
/* Generated Vectors */
/******************************************************/
VectorGenSI::VectorGenSI(GeneratedVectorPtr it) {
vector=it;
}

QString VectorGenSI::doCommand(QString command) {

QString v=doVectorScriptCommand(command, vector);
if (!v.isEmpty()) {
return v;
}

if (command.startsWith(QLatin1String("change("))) {
command.remove("change(").remove(')');
QStringList p = command.split(',');

vector->writeLock();

vector->changeRange(
p.at(0).toDouble(), // start
p.at(1).toDouble(), // end
p.at(2).toInt() // number of points
);
vector->unlock();
return "Done";
}

return "No such command";
}

bool VectorGenSI::isValid() {
return vector.isPtrValid();
}

ScriptInterface* VectorGenSI::newVector(ObjectStore *store) {
GeneratedVectorPtr vector;
vector = store->createObject<GeneratedVector>();
return new VectorGenSI(vector);
}

QByteArray VectorGenSI::endEditUpdate() {
vector->registerChange();
UpdateManager::self()->doUpdates(true);
UpdateServer::self()->requestUpdateSignal();
return ("Finished editing "+vector->Name()).toLatin1();
}


}
51 changes: 51 additions & 0 deletions src/libkst/vectorscriptinterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/***************************************************************************
* *
* copyright : (C) 2014 Barth Netterfield *
* netterfield@astro.utoronto.ca *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef VECTORSCRIPTINTERFACE_H
#define VECTORSCRIPTINTERFACE_H

#include <QString>

#include "scriptinterface.h"
#include "datavector.h"
#include "generatedvector.h"

namespace Kst {

class VectorDataSI : public ScriptInterface
{
Q_OBJECT
DataVectorPtr vector;
public:
explicit VectorDataSI(DataVectorPtr it);
QString doCommand(QString);
bool isValid();
QByteArray endEditUpdate();

static ScriptInterface* newVector(ObjectStore *store);
};

class VectorGenSI : public ScriptInterface
{
Q_OBJECT
GeneratedVectorPtr vector;
public:
explicit VectorGenSI(GeneratedVectorPtr it);
QString doCommand(QString);
bool isValid();
QByteArray endEditUpdate();

static ScriptInterface* newVector(ObjectStore *store);
};

}
#endif // VECTORSCRIPTINTERFACE_H
5 changes: 5 additions & 0 deletions src/libkst/vscalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "debug.h"
#include "objectstore.h"
#include "updatemanager.h"
#include "vscalar.h"
#include "scalarscriptinterface.h"

namespace Kst {

Expand Down Expand Up @@ -56,6 +58,9 @@ const QString& VScalar::typeString() const {
return staticTypeString;
}

ScriptInterface* VScalar::createScriptInterface() {
return new ScalarVectorSI(this);
}

void VScalar::change(DataSourcePtr in_file, const QString &in_field, int in_f0) {
Q_ASSERT(myLockStatus() == KstRWLock::WRITELOCKED);
Expand Down
2 changes: 2 additions & 0 deletions src/libkst/vscalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class KSTCORE_EXPORT VScalar : public Scalar {

virtual QString propertyString() const;

virtual ScriptInterface* createScriptInterface();

private:
/** file to read for rvectors */
DataSourcePtr _file;
Expand Down
4 changes: 2 additions & 2 deletions src/libkstapp/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "datasource.h"
#include "dialogdefaults.h"
#include "datasourcepluginmanager.h"
#include "dialogscriptinterface.h"
//#include "dialogscriptinterface.h"
#include "settings.h"

#include <QIcon>
Expand Down Expand Up @@ -55,7 +55,7 @@ Application::Application(int &argc, char **argv)
DialogLauncher::replaceSelf(new DialogLauncherGui);

//Also give us dialog-script scripting functionality
DialogLauncherSI::self = new DialogLauncherSI;
//DialogLauncherSI::self = new DialogLauncherSI;

//_mainWindow->show();
//_mainWindow->hide();
Expand Down
6 changes: 6 additions & 0 deletions src/libkstapp/arrowitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "math_kst.h"

#include "arrowscriptinterface.h"

#include <debug.h>

#include <QDebug>
Expand Down Expand Up @@ -47,6 +49,10 @@ ArrowItem::ArrowItem(View *parent)
ArrowItem::~ArrowItem() {
}

ScriptInterface* ArrowItem::createScriptInterface() {
return new ArrowSI(this);
}


void ArrowItem::paint(QPainter *painter) {
painter->drawLine(line());
Expand Down
4 changes: 4 additions & 0 deletions src/libkstapp/arrowitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

namespace Kst {

class ScriptInterface;

class ArrowItem : public LineItem
{
Q_OBJECT
Expand Down Expand Up @@ -52,6 +54,8 @@ class ArrowItem : public LineItem
virtual bool customDimensionsTab() {return true;}
void applyDialogDefaultsHeads();

virtual ScriptInterface *createScriptInterface();

public Q_SLOTS:
virtual void edit();

Expand Down
15 changes: 6 additions & 9 deletions src/libkstapp/arrowscriptinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ ArrowSI::ArrowSI(ArrowItem *it) : _dim(new DimensionTabSI), _fill(new FillTabSI)
_arrow->item=it;
}

QByteArrayList ArrowSI::commands() {
return _dim->commands()<<_fill->commands()<<_stroke->commands()<<_arrow->commands();
}

QString ArrowSI::doCommand(QString x) {
QString v =_dim->doCommand(x);

QString v=doNamedObjectCommand(x, _dim->item);

if(v.isEmpty()) {
v =_dim->doCommand(x);
}
if(v.isEmpty()) {
v=_fill->doCommand(x);
}
Expand All @@ -72,10 +73,6 @@ bool ArrowSI::isValid() {
return _dim->item;
}

QByteArray ArrowSI::getHandle() {
return ("Finished editing "%_dim->item->Name()).toLatin1();
}

ScriptInterface* ArrowSI::newArrow() {
ArrowItem* bi=new ArrowItem(kstApp->mainWindow()->tabWidget()->currentView());
kstApp->mainWindow()->tabWidget()->currentView()->scene()->addItem(bi);
Expand Down
4 changes: 1 addition & 3 deletions src/libkstapp/arrowscriptinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ class ArrowSI : public ScriptInterface
Q_OBJECT
public:
explicit ArrowSI(ArrowItem* it);
QByteArrayList commands();
QString doCommand(QString);
bool isValid();
QByteArray getHandle();
void endEditUpdate() {if (_dim->item) _dim->item->update();}
QByteArray endEditUpdate() {if (_dim->item) _dim->item->update();return ("Finished editing "+_dim->item->Name()).toLatin1();}

static ScriptInterface* newArrow();

Expand Down
895 changes: 0 additions & 895 deletions src/libkstapp/dialogscriptinterface.cpp

This file was deleted.

169 changes: 0 additions & 169 deletions src/libkstapp/dialogscriptinterface.h

This file was deleted.

713 changes: 0 additions & 713 deletions src/libkstapp/kstScript.txt

This file was deleted.

7 changes: 7 additions & 0 deletions src/libkstapp/labelitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "plotitem.h"
#include "cartesianrenderitem.h"

#include "labelscriptinterface.h"

#include <QDebug>
#include <QInputDialog>
#include <QGraphicsItem>
Expand All @@ -42,6 +44,11 @@ LabelItem::LabelItem(View *parent, const QString& txt)
applyDefaults();
}

ScriptInterface* LabelItem::createScriptInterface() {
return new LabelSI(this);
}


bool LabelItem::inputsChanged(qint64 serial) {
bool no_change = true;

Expand Down
3 changes: 3 additions & 0 deletions src/libkstapp/labelitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace Label {

namespace Kst {

class ScriptInterface;

class LabelItem : public ViewItem {
Q_OBJECT
public:
Expand Down Expand Up @@ -71,6 +73,7 @@ class LabelItem : public ViewItem {

bool inputsChanged(qint64 serial);

virtual ScriptInterface *createScriptInterface();
public Q_SLOTS:
virtual void edit();
void setDirty() { _dirty = true; }
Expand Down
29 changes: 13 additions & 16 deletions src/libkstapp/labelscriptinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,26 @@ LabelSI::LabelSI(LabelItem *it) : layout(new LayoutTabSI), dim(new DimensionTabS
lab->item=it;
}

QByteArrayList LabelSI::commands() {
return layout->commands()<<dim->commands()<<lab->commands();
}

QString LabelSI::doCommand(QString x) {
QString v=layout->doCommand(x);
if(v.isEmpty()) {
v=dim->doCommand(x);
}
if(v.isEmpty()) {
v=lab->doCommand(x);
}
return v.isEmpty()?"No command":v;

QString v=doNamedObjectCommand(x, dim->item);

if (v.isEmpty()) {
v=layout->doCommand(x);
}
if (v.isEmpty()) {
v=dim->doCommand(x);
}
if (v.isEmpty()) {
v=lab->doCommand(x);
}
return v.isEmpty()?"No command":v;
}

bool LabelSI::isValid() {
return dim->item;
}

QByteArray LabelSI::getHandle() {
return ("Finished editing "%dim->item->Name()).toLatin1();
}

ScriptInterface* LabelSI::newLabel() {
LabelItem* bi=new LabelItem(kstApp->mainWindow()->tabWidget()->currentView(),"");
kstApp->mainWindow()->tabWidget()->currentView()->scene()->addItem(bi);
Expand Down
4 changes: 1 addition & 3 deletions src/libkstapp/labelscriptinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ class LabelSI : public ScriptInterface
Q_OBJECT
public:
explicit LabelSI(LabelItem* it);
QByteArrayList commands();
QString doCommand(QString);
bool isValid();
QByteArray getHandle();
void endEditUpdate() {if (dim->item) dim->item->update();}
QByteArray endEditUpdate() {if (dim->item) dim->item->update();return ("Finished editing "+dim->item->Name()).toLatin1();}
static ScriptInterface* newLabel();

private:
Expand Down
7 changes: 6 additions & 1 deletion src/libkstapp/plotitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#include "applicationsettings.h"
#include "updatemanager.h"

#include "plotscriptinterface.h"
#include "math_kst.h"

#include "dialogdefaults.h"
Expand Down Expand Up @@ -153,6 +153,11 @@ PlotItem::PlotItem(View *parent)
applyDialogDefaultsLockPosToData();
}

ScriptInterface* PlotItem::createScriptInterface() {
return new PlotSI(this);
}


void PlotItem::applyDefaults() {
QFont font;

Expand Down
3 changes: 3 additions & 0 deletions src/libkstapp/plotitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace Kst {
class PlotItem;
class PlotAxis;
class SharedAxisBoxItem;
class ScriptInterface;

struct ZoomState {
QPointer<PlotItem> item;
Expand Down Expand Up @@ -280,6 +281,8 @@ class PlotItem : public ViewItem, public PlotItemInterface

bool maskedByMaximization() {return (view()->childMaximized() && !_plotMaximized);}

virtual ScriptInterface *createScriptInterface();

protected:
virtual QString _automaticDescriptiveName() const;
virtual void _initializeShortName();
Expand Down
15 changes: 5 additions & 10 deletions src/libkstapp/plotscriptinterface.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* *
* copyright : (C) 2011 Barth Netterfield *
* copyright : (C) 2012 Barth Netterfield *
* netterfield@astro.utoronto.ca *
* *
* This program is free software; you can redistribute it and/or modify *
Expand Down Expand Up @@ -64,10 +64,6 @@ ScriptInterface* PlotSI::newPlot() {
}


QByteArrayList PlotSI::commands() {
return _layout->commands()<<_dim->commands()<<_stroke->commands()<<_fill->commands();
}

QString PlotSI::doCommand(QString x) {
QString command = x.left(x.indexOf('('));

Expand All @@ -77,7 +73,10 @@ QString PlotSI::doCommand(QString x) {
return CALL_MEMBER_FN(*this,fn)(x);
}

QString v=_layout->doCommand(x);
QString v=doNamedObjectCommand(x, _dim->item);
if(v.isEmpty()) {
v = _layout->doCommand(x);
}
if(v.isEmpty()) {
v=_dim->doCommand(x);
}
Expand All @@ -94,10 +93,6 @@ bool PlotSI::isValid() {
return _dim->item;
}

QByteArray PlotSI::getHandle() {
return ("Finished editing " % _dim->item->Name()).toLatin1();
}

QStringList PlotSI::getArgs(const QString &command) {
int i0 = command.indexOf('(')+1;
int i1 = command.lastIndexOf(')');
Expand Down
4 changes: 1 addition & 3 deletions src/libkstapp/plotscriptinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ class PlotSI : public ScriptInterface
Q_OBJECT
public:
explicit PlotSI(PlotItem* it);
QByteArrayList commands();
QString doCommand(QString);
bool isValid();
QByteArray getHandle();
void endEditUpdate() {if (_item) _item->update();}
QByteArray endEditUpdate() {if (_item) _item->update();return ("Finished editing "+_item->Name()).toLatin1();}

static ScriptInterface* newPlot();

Expand Down
11 changes: 1 addition & 10 deletions src/libkstapp/pluginscriptinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,11 @@ PluginSI::PluginSI(BasicPluginPtr plugin, ObjectStore *store) {
}
}

QByteArrayList PluginSI::commands() {

QByteArrayList ba;
ba<< "setInputVector()" << "setInputScalar()" << "setInputMatrix()" <<
"inputVector()" << "inputScalar()" << "inputMatrix()";

return ba;
}

bool PluginSI::isValid() {
return _plugin;
}

QByteArray PluginSI::getHandle() {
QByteArray PluginSI::endEditUpdate() {
if (_plugin) {
return ("Finished editing "%_plugin->Name()).toLatin1();
} else {
Expand Down
4 changes: 1 addition & 3 deletions src/libkstapp/pluginscriptinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ class PluginSI : public ScriptInterface
Q_OBJECT
public:
PluginSI(BasicPluginPtr plugin, ObjectStore *store);
QByteArrayList commands();
QString doCommand(QString);
bool isValid();
QByteArray getHandle();
void endEditUpdate() {}
QByteArray endEditUpdate();
private:
BasicPluginPtr _plugin;
ObjectStore *_store;
Expand Down
5 changes: 0 additions & 5 deletions src/libkstapp/script.qrc

This file was deleted.

1,087 changes: 362 additions & 725 deletions src/libkstapp/scriptserver.cpp

Large diffs are not rendered by default.

190 changes: 85 additions & 105 deletions src/libkstapp/scriptserver.h

Large diffs are not rendered by default.

55 changes: 0 additions & 55 deletions src/libkstapp/stringscriptinterface.cpp

This file was deleted.

16 changes: 15 additions & 1 deletion src/libkstapp/viewitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "formatgridhelper.h"
#include "dialogdefaults.h"
#include "cartesianrenderitem.h"
#include "viewitemscriptinterface.h"

#include "layoutboxitem.h"

Expand Down Expand Up @@ -82,7 +83,8 @@ ViewItem::ViewItem(View *parentView) :
_allowedGrips(TopLeftGrip | TopRightGrip | BottomRightGrip | BottomLeftGrip |
TopMidGrip | RightMidGrip | BottomMidGrip | LeftMidGrip),
_lockPosToData(false),
_editDialog(0)
_editDialog(0),
_interface(0)
{
_initializeShortName();
setZValue(DRAWING_ZORDER);
Expand Down Expand Up @@ -2361,6 +2363,17 @@ QString ViewItem::descriptionTip() const {
return typeName();
}

ScriptInterface* ViewItem::createScriptInterface() {
return new ViewItemSI(this);
}

ScriptInterface* ViewItem::scriptInterface() {
if (!_interface) {
_interface = createScriptInterface();
}
return _interface;
}

#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, ViewItem *viewItem) {
dbg.nospace() << viewItem->typeName();
Expand All @@ -2380,6 +2393,7 @@ ViewItemCommand::~ViewItemCommand() {
}



CreateCommand::CreateCommand(const QString &text, QUndoCommand *parent)
: ViewCommand(text, false, parent) {
}
Expand Down
5 changes: 5 additions & 0 deletions src/libkstapp/viewitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class DialogPage;
class ViewGridLayout;
class ViewItem;
class ViewItemDialog;
class ScriptInterface;

typedef QList<ViewItem *> ViewItemList;

Expand Down Expand Up @@ -254,6 +255,9 @@ class ViewItem : public QObject, public NamedObject, public QGraphicsRectItem
void storePen(const QPen &pen) {_storedPen = pen; setPen(pen);}
QPen storedPen() const { return _storedPen;}

virtual ScriptInterface *createScriptInterface();

ScriptInterface *scriptInterface();
Q_SIGNALS:
void geometryChanged();
void creationComplete();
Expand Down Expand Up @@ -403,6 +407,7 @@ class ViewItem : public QObject, public NamedObject, public QGraphicsRectItem

ViewItemDialog *_editDialog;
QPen _storedPen;
ScriptInterface *_interface;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(ViewItem::GripModes)
Expand Down
77 changes: 24 additions & 53 deletions src/libkstapp/viewitemscriptinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@

namespace Kst {

QByteArrayList LayoutTabSI::commands() {
QByteArrayList ba;
ba<<"setLayoutHorizontalMargin("<<"getLayoutHorizontalMargin()"<<"setLayoutVerticalMargin("<<
"getLayoutVerticalMargin()"<<"setLayoutHorizontalSpacing("<<"getLayoutHorizontalSpacing()"<<
"setLayoutVerticalSpacing("<<"getLayoutVerticalSpacing()";
return ba;
}
QString LayoutTabSI::doCommand(QString x) {
if(x.startsWith("getLayout")) {
x.remove(0,9);
Expand Down Expand Up @@ -74,11 +67,6 @@ QString LayoutTabSI::doCommand(QString x) {
return "";
}

QByteArrayList FillTabSI::commands() {
QByteArrayList ba;
ba<<"setFillColor("<<"setIndexOfFillStyle(";
return ba;
}
QString FillTabSI::doCommand(QString x) {
if(!x.startsWith("setFillColor")&&!x.startsWith("setIndexOfFillStyle(")) {
return "";
Expand All @@ -99,12 +87,6 @@ QString FillTabSI::doCommand(QString x) {
return "Done";
}

QByteArrayList StrokeTabSI::commands() {
QByteArrayList ba;
ba<<"setIndexOfStrokeStyle("<<"setIndexOfStrokeBrushStyle("<<"setIndexOfStrokeJoinStyle("<<"setIndexOfStrokeCapStyle("<<
"setStrokeWidth("<<"setStrokeBrushColor(";
return ba;
}
QString StrokeTabSI::doCommand(QString x) {
if(!x.startsWith("setIndexOfStrokeStyle")&&!x.startsWith("setIndexOfStrokeBrushStyle(")&&!x.startsWith("setIndexOfStrokeJoinStyle")&&
!x.startsWith("setIndexOfStrokeCapStyle")&&!x.startsWith("setStrokeWidth")&&!x.startsWith("setStrokeBrushColor")) {
Expand Down Expand Up @@ -165,14 +147,6 @@ QString StrokeTabSI::doCommand(QString x) {
return "Done";
}

QByteArrayList DimensionTabSI::commands() {
QByteArrayList ba;
ba<<"setRotation("<<"getRotation()"<<"setGeoX("<<"getGeoX()"<<"setGeoY("<<"getGeoY()"<<
"setPosX("<<"getPosX()"<<"setPosY("<<"getPosY()"<<"checkFixAspectRatio()"<<
"uncheckFixAspectRatio()"<<"fixAspectRatioIsChecked()";
return ba;
}

QString DimensionTabSI::doCommand(QString x) {

QString command = x.left(x.indexOf('('));
Expand Down Expand Up @@ -244,41 +218,38 @@ ViewItemSI::ViewItemSI(ViewItem *it) : layout(new LayoutTabSI), dim(new Dimensio
stroke->item=it;
}

QByteArrayList ViewItemSI::commands() {
return layout->commands()<<dim->commands()<<fill->commands()<<stroke->commands()<<(qobject_cast<LineEditItem*>(layout->vi)||qobject_cast<ButtonItem*>(layout->vi)?"setText(":"");
}

QString ViewItemSI::doCommand(QString x) {
QString v=layout->doCommand(x);
if(v.isEmpty()) {
v=dim->doCommand(x);
}
if(v.isEmpty()) {
v=fill->doCommand(x);
}
if(v.isEmpty()) {
v=stroke->doCommand(x);
}
if(v.isEmpty()&&x.startsWith("setText(")) {
if(qobject_cast<ButtonItem*>(layout->vi)) {
qobject_cast<ButtonItem*>(layout->vi)->setText(x.remove("setText(").remove(')'));
v="Done";
} else if(qobject_cast<LineEditItem*>(layout->vi)) {
qobject_cast<LineEditItem*>(layout->vi)->setText(x.remove("setText(").remove(')'));
v="Done";
}

QString v=doNamedObjectCommand(x, dim->item);

if (v.isEmpty()) {
v=layout->doCommand(x);
}
if (v.isEmpty()) {
v=dim->doCommand(x);
}
if (v.isEmpty()) {
v=fill->doCommand(x);
}
if (v.isEmpty()) {
v=stroke->doCommand(x);
}
if (v.isEmpty()&&x.startsWith("setText(")) {
if(qobject_cast<ButtonItem*>(layout->vi)) {
qobject_cast<ButtonItem*>(layout->vi)->setText(x.remove("setText(").remove(')'));
v="Done";
} else if(qobject_cast<LineEditItem*>(layout->vi)) {
qobject_cast<LineEditItem*>(layout->vi)->setText(x.remove("setText(").remove(')'));
v="Done";
}
return v.isEmpty()?"No command":v;
}
return v.isEmpty()?"No command":v;
}

bool ViewItemSI::isValid() {
return dim->item;
}

QByteArray ViewItemSI::getHandle() {
return ("Finished editing "%dim->item->Name()).toLatin1();
}

ScriptInterface* ViewItemSI::newBox() {
BoxItem* bi=new BoxItem(kstApp->mainWindow()->tabWidget()->currentView());
kstApp->mainWindow()->tabWidget()->currentView()->scene()->addItem(bi);
Expand Down
8 changes: 1 addition & 7 deletions src/libkstapp/viewitemscriptinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,21 @@ class ViewItem;

struct LayoutTabSI {
ViewItem* vi;
QByteArrayList commands();
QString doCommand(QString x);
};

struct FillTabSI {
ViewItem* item;
QByteArrayList commands();
QString doCommand(QString x);
};

struct StrokeTabSI {
ViewItem* item;
QByteArrayList commands();
QString doCommand(QString x);
};

struct DimensionTabSI {
ViewItem* item;
QByteArrayList commands();
QString doCommand(QString x);
};

Expand All @@ -62,11 +58,9 @@ class ViewItemSI : public ScriptInterface
Q_OBJECT
public:
explicit ViewItemSI(ViewItem* it);
QByteArrayList commands();
QString doCommand(QString);
bool isValid();
QByteArray getHandle();
void endEditUpdate() {if (dim->item) dim->item->update();}
QByteArray endEditUpdate() {if (dim->item) dim->item->update();return ("Finished editing "+dim->item->Name()).toLatin1();}

static ScriptInterface* newBox();
static ScriptInterface* newButton();
Expand Down