21 changes: 18 additions & 3 deletions pyKst/demo/viewitems.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@
C1 = client.new_circle((0.9,0.3),0.1, stroke_width = 2, stroke_brush_color="red")
C1.set_fill_color("Green")

C1.set_diameter(0.05)

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 = client.new_arrow((0.1, 0.5), (0.2, 0.8), False, True, 18)
A1.set_stroke_style(3)
#A1.set_endpoints((0.2, 0.7), (0.05, 0.8))

L1 = client.new_line((0.1, 0.5), 0.1, 15, stroke_width=4, stroke_brush_color="green")
L1 = client.new_line((0.20, 0.20), (0.30, 0.30), stroke_width=4, stroke_brush_color="green")
L1.set_stroke_style(2)
L1.set_parent_auto()
L1.set_lock_pos_to_data(True)
L1.set_endpoints((-5,-0.05), (5, 0.05))

Label = client.new_label("Label Here", (0.7,0.7), 0, 16, font_family="courier")
Label.set_font_italic(True)
Expand All @@ -29,7 +35,16 @@
Label2.set_parent_auto()

P1.set_pos((0.5,0.5))
P1.set_fixed_aspect_ratio(True)

print Label2.position(), Label2.dimensions()

Label2.set_parent_toplevel()
Label2.set_lock_pos_to_data(True)
Label2.set_pos((5,0))

B1.set_pos((0.4, 0.4))

B1.set_parent_auto()

B1.set_lock_pos_to_data(True)
B1.set_pos((-5, 0.05))
117 changes: 75 additions & 42 deletions pyKst/pykst.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,14 +610,14 @@ def ellipse(self, name):
"""
return Ellipse(self, name=name, new=False)

def new_line(self,pos=(0.1,0.1),length=0.1,rot=0,
def new_line(self,start=(0,0),end = (1,1),
stroke_style=1,stroke_width=1,stroke_brush_color="black",
stroke_brush_style=1,stroke_cap_style=1, name="") :
""" Create a New Line in kst.
See :class:`Line`
"""
return Line(self,pos, length, rot, stroke_style, stroke_width,
return Line(self,start,end, stroke_style, stroke_width,
stroke_brush_color, stroke_brush_style, stroke_cap_style, name)

def line(self, name):
Expand All @@ -627,15 +627,15 @@ def line(self, name):
"""
return Line(self, name=name, new=False)

def new_arrow(self,pos=(0.1,0.1), length=0.1, rot=0,
def new_arrow(self,start=(0,0),end = (1,1),
arror_at_start = False, arrow_at_end = True, arrow_size = 12.0,
stroke_style=1, stroke_width=1, stroke_brush_color="black",
stroke_brush_style=1, stroke_cap_style=1, name="") :
""" Create a New Arrow in kst.
See :class:`Arrow`
"""
return Arrow(self,pos, length, rot, arror_at_start, arrow_at_end, arrow_size,
return Arrow(self,start,end, arror_at_start, arrow_at_end, arrow_size,
stroke_style, stroke_width, stroke_brush_color, stroke_brush_style,
stroke_cap_style, name)

Expand Down Expand Up @@ -2342,9 +2342,9 @@ def set_fixed_aspect_ratio(self, fixed=True):
view item dialog in kst.
"""
if fixed == True:
self.client.send_si(self.handle, b2str("checkFixAspectRatio()"))
self.client.send_si(self.handle, b2str("lockAspectRatio(True)"))
else:
self.client.send_si(self.handle, b2str("uncheckFixAspectRatio()"))
self.client.send_si(self.handle, b2str("lockAspectRatio(False)"))

def position(self):
x = str(self.client.send_si(self.handle, "position()"))
Expand All @@ -2363,17 +2363,17 @@ def dimensions(self):
def set_pos(self,pos):
""" Set the center position of the item.
:param pos: a 2 element tuple ``(x,y)`` specifying the position. The Top Left is (0,0).
The Bottom Right is (1,1)
:param pos: a 2 element tuple ``(x,y)`` specifying the position.
The Top Left of the parent is (0,0).
The Bottom Right of the parent is (1,1)
This is equivalent to setting Dimensions>Position within a view
item dialog in kst.
"""
x,y = pos

self.client.send("beginEdit("+self.handle+")")
self.client.send("setPosX("+b2str(x)+")")
self.client.send("setPosY("+b2str(y)+")")
self.client.send("setPos("+b2str(x)+","+b2str(y)+")")
#self.client.send("setPosX("+b2str(x)+")")
#self.client.send("setPosY("+b2str(y)+")")
self.client.send("endEdit()")

def set_size(self,size):
Expand All @@ -2390,10 +2390,25 @@ def set_size(self,size):
"""
w,h = size
self.client.send("beginEdit("+self.handle+")")
self.client.send("setGeoX("+b2str(w)+")")
self.client.send("setGeoY("+b2str(h)+")")
self.client.send("setSize("+b2str(w)+","+b2str(h)+")")
self.client.send("endEdit()")

def set_lock_pos_to_data(self, lock=True):
"""
if lock is True, and the item is in a plot, then the position of the item
will be locked to the data coordinates in the plot. The item will move with
zooming and scrolling.
If lock is False, or the item is not in a plot, then the item will be fixed
to the geometry of the window, and zooming/scrolling will not change its
position.
"""
if lock==True:
self.client.send_si(self.handle, "setLockPosToData(True)")
else:
self.client.send_si(self.handle, "setLockPosToData(False)")

def set_parent_auto(self):
"""
Set the parent of the viewitem to an existing view item which fully contains it.
Expand Down Expand Up @@ -2834,8 +2849,7 @@ def set_diameter(self,diameter):
The width of the window is 1.0.
"""
self.client.send_si(self.handle,"setGeoX("+b2str(diameter)+")")

self.client.send_si(self.handle,"setSize("+b2str(diameter)+","+b2str(diameter)+")")

class Ellipse(ViewItem) :
""" A floating ellipse inside kst.
Expand Down Expand Up @@ -2915,9 +2929,12 @@ def getList(cls,client):
class Line(ViewItem) :
""" A floating line inside kst.
:param pos: a 2 element tuple ``(x,y)`` specifying the position of the
center of the line.
``(0,0)`` is top left. ``(1,1)`` is bottom right.
:param start: a 2 element tuple ``(x,y)`` specifying the position of the
start of the line.
``(0,0)`` is top left of the window, and ``(1,1)`` is bottom right.
:param end: a 2 element tuple ``(x,y)`` specifying the position of the
end of the line.
``(0,0)`` is top left of the window, and ``(1,1)`` is bottom right.
:param length: The length of the line. 1 is the width of the window.
:param rot: rotation of the line in degrees.
:param stroke_style: see set_stroke_style
Expand All @@ -2938,10 +2955,10 @@ class Line(ViewItem) :
import pykst as kst
client = kst.Client()
...
Ln = client.new_line((0.25, 0.25), 0.2, rot=15)
Ln = client.new_line((0.25, 0.25), (0.5, 0.5))
"""
def __init__(self,client,pos=(0.1,0.1),length=0.1,rot=0,
def __init__(self,client,start=(0,0),end=(1,1),
stroke_style=1,stroke_width=1,stroke_brush_color="black",
stroke_brush_style=1,stroke_cap_style=1, name="", new=True) :
ViewItem.__init__(self,client)
Expand All @@ -2952,9 +2969,7 @@ def __init__(self,client,pos=(0.1,0.1),length=0.1,rot=0,

self.handle.remove(0,self.handle.indexOf("ing ")+4)

self.set_pos(pos)
self.set_length(length)
self.set_rotation(rot)
self.set_endpoints(start, end)

self.set_stroke_brush_color(stroke_brush_color)
self.set_stroke_style(stroke_style)
Expand All @@ -2981,10 +2996,20 @@ def getList(cls,client):
def set_length(self, length):
""" set the length of the line.
The width of the window is 1.0.
The length, between 0 and 1, is as a fraction of the width of the parent item.
"""
self.client.send_si(self.handle,"setGeoX("+b2str(length)+")")
self.client.send_si(self.handle,"setSize("+b2str(length)+","+b2str(length)+")")

def set_endpoints(self, start = (0,0), end = (1,1)) :
""" set the endpoints of the line.
If lock_pos_to_data has been set True, and the item parent is a plot, then the coordinates are
in terms the data's coordinates. Otherwise, the coordinates, between 0 and 1, are relative to
the dimensions of the parent object.
"""
x1,y1 = start
x2,y2 = end
self.client.send_si(self.handle, "setLineEndpoints("+b2str(x1)+","+b2str(y1)+","+b2str(x2)+","+b2str(y2)+")")

class Arrow(ViewItem) :
""" A floating arrow inside kst.
Expand Down Expand Up @@ -3017,7 +3042,7 @@ class Arrow(ViewItem) :
Ln = client.new_arrow((0.25, 0.25), 0.2, rot=15, arror_at_start=True)
"""
def __init__(self,client,pos=(0.1,0.1), length=0.1, rot=0,
def __init__(self,client,start=(0,0),end = (1,1),
arror_at_start = False, arrow_at_end = True, arrow_size = 12.0,
stroke_style=1, stroke_width=1, stroke_brush_color="black",
stroke_brush_style=1, stroke_cap_style=1, name="", new=True) :
Expand All @@ -3028,9 +3053,10 @@ def __init__(self,client,pos=(0.1,0.1), length=0.1, rot=0,
self.handle=self.client.send("endEdit()")
self.handle.remove(0,self.handle.indexOf("ing ")+4)

self.set_pos(pos)
self.set_length(length)
self.set_rotation(rot)
self.set_endpoints(start,end)
#self.set_pos(pos)
#self.set_length(length)
#self.set_rotation(rot)

self.set_stroke_brush_color(stroke_brush_color)
self.set_stroke_style(stroke_style)
Expand Down Expand Up @@ -3067,7 +3093,18 @@ def set_length(self, length):
The width of the window is 1.0.
"""
self.client.send_si(self.handle,"setGeoX("+b2str(length)+")")
self.client.send_si(self.handle,"setSize("+b2str(length)+","+b2str(length)+")")

def set_endpoints(self, start = (0,0), end = (1,1)) :
""" set the endpoints of the arrow.
If lock_pos_to_data has been set True, and the item parent is a plot, then the coordinates are
in terms the data's coordinates. Otherwise, the coordinates, between 0 and 1, are relative to
the dimensions of the parent object.
"""
x1,y1 = start
x2,y2 = end
self.client.send_si(self.handle, "setLineEndpoints("+b2str(x1)+","+b2str(y1)+","+b2str(x2)+","+b2str(y2)+")")

@classmethod
def getList(cls,client):
Expand Down Expand Up @@ -3129,7 +3166,7 @@ def set_width(self, width):
The width of the window is 1.0.
"""
self.client.send_si(self.handle,"setGeoX("+b2str(width)+")")
self.client.send_si(self.handle,"setSize("+b2str(width)+")")


def set_picture(self,pic):
Expand Down Expand Up @@ -3197,7 +3234,7 @@ def set_width(self, width):
The width of the window is 1.0.
"""
self.client.send_si(self.handle,"setGeoX("+b2str(width)+")")
self.client.send_si(self.handle,"setSize("+b2str(width)+")")

@classmethod
def getList(cls,client):
Expand Down Expand Up @@ -3276,8 +3313,8 @@ def __init__(self,client,pos=(0,0),size=(0,0),rot=0,

self.handle.remove(0,self.handle.indexOf("ing ")+4)
if (size != (0,0)):
self.set_pos(pos)
self.set_size(size)
self.set_pos(pos)

self.set_global_font(font_size = font_size)
self.set_fixed_aspect_ratio(fix_aspect)
Expand Down Expand Up @@ -3512,10 +3549,8 @@ class Button(ViewItem) :
def __init__(self,client,text,socket,posX=0.1,posY=0.1,sizeX=0.1,sizeY=0.1,rot=0) :
ViewItem.__init__(self,client)
self.client.send("newButton()")
self.client.send("setPosX("+b2str(posX)+")")
self.client.send("setPosY("+b2str(posY)+")")
self.client.send("setGeoX("+b2str(sizeX)+")")
self.client.send("setGeoY("+b2str(sizeY)+")")
self.client.send("setPos("+b2str(posX)+","+b2str(posY)+")")
self.client.send("setSize("+b2str(sizeX)+","+b2str(sizeY)+")")
self.client.send("setText("+b2str(text)+")")
self.client.send("setRotation("+b2str(rot)+")")
self.handle=self.client.send("endEdit()")
Expand Down Expand Up @@ -3543,10 +3578,8 @@ class LineEdit(ViewItem) :
def __init__(self,client,text,socket,posX=0.1,posY=0.1,sizeX=0.1,sizeY=0.1,rot=0) :
ViewItem.__init__(self,client)
self.client.send("newLineEdit()")
self.client.send("setPosX("+b2str(posX)+")")
self.client.send("setPosY("+b2str(posY)+")")
self.client.send("setGeoX("+b2str(sizeX)+")")
self.client.send("setGeoY("+b2str(sizeY)+")")
self.client.send("setPos("+b2str(posX)+","+b2str(posY)+")")
self.client.send("setSize("+b2str(sizeX)+","+b2str(sizeY)+")")
self.client.send("setText("+b2str(text)+")")
self.client.send("setRotation("+b2str(rot)+")")
self.handle=self.client.send("endEdit()")
Expand Down
1 change: 1 addition & 0 deletions src/libkst/builtinprimitives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace Kst {
new DataScalarFactory();
new VScalarFactory();
new StringFactory();
new DataStringFactory();
new GeneratedMatrixFactory();
new EditableMatrixFactory();
new DataMatrixFactory();
Expand Down
6 changes: 5 additions & 1 deletion src/libkst/datastring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ void DataString::change(DataSourcePtr in_file, const QString &in_field) {

_field = in_field;
setDataSource(in_file);

registerChange();
}

void DataString::changeFile(DataSourcePtr in_file) {
Expand All @@ -99,6 +101,8 @@ void DataString::changeFile(DataSourcePtr in_file) {
Debug::self()->log(tr("Data file for string %1 was not opened.").arg(Name()), Debug::Warning);
}
setDataSource(in_file);

registerChange();
}


Expand All @@ -109,7 +113,7 @@ void DataString::save(QXmlStreamWriter &s) {
saveFilename(s);
s.writeAttribute("field", _field);

saveNameInfo(s, XNUM);
saveNameInfo(s, TNUM);
s.writeEndElement();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libkst/datastring.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class KSTCORE_EXPORT DataString : public String, public DataPrimitive
void change(DataSourcePtr file, const QString &field);
void changeFile(DataSourcePtr file);

/** Save scalar information */
/** Save data string to kst session file */
virtual void save(QXmlStreamWriter &s);

virtual QString descriptionTip() const;
Expand Down
2 changes: 1 addition & 1 deletion src/libkst/string_kst.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class KSTCORE_EXPORT String : public Primitive

virtual ~String();
/** Save information */
void save(QXmlStreamWriter &s);
virtual void save(QXmlStreamWriter &s);

String& operator=(const QString& v);
String& operator=(const char *v);
Expand Down
Loading