Revision 1250641

Go back to digest for 4th September 2011

Features in Educational

Joshua Netterfield committed changes in /branches/work/kst/portto4/kst:

Adds scripting functionality to Kst.
PyKst scripts can control and share data with a kst session.

ABOUT PYKST
===============================
(The following information is also available inside the svn tree at pyKst/README)

Currently python scripting is implemented. If you are interested in adding Kst support to
other languages, see below.

PyKst (available inside the svn tree at pyKst) is, at the time of writing, not stable
enough for serious use. For the time being, do not write scripts with it except to
test and to send feedback.

Scripting does not introduce any new dependencies to Kst, but PyKst will not run
without certain libraries.

PyKst is tested on Python 2.6 and does not work with Python 3.x.

PyKst needs NumPy 1.6 and does not work with NumPy 1.5. If it is very important
that it should work with NumPy 1.5, modify pykstpp.py to work with the old
API (and submit these changes to kst!!) or send an email to the devel list.

PyKst currently is not portable as pykstpp.py contains C++ code which is
compiled upon first use. It should, instead, create a dynamic library at
Kst compile time. Also, it does not detect the location of the Qt library or
include files, so to get it to compile you might have to modify pykstpp.py.

Please email the Kst list with feature requests and bug reports. I am not able to work on
scripting as much as I have had the chance to do in the past two weeks because of
high school, but can certainly try to help with relatively minor fixes.

The fastest way to get started is to take a look at the examples inside the svn tree
at pyKst/

Documentation is available for now at hen.astro.utoronto.ca/pyKst or inside the
svn tree at pyKst/doc.

DEVELOPPER INFORMATION
===============================
(The following information is also available inside the svn tree at README.kstScript)

Kst implements a client-server interface for scripting. Scripts interacts with a running kst session.

This server is implemented in scriptserver.cpp.

Upon receiving a socket message from QLocalSocket, ScriptServer parses it. ScriptServer implements a map
between command strings and ScriptServer member functions.

These commands include "newVector()", "getPlotList()", etc.

To edit a vector, you would call "beginEdit(Vector Name)". This would open an "interface". One interface
is DialogScriptInterface which simply allows a script to control a hidden dialog. Where speed is important,
other (hard-coded) interfaces are created. To close the interface, one would call "endEdit()".

ScriptServer also implements a very minimalistic language providing:

- if statements in the form:

if(...)
fi()

- variables in the form:
$a=blah
setText($a)

- macros in the form:
newMacro(a,d=c)
setText($a)
setColor($d)
endMacro()

Note that 'c' is not a default argument: they initialize a and d so you can run a macro while writing it.
newMacro(...) runs the macro while it is being written. newMacro_(...) does not)

Note that kstScript (that is, the simple language ScriptServer understands) never uses quotes. It is therefore
important that extra spacing is not added. Comments are also not supported. I feel that it is not worth improving
this 'language'. If someone should have time, a port to javascript would certainly be better.

You can use tests/kstcontrol to write kstScript macros. A list of possible commands is shown inside kstcontrol on the
right hand side. To make macros permanent (i.e., load on start of kst) add them to the file "kstScript.txt".
kstcontrol outputs macros you create to stdout on endMacro().

Writing macros is preferred over implementing them directly in a language (say, python) because the underlying API is
not guaranteed to be consistent and macros allow multiple languages to all have similar functionality with better code
reuse.

To get a feel for how they are written, please see kstScript.txt.

To give a language the ability to communicate with kst, implement functions which use QLocalSocket to communicate with
ScriptServer. Refer to pykst whose source is available in pykst/pykst.py and pykst/pykstpp.py.

File Changes

Added 35 files
  • /branches/work/kst/portto4/kst
  •   /pyKst
  •   /README.kstScript
  •   /pyKst/bonjourMonde.py
  •   /pyKst/failsafetm.py
  •   /pyKst/ksnspire.py
  •   /pyKst/kstOwl.py
  •   /pyKst/pykst.py
  •   /pyKst/README
  •   /pyKst/vectors.py
  •   /tests/kstcontrol
  •   /src/images/kstScript.txt
  •   /src/libkstapp/buttonitem.cpp
  •   /src/libkstapp/buttonitem.h
  •   /src/libkstapp/dialogscriptinterface.cpp
  •   /src/libkstapp/dialogscriptinterface.h
  •   /src/libkstapp/labelscriptinterface.cpp
  •   /src/libkstapp/labelscriptinterface.h
  •   /src/libkstapp/lineedititem.cpp
  •   /src/libkstapp/lineedititem.h
  •   /src/libkstapp/scriptinterface.cpp
  •   /src/libkstapp/scriptinterface.h
  •   /src/libkstapp/scriptserver.cpp
  •   /src/libkstapp/scriptserver.h
  •   /src/libkstapp/stringscriptinterface.cpp
  •   /src/libkstapp/stringscriptinterface.h
  •   /src/libkstapp/viewitemscriptinterface.cpp
  •   /src/libkstapp/viewitemscriptinterface.h
  •   /tests/kstcontrol/cwidget.cpp
  •   /tests/kstcontrol/cwidget.h
  •   /tests/kstcontrol/cwidget.ui
  •   /tests/kstcontrol/KstControl.pro
  •   /tests/kstcontrol/KstControl.pro.user
  •   /tests/kstcontrol/KstControl.pro.user.2.2pre5
  •   /tests/kstcontrol/main.cpp
  •   /tests/kstcontrol/Makefile
Modified 94 files
  • /branches/work/kst/portto4/kst
  •   /config.h
  •   /cmake/CMakeLists.txt
  •   /cmake/modules/KstMacros.cmake
  •   /src/images/images.qrc
  •   /src/kst/kst.pro
  •   /src/libkst/coredocument.cpp
  •   /src/libkst/coredocument.h
  •   /src/libkst/datavector.cpp
  •   /src/libkst/datavector.h
  •   /src/libkst/editablevector.cpp
  •   /src/libkst/editablevector.h
  •   /src/libkst/matrix.cpp
  •   /src/libkst/matrix.h
  •   /src/libkst/object.cpp
  •   /src/libkst/object.h
  •   /src/libkst/objectstore.cpp
  •   /src/libkst/vector.cpp
  •   /src/libkst/vector.h
  •   /src/libkst/vectorfactory.cpp
  •   /src/libkstapp/application.cpp
  •   /src/libkstapp/arrowpropertiestab.cpp
  •   /src/libkstapp/axistab.cpp
  •   /src/libkstapp/builtingraphics.cpp
  •   /src/libkstapp/contenttab.cpp
  •   /src/libkstapp/contenttab.h
  •   /src/libkstapp/contenttab.ui
  •   /src/libkstapp/csddialog.cpp
  •   /src/libkstapp/curvedialog.cpp
  •   /src/libkstapp/datadialog.cpp
  •   /src/libkstapp/datadialog.h
  •   /src/libkstapp/datasourcedialog.h
  •   /src/libkstapp/datawizard.cpp
  •   /src/libkstapp/dialog.cpp
  •   /src/libkstapp/dialog.h
  •   /src/libkstapp/dimensionstab.cpp
  •   /src/libkstapp/dimensionstab.ui
  •   /src/libkstapp/editmultiplewidget.cpp
  •   /src/libkstapp/equationdialog.cpp
  •   /src/libkstapp/eventmonitordialog.cpp
  •   /src/libkstapp/exportgraphicsdialog.cpp
  •   /src/libkstapp/filltab.ui
  •   /src/libkstapp/filterfitdialog.cpp
  •   /src/libkstapp/histogramdialog.cpp
  •   /src/libkstapp/imagedialog.cpp
  •   /src/libkstapp/imagetab.ui
  •   /src/libkstapp/labelcreator.cpp
  •   /src/libkstapp/labelcreator.ui
  •   /src/libkstapp/labelpropertiestab.cpp
  •   /src/libkstapp/labelpropertiestab.ui
  •   /src/libkstapp/labelrenderer.h
  •   /src/libkstapp/labeltab.cpp
  •   /src/libkstapp/labeltab.ui
  •   /src/libkstapp/layouttab.cpp
  •   /src/libkstapp/layouttab.ui
  •   /src/libkstapp/legendtab.ui
  •   /src/libkstapp/libkstapp.pro
  •   /src/libkstapp/mainwindow.h
  •   /src/libkstapp/markerstab.cpp
  •   /src/libkstapp/markerstab.ui
  •   /src/libkstapp/matrixdialog.cpp
  •   /src/libkstapp/matrixdialog.h
  •   /src/libkstapp/matrixtab.ui
  •   /src/libkstapp/overridelabeltab.ui
  •   /src/libkstapp/plotaxis.cpp
  •   /src/libkstapp/powerspectrumdialog.cpp
  •   /src/libkstapp/rangetab.cpp
  •   /src/libkstapp/scalardialog.h
  •   /src/libkstapp/scalartab.ui
  •   /src/libkstapp/stringdialog.cpp
  •   /src/libkstapp/stringdialog.h
  •   /src/libkstapp/stroketab.cpp
  •   /src/libkstapp/stroketab.ui
  •   /src/libkstapp/themedialog.ui
  •   /src/libkstapp/vectordialog.cpp
  •   /src/libkstapp/vectordialog.h
  •   /src/libkstapp/vectortab.ui
  •   /src/libkstapp/viewitem.h
  •   /src/libkstapp/viewitemdialog.cpp
  •   /src/libkstapp/viewitemdialog.h
  •   /src/widgets/colorpalette.cpp
  •   /src/widgets/curveappearance.cpp
  •   /src/widgets/curveappearance.ui
  •   /src/widgets/curveplacement.cpp
  •   /src/widgets/curveplacement.ui
  •   /src/widgets/datarange.cpp
  •   /src/widgets/datarange.ui
  •   /src/widgets/datasourceselector.cpp
  •   /src/widgets/fftoptions.cpp
  •   /src/widgets/matrixselector.cpp
  •   /src/widgets/matrixselector.h
  •   /src/widgets/scalarselector.cpp
  •   /src/widgets/stringselector.cpp
  •   /src/widgets/vectorselector.cpp
  •   /cmake/src/kst/CMakeLists.txt
129 files changed in total