Showing with 355 additions and 91 deletions.
  1. +8 −0 pyKst/demo/testdataobjects.py
  2. +37 −0 pyKst/pykst.py
  3. +9 −34 src/libkstapp/scriptserver.cpp
  4. +2 −2 src/libkstapp/scriptserver.h
  5. +2 −1 src/libkstmath/basicplugin.cpp
  6. +3 −0 src/libkstmath/dataobject.cpp
  7. +1 −0 src/libkstmath/dataobject.h
  8. +184 −49 src/libkstmath/dataobjectscriptinterface.cpp
  9. +61 −5 src/libkstmath/dataobjectscriptinterface.h
  10. +8 −0 src/libkstmath/equation.cpp
  11. +2 −0 src/libkstmath/equation.h
  12. +1 −0 src/plugins/dataobject/bin/bin.cpp
  13. +1 −0 src/plugins/dataobject/chop/chop.cpp
  14. +1 −0 src/plugins/dataobject/convolution/convolve/convolve.cpp
  15. +1 −0 src/plugins/dataobject/convolution/deconvolve/deconvolve.cpp
  16. +1 −0 src/plugins/dataobject/correlation/autocorrelation/autocorrelation.cpp
  17. +1 −0 src/plugins/dataobject/correlation/crosscorrelation/crosscorrelation.cpp
  18. +1 −0 src/plugins/dataobject/crossspectrum/crossspectrum.cpp
  19. +1 −0 src/plugins/dataobject/effectivebandwidth/effectivebandwidth.cpp
  20. +1 −0 src/plugins/dataobject/genericfilter/genericfilter.cpp
  21. +1 −0 src/plugins/dataobject/interpolations/akima/akima.cpp
  22. +1 −0 src/plugins/dataobject/interpolations/akimaperiodic/akimaperiodic.cpp
  23. +1 −0 src/plugins/dataobject/interpolations/cspline/cspline.cpp
  24. +1 −0 src/plugins/dataobject/interpolations/csplineperiodic/csplineperiodic.cpp
  25. +1 −0 src/plugins/dataobject/interpolations/linear/linear.cpp
  26. +1 −0 src/plugins/dataobject/interpolations/polynomial/polynomial.cpp
  27. +1 −0 src/plugins/dataobject/linefit/linefit.cpp
  28. +1 −0 src/plugins/dataobject/lockin/lockin.cpp
  29. +1 −0 src/plugins/dataobject/noiseaddition/noiseaddition.cpp
  30. +1 −0 src/plugins/dataobject/periodogram/periodogram.cpp
  31. +1 −0 src/plugins/dataobject/phase/phase.cpp
  32. +1 −0 src/plugins/dataobject/shift/shift.cpp
  33. +1 −0 src/plugins/dataobject/statistics/statistics.cpp
  34. +1 −0 src/plugins/dataobject/syncbin/syncbin.cpp
  35. +1 −0 src/plugins/fits/exponential_unweighted/fitexponential_unweighted.cpp
  36. +1 −0 src/plugins/fits/exponential_weighted/fitexponential_weighted.cpp
  37. +1 −0 src/plugins/fits/gaussian_unweighted/fitgaussian_unweighted.cpp
  38. +1 −0 src/plugins/fits/gaussian_weighted/fitgaussian_weighted.cpp
  39. +1 −0 src/plugins/fits/gradient_unweighted/fitgradient_unweighted.cpp
  40. +1 −0 src/plugins/fits/gradient_weighted/fitgradient_weighted.cpp
  41. +1 −0 src/plugins/fits/kneefrequency/fitkneefrequency.cpp
  42. +1 −0 src/plugins/fits/linear_unweighted/fitlinear_unweighted.cpp
  43. +1 −0 src/plugins/fits/linear_weighted/fitlinear_weighted.cpp
  44. +1 −0 src/plugins/fits/lorentzian_unweighted/fitlorentzian_unweighted.cpp
  45. +1 −0 src/plugins/fits/lorentzian_weighted/fitlorentzian_weighted.cpp
  46. +1 −0 src/plugins/fits/polynomial_unweighted/fitpolynomial_unweighted.cpp
  47. +1 −0 src/plugins/fits/polynomial_weighted/fitpolynomial_weighted.cpp
  48. +1 −0 src/plugins/fits/sinusoid_unweighted/fitsinusoid_unweighted.cpp
  49. +1 −0 src/plugins/fits/sinusoid_weighted/fitsinusoid_weighted.cpp
8 changes: 8 additions & 0 deletions pyKst/demo/testdataobjects.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/python2.7
import pykst as kst

client=kst.Client("TestPlugins")

v1 = client.new_generated_vector(0, 10, 10)

e1 = client.new_equation(v1, "x^2")
37 changes: 37 additions & 0 deletions pyKst/pykst.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,20 @@ def image(self, name):
"""
return Image(self, "", "", name, new=False)

def new_equation(self, x_vector, equation, name=""):
""" Create a new Equation in kst.
See :class:`Equation`
"""
return Equation(self, x_vector, equation, name)

def equation(self, name):
""" Returns an Equation from kst given its name.
See :class:`Equation`
"""
return Equation(self, "", "", name, new=False)

def new_linear_fit(self, xVector, yVector, weightvector = 0, name = ""):
""" Create a New Linear Fit in kst.
Expand Down Expand Up @@ -1322,6 +1336,29 @@ def min_z(self):
""" Returns the max Z value of the curve or image. """
return self.client.send_si(self.handle, "minZ()")

# Equation ############################################################
class Equation(NamedObject) :
""" An equation inside kst.
:param x_vector: the x vector of the equation
:param equation: the equation
Vectors inside kst are refered to as [vectorname] or [scalarname].
"""
def __init__(self, client, xvector, equation, name="", new=True) :
NamedObject.__init__(self,client)

if (new == True):
self.client.send("newEquation()")

self.client.send("setEquation(" + equation + ")")
self.client.send("setInputVector(X,"+xvector.handle+")")
self.handle=self.client.send("endEdit()")
self.handle.remove(0,self.handle.indexOf("ing ")+4)
self.set_name(name)
else:
self.handle = name

# FIT ###################################################################
class Fit(NamedObject) :
""" This is a class which provides some methods common to all fits """
Expand Down
43 changes: 9 additions & 34 deletions src/libkstapp/scriptserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ ScriptServer::ScriptServer(ObjectStore *obj) : _server(new QLocalServer(this)),
_fnMap.insert("newCurve()",&ScriptServer::newCurve);

_fnMap.insert("getEquationList()",&ScriptServer::getEquationList);
// _fnMap.insert("newEquation()",&ScriptServer::newEquation);
_fnMap.insert("newEquation()",&ScriptServer::newEquation);

_fnMap.insert("getHistogramList()",&ScriptServer::getHistogramList);
// _fnMap.insert("newHistogram()",&ScriptServer::newHistogram);
Expand Down Expand Up @@ -332,12 +332,6 @@ QByteArray ScriptServer::exec(QByteArray command, QLocalSocket *s)
if(fn!=&ScriptServer::noSuchFn) {
return CALL_MEMBER_FN(*this,fn)(command, s,_store);
} else {
if(command.contains("::")) {
QByteArray ret=checkPrimatives(command,s);
if(!ret.isEmpty()) {
return ret;
}
}
if(_interface) {
return handleResponse(_interface->doCommand(command).toLatin1(),s); //magic
} else {
Expand All @@ -348,6 +342,7 @@ QByteArray ScriptServer::exec(QByteArray command, QLocalSocket *s)
return "?";
}

#if 0
QByteArray ScriptServer::checkPrimatives(QByteArray &command, QLocalSocket *s)
{
///
Expand Down Expand Up @@ -418,6 +413,7 @@ QByteArray ScriptServer::checkPrimatives(QByteArray &command, QLocalSocket *s)

return "";
}
#endif

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

Expand Down Expand Up @@ -588,16 +584,14 @@ QByteArray ScriptServer::getEquationList(QByteArray&, QLocalSocket* s,ObjectStor
return outputObjectList<Equation>(s,_store);
}

/*
QByteArray ScriptServer::newEquation(QByteArray&, QLocalSocket* s,ObjectStore*,const int&ifMode,
QByteArray ScriptServer::newEquation(QByteArray&, QLocalSocket* s,ObjectStore*) {

if(_interface) { return handleResponse("To access this function, first call endEdit()",s); }
else {
_interface = DialogLauncherSI::self->showEquationDialog();
return handleResponse("Ok",s);
if(_interface) {
return handleResponse("To access this function, first call endEdit()",s);
} else {
_interface = EquationSI::newEquation(_store); return handleResponse("Ok",s);
}
}
*/


QByteArray ScriptServer::getHistogramList(QByteArray&, QLocalSocket* s,ObjectStore*_store) {
Expand Down Expand Up @@ -647,7 +641,7 @@ QByteArray ScriptServer::newPlugin(QByteArray& plugin, QLocalSocket* s,ObjectSto
} else {
plugin.replace("newPlugin(","");
plugin.remove(plugin.lastIndexOf(")"),1);
_interface = DataObjectSI::newPlugin(store, plugin);
_interface = PluginSI::newPlugin(store, plugin);
return handleResponse("Ok",s);
}
}
Expand Down Expand Up @@ -690,25 +684,6 @@ QByteArray ScriptServer::getBasicPluginList(QByteArray&, QLocalSocket* s,ObjectS
return outputObjectList<BasicPlugin>(s,_store);
}

/*
QByteArray ScriptServer::newBasicPlugin(QByteArray&command, QLocalSocket* s,ObjectStore*,const int&ifMode,
command.replace("newBasicPlugin(","");
if(command.contains(")")) { command.remove(command.indexOf(")"),99999999); }
bool ok=0;
for(int i=0;i<DataObject::dataObjectPluginList().size();i++) {
if(command==DataObject::dataObjectPluginList()[i]) {
ok=1;
break;
}
}
if(!ok) { return handleResponse("No such plugin",s); }
else if(_interface) { return handleResponse("To access this function, first call endEdit()",s); }
else { _interface = DialogLauncherSI::self->showBasicPluginDialog(command); return handleResponse("Ok",s); }
}
*/

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

QString a;
Expand Down
4 changes: 2 additions & 2 deletions src/libkstapp/scriptserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ScriptServer : public QObject
public:
explicit ScriptServer(ObjectStore*obj);
~ScriptServer();
QByteArray checkPrimatives(QByteArray&command,QLocalSocket* s);
//QByteArray checkPrimatives(QByteArray&command,QLocalSocket* s);
void setStore(ObjectStore *obj) { _store = obj; vi.clear();}
public slots:
void procConnection();
Expand Down Expand Up @@ -79,7 +79,7 @@ public slots:
QByteArray newCurve(QByteArray& command, QLocalSocket* s,ObjectStore*_store);

QByteArray getEquationList(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
//QByteArray newEquation(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
QByteArray newEquation(QByteArray& command, QLocalSocket* s,ObjectStore*_store);

QByteArray getHistogramList(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
//QByteArray newHistogram(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
Expand Down
3 changes: 2 additions & 1 deletion src/libkstmath/basicplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ void BasicPlugin::_initializeShortName() {

}


ScriptInterface* BasicPlugin::createScriptInterface() {
return new DataObjectSI(this);
return new PluginSI(this);
}


Expand Down
3 changes: 3 additions & 0 deletions src/libkstmath/dataobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "primitive.h"
#include "settings.h"

#include "dataobjectscriptinterface.h"

#include <QApplication>
#include <QDir>
#include <qdebug.h>
Expand Down Expand Up @@ -145,6 +147,7 @@ StringPtr DataObject::outputString(const QString& string) const {

void DataObject::setInputVector(const QString &type, VectorPtr ptr) {
if (ptr) {
qDebug() << " data object set input vector" << type << "to" << ptr->Name();
_inputVectors[type] = ptr;
} else {
_inputVectors.remove(type);
Expand Down
1 change: 1 addition & 0 deletions src/libkstmath/dataobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class KSTMATH_EXPORT DataObject : public Object
// this is reimplemented but must not be virtual.
QByteArray scriptInterface(QList<QByteArray>&command);


protected slots:
virtual void showNewDialog() = 0;
virtual void showEditDialog() = 0;
Expand Down
Loading