275 changes: 198 additions & 77 deletions pyKst/pykst.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/libkstapp/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void MainWindow::saveAs() {
QString restorePath = QDir::currentPath();
QString kstfiledir = fn.left(fn.lastIndexOf('/')) + '/';
QDir::setCurrent(kstfiledir);
QString currentP = QDir::currentPath();
//QString currentP = QDir::currentPath();
_doc->save(fn);
QDir::setCurrent(restorePath);
setWindowTitle("Kst - " + fn);
Expand Down
34 changes: 26 additions & 8 deletions src/libkstapp/scriptserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ ScriptServer::ScriptServer(ObjectStore *obj) : _server(new QLocalServer(this)),
// _fnMap.insert("newPlugin()",&ScriptServer::newPlugin);

_fnMap.insert("getImageList()",&ScriptServer::getImageList);
// _fnMap.insert("newImage()",&ScriptServer::newImage);
_fnMap.insert("newImage()",&ScriptServer::newImage);

_fnMap.insert("getCSDList()",&ScriptServer::getCSDList);
// _fnMap.insert("newCSD()",&ScriptServer::newCSD);
Expand Down Expand Up @@ -191,6 +191,8 @@ ScriptServer::ScriptServer(ObjectStore *obj) : _server(new QLocalServer(this)),
_fnMap.insert("setPaused()",&ScriptServer::setPaused);
_fnMap.insert("unsetPaused()",&ScriptServer::unsetPaused);

_fnMap.insert("fileOpen()", &ScriptServer::fileOpen);
_fnMap.insert("fileSave()", &ScriptServer::fileSave);

#if 0

Expand Down Expand Up @@ -654,16 +656,15 @@ QByteArray ScriptServer::getImageList(QByteArray&, QLocalSocket* s,ObjectStore*_

return outputObjectList<Image>(s,_store);
}
/*
QByteArray ScriptServer::newImage(QByteArray&, QLocalSocket* s,ObjectStore*,const int&ifMode,

if(_interface) { return handleResponse("To access this function, first call endEdit()",s); }
else {
_interface = DialogLauncherSI::self->showImageDialog();
return handleResponse("Ok",s);
QByteArray ScriptServer::newImage(QByteArray&, QLocalSocket* s,ObjectStore*) {

if(_interface) {
return handleResponse("To access this function, first call endEdit()",s);
} else {
_interface = ImageSI::newImage(_store); return handleResponse("Ok",s);
}
}
*/


QByteArray ScriptServer::getCSDList(QByteArray&, QLocalSocket* s,ObjectStore*_store) {
Expand Down Expand Up @@ -1025,6 +1026,23 @@ QByteArray ScriptServer::unsetPaused(QByteArray&, QLocalSocket* s,ObjectStore*)

}

QByteArray ScriptServer::fileOpen(QByteArray&command, QLocalSocket* s, ObjectStore*) {
command.replace("fileOpen(", "");
command.chop(1);

kstApp->mainWindow()->openFile(command);

return handleResponse("Done",s);
}

QByteArray ScriptServer::fileSave(QByteArray&command, QLocalSocket* s, ObjectStore*) {
command.replace("fileSave(", "");
command.chop(1);

kstApp->mainWindow()->document()->save(command);

return handleResponse("Done",s);
}

QByteArray ScriptServer::editableVectorSetBinaryArray(QByteArray&command, QLocalSocket* s, ObjectStore*) {

Expand Down
5 changes: 4 additions & 1 deletion src/libkstapp/scriptserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public slots:
//QByteArray newPlugin(QByteArray& command, QLocalSocket* s,ObjectStore*_store);

QByteArray getImageList(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
//QByteArray newImage(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
QByteArray newImage(QByteArray& command, QLocalSocket* s,ObjectStore*_store);

QByteArray getCSDList(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
//QByteArray newCSD(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
Expand Down Expand Up @@ -163,6 +163,9 @@ public slots:
QByteArray setPaused(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
QByteArray unsetPaused(QByteArray& command, QLocalSocket* s,ObjectStore*_store);

QByteArray fileOpen(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
QByteArray fileSave(QByteArray& command, QLocalSocket* s,ObjectStore*_store);


// Hacks
QByteArray editableVectorSetBinaryArray(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
Expand Down
13 changes: 10 additions & 3 deletions src/libkstmath/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Image::Image(ObjectStore *store) : Relation(store) {
_initializeShortName();

_hasContourMap = false;
_hasColorMap = false;
_hasColorMap = true;
setColorDefaults();
setContourDefaults();

Expand Down Expand Up @@ -158,8 +158,8 @@ QColor Image::getMappedColor(double z) {
}


void Image::setPalette(const Palette &pal) {
_pal.changePaletteName(pal.paletteName());
void Image::setPalette(const QString &palname) {
_pal.changePaletteName(palname);
}


Expand Down Expand Up @@ -196,6 +196,13 @@ void Image::setThresholdToSpikeInsensitive(double per) {
}


void Image::setMatrix(MatrixPtr in_matrix) {
if (in_matrix) {
_inputMatrices[THEMATRIX] = in_matrix;
}
}


void Image::changeToColorOnly(MatrixPtr in_matrix, double lowerZ,
double upperZ, bool autoThreshold, const QString &paletteName) {

Expand Down
3 changes: 2 additions & 1 deletion src/libkstmath/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class KSTMATH_EXPORT Image : public Relation {

virtual bool getNearestZ(double x, double y, double& z, QPointF &matchedPoint);
virtual QColor getMappedColor(double z);
virtual void setPalette(const Palette &pal);
virtual void setPalette(const QString &palname);
virtual void setUpperThreshold(double z);
virtual void setLowerThreshold(double z);
virtual void setAutoThreshold(bool yes);
Expand All @@ -66,6 +66,7 @@ class KSTMATH_EXPORT Image : public Relation {
virtual double lowerThreshold() const { return _zLower; }
virtual bool autoThreshold() const { return _autoThreshold; }

virtual void setMatrix(MatrixPtr in_matrix);
virtual MatrixPtr matrix() const;
virtual QString paletteName() const;
virtual const Palette &palette() const { return _pal; }
Expand Down
166 changes: 166 additions & 0 deletions src/libkstmath/relationscriptinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "vector.h"
#include "colorsequence.h"
#include "linestyle.h"
#include "palette.h"

#include <QStringBuilder>

Expand Down Expand Up @@ -109,6 +110,13 @@ CurveSI::CurveSI(CurvePtr it) {
_fnMap.insert("minY",&CurveSI::minY);
_fnMap.insert("showEditDialog",&CurveSI::showEditDialog);

_fnMap.insert("xVector",&CurveSI::xVector);
_fnMap.insert("yVector",&CurveSI::yVector);
_fnMap.insert("xErrorVector",&CurveSI::xErrorVector);
_fnMap.insert("yErrorVector",&CurveSI::yErrorVector);
_fnMap.insert("xMinusErrorVector",&CurveSI::xMinusErrorVector);
_fnMap.insert("yMinusErrorVector",&CurveSI::yMinusErrorVector);

}

QString CurveSI::doCommand(QString command_in) {
Expand Down Expand Up @@ -420,5 +428,163 @@ QString CurveSI::pointDensity(QString& command) {
return QString::number(curve->pointDensity());
}

QString CurveSI::xVector(QString &) {
return curve->xVector()->shortName();
}

QString CurveSI::yVector(QString &) {
return curve->yVector()->shortName();
}

QString CurveSI::xErrorVector(QString &) {
return curve->xErrorVector()->shortName();
}

QString CurveSI::yErrorVector(QString &) {
return curve->yErrorVector()->shortName();
}

QString CurveSI::xMinusErrorVector(QString &) {
return curve->xMinusErrorVector()->shortName();
}

QString CurveSI::yMinusErrorVector(QString &) {
return curve->yMinusErrorVector()->shortName();
}


/******************************************************/
/* Images */
/******************************************************/
ImageSI::ImageSI(ImagePtr it) {
image=it;
relation = it;

_fnMap.insert("setMatrix", &ImageSI::setMatrix);
_fnMap.insert("setPalette", &ImageSI::setPalette);
_fnMap.insert("setFixedColorRange", &ImageSI::setFixedColorRange);
_fnMap.insert("setAutoColorRange", &ImageSI::setAutoColorRange);

_fnMap.insert("lowerThreshold", &ImageSI::lowerThreshold);
_fnMap.insert("upperThreshold", &ImageSI::upperThreshold);

// functions from relationSI
_fnMap.insert("maxX",&ImageSI::maxX);
_fnMap.insert("minX",&ImageSI::minX);
_fnMap.insert("maxY",&ImageSI::maxY);
_fnMap.insert("minY",&ImageSI::minY);
_fnMap.insert("showEditDialog",&ImageSI::showEditDialog);

}

QString ImageSI::doCommand(QString command_in) {
QString command = command_in.left(command_in.indexOf('('));

ImageInterfaceMemberFn fn=_fnMap.value(command,&ImageSI::noSuchFn);

if(fn!=&ImageSI::noSuchFn) {
return CALL_MEMBER_FN(*this,fn)(command_in);
}


QString v=doRelationScriptCommand(command_in, image);
if (!v.isEmpty()) {
return v;
}

return "No such command";
}

bool ImageSI::isValid() {
return image.isPtrValid();
}

ScriptInterface* ImageSI::newImage(ObjectStore *store) {
ImagePtr image;
image = store->createObject<Image>();
image->setAutoThreshold(true);
image->setPalette(Palette::getPaletteList().at(0));

return new ImageSI(image);
}

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

/***************************/
/* commands */
/***************************/

QString ImageSI::setMatrix(QString& command) {
QString parameter = getArg(command);

MatrixPtr m = kst_cast<Matrix>(image->store()->retrieveObject(parameter));

if (m) {
image->setMatrix(m);
return "Done";
} else {
return QString("matrix %1 not found").arg(parameter);
}
}

QString ImageSI::setPalette(QString& command) {
QString parameter = getArg(command);
int x = parameter.toInt();

if (x<0) x = 0;

QStringList palette_list = Palette::getPaletteList();

if (x>=palette_list.length()) {
x = palette_list.length();
}
image->setPalette(palette_list.at(x));

return "Done";
}

QString ImageSI::setFixedColorRange(QString& command) {
QStringList vars = getArgs(command);

double zmin = vars[0].toDouble();
double zmax = vars[1].toDouble();

if (zmin==zmax) {
image->setAutoThreshold(true);
} else {
if (zmin>zmax) {
double z = zmax;
zmax = zmin;
zmin = z;
}
image->setAutoThreshold(false);
image->setLowerThreshold(zmin);
image->setUpperThreshold(zmax);
}
return "Done";
}


QString ImageSI::setAutoColorRange(QString& command) {
QString parameter = getArg(command);
double per = parameter.toDouble();

image->setThresholdToSpikeInsensitive(per);

return "Done";
}

QString ImageSI::lowerThreshold(QString&) {
return QString::number(image->lowerThreshold());
}

QString ImageSI::upperThreshold(QString&) {
return QString::number(image->upperThreshold());
}

}
40 changes: 40 additions & 0 deletions src/libkstmath/relationscriptinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@

#include "scriptinterface.h"
#include "curve.h"
#include "image.h"

namespace Kst {

class CurveSI;
typedef QString (CurveSI::*CurveInterfaceMemberFn)(QString& command);

class ImageSI;
typedef QString (ImageSI::*ImageInterfaceMemberFn)(QString& command);

class KSTMATH_EXPORT RelationSI : public ScriptInterface
{
Q_OBJECT
Expand Down Expand Up @@ -99,6 +103,42 @@ class KSTMATH_EXPORT CurveSI : public RelationSI
QString lineStyle(QString&);
QString pointDensity(QString& command);

QString xVector(QString &);
QString yVector(QString &);
QString xErrorVector(QString &);
QString yErrorVector(QString &);
QString xMinusErrorVector(QString &);
QString yMinusErrorVector(QString &);

};

class KSTMATH_EXPORT ImageSI : public RelationSI
{
Q_OBJECT
public:
explicit ImageSI(ImagePtr it);
QString doCommand(QString);
bool isValid();
QByteArray endEditUpdate();

static ScriptInterface* newImage(ObjectStore *store);

protected:
QString noSuchFn(QString&) {return ""; }

private:
ImagePtr image;

QMap<QString,ImageInterfaceMemberFn> _fnMap;

QString setMatrix(QString& command);
QString setPalette(QString& command);
QString setFixedColorRange(QString& command);
QString setAutoColorRange(QString& command);

QString lowerThreshold(QString&);
QString upperThreshold(QString&);

};

}
Expand Down