Showing with 101 additions and 27 deletions.
  1. +34 −15 pyKst/pykst.py
  2. +2 −0 src/libkstapp/plotitem.cpp
  3. +40 −10 tests/dirfile_maker/dirfile_maker.c
  4. +2 −2 tests/dirfile_maker/dirfile_maker.pro
  5. +23 −0 tests/dirfile_maker/dirfile_maker_new.pro
49 changes: 34 additions & 15 deletions pyKst/pykst.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
import sys
import math
import os
import ctypes
from PyQt4 import QtCore, QtNetwork
#from PySide import QtCore, QtNetwork
import atexit
import os

try:
from PySide import QtCore, QtNetwork, QtGui
except ImportError as err1:
try:
from PyQt4 import QtCore, QtNetwork, QtGui
except ImportError as err2:
print("ImportError: {} and {}. One of the two is required.".format(err1, err2))
sys.exit()

QtGui.QApplication([""])

from numpy import *
import tempfile
import time
import subprocess

def cleanTmpFile(file):
os.remove(file.name)

def b2str(val):
if isinstance(val, bool):
return "True" if val else "False"
else:
return str(val)


class Client:
""" An interface to a running kst session.
Expand Down Expand Up @@ -46,15 +60,14 @@ def __init__(self,server_name="kstScript"):
self.ls.connectToServer(server_name)
self.ls.waitForConnected(300)
self.server_name=server_name
if self.ls.state()==QtNetwork.QLocalSocket.UnconnectedState:
#os.system("kst2 --server_name="+str(server_name)+"&")
subprocess.Popen(["kst2", "--serverName="+str(server_name)])
#time.sleep(1)

if self.ls.state() == QtNetwork.QLocalSocket.UnconnectedState:
subprocess.Popen(["kst2","--serverName="+str(server_name)])
time.sleep(.5)

while self.ls.state()==QtNetwork.QLocalSocket.UnconnectedState:
self.ls.connectToServer(server_name)
self.ls.waitForConnected(300)
self.server_name=server_name

def send(self,command):
""" Sends a command to kst and returns a response.
Expand Down Expand Up @@ -1118,7 +1131,9 @@ def __init__(self, client, np_array = None, name="", new=True) :
if (np_array != None) :
assert(np_array.dtype == float64)

with tempfile.NamedTemporaryFile() as f:
with tempfile.NamedTemporaryFile(delete=False) as f:
f.close()
atexit.register(cleanTmpFile, f)
np_array.tofile(f.name)
self.client.send("load(" + f.name + ")")

Expand All @@ -1134,8 +1149,9 @@ def load(self, np_array):
1D np array """

assert(np_array.dtype == float64)

with tempfile.NamedTemporaryFile() as f:
with tempfile.NamedTemporaryFile(delete=False) as f:
f.close()
atexit.register(cleanTmpFile, f)
np_array.tofile(f.name)
retval = self.client.send_si(self.handle, "load(" + f.name + ")")

Expand Down Expand Up @@ -1301,7 +1317,9 @@ def __init__(self, client, np_array = None, name="", new=True) :
nx = np_array.shape[0]
ny = np_array.shape[1]

with tempfile.NamedTemporaryFile() as f:
with tempfile.NamedTemporaryFile(delete=False) as f:
f.close()
atexit.register(cleanTmpFile, f)
np_array.tofile(f.name)
self.client.send("load(" + f.name + ","+b2str(nx)+","+b2str(ny)+")")

Expand All @@ -1320,7 +1338,9 @@ def load(self, np_array):
nx = np_array.shape[0]
ny = np_array.shape[1]

with tempfile.NamedTemporaryFile() as f:
with tempfile.NamedTemporaryFile(delete=False) as f:
f.close()
atexit.register(cleanTmpFile, f)
np_array.tofile(f.name)
retval = self.client.send_si(self.handle, "load(" + f.name + ","+b2str(nx)+","+b2str(ny)+")")

Expand Down Expand Up @@ -3003,7 +3023,6 @@ def __init__(self,client,pos=(0,0),size=(0,0),rot=0,
self.client.send("addToCurrentView(Auto,2)")
else:
self.client.send("addToCurrentView(Protect,2)")

self.handle=self.client.send("endEdit()")

self.handle.remove(0,self.handle.indexOf("ing ")+4)
Expand Down Expand Up @@ -3231,4 +3250,4 @@ def set_text(self,text):
""" Sets the text of the line edit. """
self.client.send("beginEdit("+self.handle+")")
self.client.send("setText("+b2str(text)+")")
self.client.send("endEdit()")
self.client.send("endEdit()")
2 changes: 2 additions & 0 deletions src/libkstapp/plotitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2837,6 +2837,8 @@ QPainterPath PlotItem::tiedZoomCheck() const {
grip = QRectF(QPointF(_calculatedPlotRect.topRight().x() + sizeOfGrip().width() * .25, _calculatedPlotRect.topRight().y() - sizeOfGrip().height() * -.25), sizeOfGrip());
} else if (sharedAxisBox()->isYAxisShared()) {
grip = QRectF(QPointF(_calculatedPlotRect.topRight().x() - sizeOfGrip().width() * 1.25, _calculatedPlotRect.topRight().y() - sizeOfGrip().height() * 1.25), sizeOfGrip());
} else {
qDebug() << "warning: no grip set in PlotItem::tiedZoomCheck (bug?)";
}
QPainterPath path;
if (isXTiedZoom() && isYTiedZoom()) {
Expand Down
50 changes: 40 additions & 10 deletions tests/dirfile_maker/dirfile_maker.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <fcntl.h>
#include <math.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>

struct DFEntryType {
char field[17];
Expand Down Expand Up @@ -51,7 +53,7 @@ int main() {

struct timeval tv;

sprintf(dirfilename, "%d.dm", time(NULL));
sprintf(dirfilename, "%lu.dm", time(NULL));

printf("Writing dirfile %s\n", dirfilename);
printf("The fields are:\n");
Expand All @@ -69,7 +71,9 @@ int main() {
fpf = fopen(tmpstr,"w");
/* make curfile */
unlink("dm.lnk");
symlink(dirfilename, "dm.lnk");
if (symlink(dirfilename, "dm.lnk")<0) {
fprintf(stderr, "symlink of %s to dm.lnk failed\n", dirfilename);
}

sleep(1);
for (i=0; i<NDF; i++) {
Expand All @@ -91,56 +95,82 @@ int main() {

printf("starting loop\n");
while (1) {
int nw;
/* write 'fcount' */
for (i=0; i<df[FCOUNT].spf; i++) {
x = count*df[FCOUNT].spf+i;
write(df[FCOUNT].fp, &x, sizeof(float));
nw = write(df[FCOUNT].fp, &x, sizeof(float));
if (nw<0) {
fprintf(stderr, "error writing fcount\n");
}
}

/* write 'sine' */
for (i=0; i<df[SINE].spf; i++) {
dx = count*df[SINE].spf+i;
x = sin(2.0*M_PI*dx/100.0);
write(df[SINE].fp, &x, sizeof(float));
nw = write(df[SINE].fp, &x, sizeof(float));
if (nw<0) {
fprintf(stderr, "error writing sin\n");
}
}

/* write 'ssine' */
for (i=0; i<df[SSINE].spf; i++) {
dx = count*df[SSINE].spf+i;
x = sin(2.0*M_PI*dx/100.0);
write(df[SSINE].fp, &x, sizeof(float));
nw = write(df[SSINE].fp, &x, sizeof(float));
if (nw<0) {
fprintf(stderr, "error writing ssine\n");
}

}

/* write 'cos' */
for (i=0; i<df[COS].spf; i++) {
dx = count*df[COS].spf+i;
x = cos(2.0*M_PI*dx/100.0);
write(df[COS].fp, &x, sizeof(float));
nw = write(df[COS].fp, &x, sizeof(float));
if (nw<0) {
fprintf(stderr, "error writing cos\n");
}

}

gettimeofday(&tv, 0);
for (i=0; i<df[TIME].spf; i++) {
dx = (double)tv.tv_sec +( double)(tv.tv_usec)/1000000.0 + (double)i/100.0;
write(df[TIME].fp, &dx, sizeof(double));
nw = write(df[TIME].fp, &dx, sizeof(double));
if (nw<0) {
fprintf(stderr, "error writing time\n");
}

}

/* write extras */
for (j=6; j<NDF; j++) {
for (i=0; i<df[j].spf; i++) {
x = (double)rand()/(double)RAND_MAX;
write(df[j].fp, &x, sizeof(float));
nw = write(df[j].fp, &x, sizeof(float));
if (nw<0) {
fprintf(stderr, "error writing E%d\n", j);
}

}
}

/* write 'count' */
x = count;
write(df[SCOUNT].fp, &x, sizeof(float));
nw = write(df[SCOUNT].fp, &x, sizeof(float));
if (nw<0) {
fprintf(stderr, "error writing count\n");
}


printf("writing frame %d \r", count);
fflush(stdout);
usleep(200000);
count++;
}
return (42);
return (0);
}
4 changes: 2 additions & 2 deletions tests/dirfile_maker/dirfile_maker.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ TOPOUT_REL=../..
include($$PWD/$$TOPOUT_REL/kst.pri)

TEMPLATE = app
TARGET = $$kstlib(dirfile_maker_new)
TARGET = $$kstlib(dirfile_maker)
DESTDIR = $$OUTPUT_DIR/bin
CONFIG -= precompile_header windows
CONFIG += console
Expand All @@ -18,6 +18,6 @@ INCLUDEPATH +=

LIBS +=

SOURCES += dirfile_maker_new.c
SOURCES += dirfile_maker.c


23 changes: 23 additions & 0 deletions tests/dirfile_maker/dirfile_maker_new.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
TOPOUT_REL=../..
include($$PWD/$$TOPOUT_REL/kst.pri)

TEMPLATE = app
TARGET = $$kstlib(dirfile_maker_new)
DESTDIR = $$OUTPUT_DIR/bin
CONFIG -= precompile_header windows
CONFIG += console

QT -= core xml gui

!isEmpty(INSTALL_PREFIX) {
target.path = $$INSTALL_PREFIX/bin
INSTALLS += target
}

INCLUDEPATH +=

LIBS +=

SOURCES += dirfile_maker_new.c