2,000 changes: 2,000 additions & 0 deletions pyKst/demo/demodata.dat

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions pyKst/demo/equation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/python2.7
import pykst as kst

client=kst.Client("TestX2")

v1 = client.new_generated_vector(-10, 10, 1000)
e1 = client.new_equation(v1, "sin(x)")
c1 = client.new_curve(e1.x(), e1.y())
p1 = client.new_plot()
p1.add(c1)
25 changes: 12 additions & 13 deletions pyKst/demo/testdataobjects.py → pyKst/demo/equation_histogram.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
#!/usr/bin/python2.7
import pykst as kst

client=kst.Client("TestPlugins")
client=kst.Client("EqHist")

v1 = client.new_generated_vector(0, 10, 1000)
v4 = client.new_generated_vector(0, 20, 10000)

e1 = client.new_equation(v1, "x^2")
e1.set_x(v4)
v2 = e1.Y()
v3 = e1.X()
print v2.name(), v2.value(3), v3.value(3), v2.description_tip()
v2 = e1.y()
v3 = e1.x()
print "vector 2 name: ", v2.name()
print "vector 2 Value at 4th element: ", v2.value(3)

print v1.type_str(), v3.type_str()
print "vector 1 type: ", v1.type_str()

c1 = client.new_curve(e1.X(), e1.Y())
c1 = client.new_curve(e1.x(), e1.y())
c1.set_color("blue")

p1 = client.new_plot((0.5,0.25), (1,0.5))
p1.add(c1)

psd1 = client.new_spectrum(e1.X())
c2 = client.new_curve(psd1.X(), psd1.Y())
psd1 = client.new_spectrum(e1.x())
c2 = client.new_curve(psd1.x(), psd1.y())
c2.set_color("green")

p2 = client.new_plot((0.5,0.75), (1,0.5))
#p2.add(c2)

print "average?", psd1.interleaved_average()

h1 = client.new_histogram(v2)

c3 = client.new_curve(h1.X(), h1.Y())
c3 = client.new_curve(h1.x(), h1.y())
c3.set_color("black")
c3.set_has_bars(True)
c3.set_has_lines(False)
Expand All @@ -40,5 +38,6 @@

h1.change(v2, 0, 400, 10)

print h1.bin_min(), h1.bin_max(), h1.n_bins(), h1.auto_bin()
print "histogram 1 range: ", h1.bin_min(), h1.bin_max()
print "histogram 1 num bins: ", h1.num_bins()

118 changes: 0 additions & 118 deletions pyKst/demo/kstOwl.py

This file was deleted.

18 changes: 10 additions & 8 deletions pyKst/demo/matrix.py → pyKst/demo/numpy_matrix.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/python
import pykst as kst
from datetime import datetime
from numpy import *
from PyQt4 import QtCore, QtNetwork, QtGui
#from PyQt4 import QtCore, QtNetwork, QtGui

def mandelbrot( h,w, maxit=10 ):
'''Returns an image of the Mandelbrot fractal of size (h,w).
Expand All @@ -17,12 +16,15 @@ def mandelbrot( h,w, maxit=10 ):
diverge = z*conj(z) > 2**2 # who is diverging
div_now = diverge & (divtime==maxit) # who is diverging now
divtime[div_now] = i # note when
z[diverge] = 2 # avoid diverging too much
z[diverge] = 2.0 # avoid diverging too much

return divtime

client=kst.Client()
dt=datetime.now()
client.plot(mandelbrot(100,100))
arr_2d=kst.ExistingMatrix.getList(client)[-1].getNumPyArray()
client.plot(arr_2d)
client=kst.Client("numpy_matrix_demo")
np = mandelbrot(1000,1000)

M = client.new_editable_matrix(np)
I = client.new_image(M)
P = client.new_plot()
P.add(I)

43 changes: 43 additions & 0 deletions pyKst/demo/numpy_vector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/python2.7
import pykst as kst
from numpy import *
import time

client=kst.Client("VectorIO")

t0 = time.clock()

# create a pair of numpy arrays
x = linspace( 0, 50, 500000)
y = sin(x)

t1 = time.clock()

# copy the numpy arrays into kst and plot them
V1 = client.new_editable_vector(x)
V2 = client.new_editable_vector(y)
c1 = client.new_curve(V1, V2)
p1 = client.new_plot()
p1.add(c1)

t2 = time.clock()

# copy numpy array back into python.
A = V2.get_numpy_array()

t3 = time.clock()

# manipulate the array in python, and plot it in kst
A = A*A
V3 = client.new_editable_vector(A)
c2 = client.new_curve(V1, V3)
p1.add(c2)

# manipulate it again, and replace it in kst
A = A/2
V2.load(A)

print "creation of numpy arrays took", t1 - t0, "s"
print "copying onto kst and plotting took", t2-t1, "s"
print "copying from kst into python took:", t3-t2, "s"

27 changes: 27 additions & 0 deletions pyKst/demo/plot_layout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/python2.7
import pykst as kst

client=kst.Client("PlotLayoutDemo")

#autolayout in tab 1
p1 = client.new_plot(font_size = 12)

client.new_plot(font_size = 12)
client.new_plot(font_size = 12)
client.new_plot(font_size = 12)
client.new_plot(font_size = 12)
client.new_plot(font_size = 12)
client.new_plot(font_size = 12)
client.new_plot(font_size = 12)
client.new_plot(font_size = 12)

client.cleanup_layout(3)

p1.set_global_font(family = "Courier", font_size = 6)

# manual grid
client.new_tab()
for x in [.125, 0.375, 0.625, 0.875]:
for y in [.125, 0.375, 0.625, 0.875]:
client.new_plot((x,y),(0.25,0.25))

39 changes: 0 additions & 39 deletions pyKst/demo/primitives.py

This file was deleted.

20 changes: 9 additions & 11 deletions pyKst/demo/testvector.py → pyKst/demo/renamevector.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
#!/usr/bin/python2.7
import pykst as kst

client=kst.Client("TestVectors")
client=kst.Client("RenameDemo")
V1=client.new_data_vector("/home/cbn/programs/KDE/kst_tutorial/gyrodata.dat",
field="INDEX",
start=0,NFrames=1000)
start=0,num_frames=1000)

V2=client.new_data_vector("/home/cbn/programs/KDE/kst_tutorial/gyrodata.dat",
field="Column 2",
start=0,NFrames=1000)
start=0,num_frames=1000)

c1 = client.new_curve(V1, V2)

p1 = client.new_plot()
p1 = client.new_plot(font_size = 12)

p1.add(c1)

print V2.length()

print "-------------- Scalar list -------------"
print client.get_scalar_list()

print "--------------"
print "-------------- Vector list -------------"
vectors = client.get_vector_list()
print vectors
print "----------"

print vectors[1]

# change the name of the vector made from field "Column 1"
for Vname in vectors:
Vr = client.data_vector(Vname)
if Vr.field() == "Column 2":
print "Changing name of ", Vr.name(), " to A Gyro"
Vr.set_name("A Gyro")



27 changes: 0 additions & 27 deletions pyKst/demo/testmatrix.py

This file was deleted.

36 changes: 0 additions & 36 deletions pyKst/demo/testplugins.py

This file was deleted.

49 changes: 0 additions & 49 deletions pyKst/demo/testvectorIO.py

This file was deleted.

46 changes: 0 additions & 46 deletions pyKst/demo/testviewitems.py

This file was deleted.

13 changes: 9 additions & 4 deletions pyKst/demo/ksnspire.py → pyKst/demo/textinput.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/python

# demonstrate buttons and line inputs:
# plot an equation the user inputs

import sip
sip.setapi('QString', 1)
import pykst as kst
Expand All @@ -16,12 +20,13 @@ def __init__(self,client):
self.s2.readyRead.connect(self.changeValue)
self.l=kst.LineEdit(client,"",self.s2,0.47,0.975,0.93,0.025)
self.b=kst.Button(client,"Go!",self.s,0.97,0.975,0.05,0.025)
self.plot=kst.Plot(client,0.5,0.4885,0.9,0.8,0,"KsNspirePLOT")
self.genVec=kst.GeneratedVector(self.client,-100,100,1000)
self.plot=client.new_plot((0.5,0.4885),(0.9,0.8))
self.genVec=client.new_generated_vector(-100,100,1000)

def create(self):
eq = kst.NewEquation(self.client,self.text,self.genVec)
kst.NewCurve(client,eq.X(), eq.Y(), curvecolor="black", curveweight=1, placeinexistingplot=self.plot)
eq = client.new_equation(self.genVec, self.text)
c = client.new_curve(eq.x(), eq.y())
self.plot.add(c)

def changeValue(self):
strx=QtCore.QString(self.s2.read(8000))
Expand Down
19 changes: 0 additions & 19 deletions pyKst/demo/vectors.py

This file was deleted.

27 changes: 27 additions & 0 deletions pyKst/demo/viewitems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/python2.7
import pykst as kst

client=kst.Client("viewitems")


P1=client.new_plot((0.25,0.25),(0.5,0.5),0)
P1.set_x_range(-10.0,10.0)
P1.set_global_font("courier",12,False,False)

C1 = client.new_circle((0.9,0.3),0.1, stroke_width = 2, stroke_brush_color="red")
C1.set_fill_color("Green")

B1 = client.new_box((0.9,0.9), (0.1,0.1), fill_color="pink")

E1 = client.new_ellipse((0.1, 0.7), (0.1, 0.1), 45, fill_color="blue")

A1 = client.new_arrow((0.1, 0.5), 0.1, 45, False, True, 18)
A1.set_stroke_style(3)

L1 = client.new_line((0.1, 0.5), 0.1, 15, stroke_width=4, stroke_brush_color="green")
L1.set_stroke_style(2)

Label = client.new_label("Label Here", (0.7,0.7), 0, 16, font_family="courier")
Label.set_font_italic(True)


21 changes: 15 additions & 6 deletions pyKst/html/index.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
.. toctree::
:maxdepth: 2

Welcome to pykst's documentation!
PyKst documentation
=================================
PyKst is a python interface to kst. With PyKst, scripts can control and share data with a kst session.

Clients
*******************
To interact with a kst session, you must create a client. To open an interface with the last kst session started, or if none open, a new one, try::
The following minimal example plots sin(x) from -10 to 10::

import pykst as kst

client=kst.Client("TestSinX")

import pykst as kst
client = kst.Client()
v1 = client.new_generated_vector(-10, 10, 1000)
e1 = client.new_equation(v1, "sin(x)")
c1 = client.new_curve(e1.x(), e1.y())
p1 = client.new_plot()
p1.add(c1)



Clients
*******************
.. automodule:: pykst
:members: Client
:exclude-members: getArray, getList, send
Expand Down
548 changes: 284 additions & 264 deletions pyKst/pykst.py

Large diffs are not rendered by default.

29 changes: 23 additions & 6 deletions src/libkstapp/plotscriptinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,19 +277,29 @@ QString PlotSI::normalizeXtoY(QString &) {
}


QString PlotSI::setLogX(QString &) {
QString PlotSI::setLogX(QString &command) {

if (_item) {
_item->zoomLogX();
QString arg = getArg(command);
if (arg.toLower()=="true") {
_item->zoomLogX(false, false, true);
} else {
_item->zoomLogX(false, false, false);
}
}
return "Done.";
}


QString PlotSI::setLogY(QString &) {
QString PlotSI::setLogY(QString &command) {

if (_item) {
_item->zoomLogY();
QString arg = getArg(command);
if (arg.toLower()=="true") {
_item->zoomLogY(false, false, true);
} else {
_item->zoomLogY(false, false, false);
}
}
return "Done.";
}
Expand Down Expand Up @@ -333,15 +343,22 @@ QString PlotSI::setGlobalFont(QString &command) {
if (_item) {
QFont font = _item->globalFont();
QString family = vars.at(0);
bool bold = ((vars.at(1)=="bold") || (vars.at(1)=="true"));
bool italic = ((vars.at(2)=="italic") || (vars.at(2)=="true"));
qreal size = vars.at(1).toDouble();
bool bold = ((vars.at(2)=="bold") || (vars.at(2)=="true"));
bool italic = ((vars.at(3)=="italic") || (vars.at(3)=="true"));
if (!family.isEmpty()) {
font.setFamily(family);
}


font.setItalic(italic);
font.setBold(bold);

_item->setGlobalFont(font);
if (size>1.0) {
_item->setGlobalFontScale(size);
}

}
return "Done.";
}
Expand Down
20 changes: 20 additions & 0 deletions src/libkstapp/scriptserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ ScriptServer::ScriptServer(ObjectStore *obj) : _server(new QLocalServer(this)),
_fnMap.insert("fileOpen()", &ScriptServer::fileOpen);
_fnMap.insert("fileSave()", &ScriptServer::fileSave);

_fnMap.insert("cleanupLayout()", &ScriptServer::cleanupLayout);

#if 0

_fnMap.insert("EditableVector::setBinaryArray()",&ScriptServer::editableVectorSetBinaryArray);
Expand Down Expand Up @@ -946,5 +948,23 @@ QByteArray ScriptServer::fileSave(QByteArray&command, QLocalSocket* s, ObjectSto
return handleResponse("Done",s);
}

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

QString param = command.replace("cleanupLayout(","").replace(")","");
bool isNum = true;
int n_cols = param.toInt(&isNum);

if (isNum) { // columns
kstApp->mainWindow()->tabWidget()->currentView()->createLayout(false, n_cols);
} else if (param.toLower() == "protect") {
kstApp->mainWindow()->tabWidget()->currentView()->createLayout();
} else {
kstApp->mainWindow()->tabWidget()->currentView()->createUnprotectedLayout();
}

kstApp->mainWindow()->tabWidget()->setCurrentIndex(command.replace("setTab(","").replace(")","").toInt());
return handleResponse("Done",s);
}


}
2 changes: 2 additions & 0 deletions src/libkstapp/scriptserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ public slots:
QByteArray fileOpen(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
QByteArray fileSave(QByteArray& command, QLocalSocket* s,ObjectStore*_store);

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

};


Expand Down