Showing with 184 additions and 7 deletions.
  1. +68 −1 pyKst/pykst.py
  2. +7 −0 src/libkstapp/debugdialog.cpp
  3. +1 −0 src/libkstapp/debugdialog.h
  4. +30 −5 src/libkstapp/debugdialog.ui
  5. +0 −1 src/libkstapp/logwidget.cpp
  6. +75 −0 src/libkstapp/scriptserver.cpp
  7. +3 −0 src/libkstapp/scriptserver.h
69 changes: 68 additions & 1 deletion pyKst/pykst.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,74 @@ def plot(self, name):
"""
return Plot(self, name = name, new=False)


def set_datasource_option(self, option, value, filename, data_source="Ascii File"):
""" Sets the value of a data source configuration option.
:param option: the name of the option - eg ""Data Start"
:param value: True or False
:param filename: the name of the file or 0 to set global default
:param data_source: the type of data source
Examples:
Tell kst that trial1.csv is a file with the field names in row 1 and units in row 2::
import pykst as kst
client = kst.Client()
client.set_datasource_option("Column Delimiter", ",", "trial1.csv")
client.set_datasource_option("Column Type", 2, "trial1.csv")
client.set_datasource_option("Data Start", 3-1, "trial1.csv")
client.set_datasource_option("Fields Line", 1-1, "trial1.csv")
client.set_datasource_option("Read Fields", True, "trial1.csv")
client.set_datasource_option("Units Line", 2-1, "trial1.csv")
client.set_datasource_option("Read Units", True, "trial1.csv")
Configuration options supported by the ASCII data source (default) are::
"ASCII Time format"
"Column Delimiter"
"Column Type"
"Column Width"
"Column Width is const"
"Comment Delimiters"
"Data Rate for index"
"Data Start"
"Default INDEX Interpretation"
"Fields Line"
"Filename Pattern"
"Index"
"Limit file buffer size"
"NaN value"
"Read Fields"
"Read Units"
"Size of limited file buffer"
"Units Line"
"Use Dot"
"Use threads when parsing Ascii data"
"date/time offset"
"relative offset"
"updateType"
"use an explicit date/time offset"
"use file time/date as offset"
"use relative file time offset"
"""

if (filename == 0):
filename = "$DEFAULT"

if isinstance(value, bool):
self.send("setDatasourceBoolConfig("+data_source+","+filename+","+option+","+b2str(value)+")")
elif isinstance(value, int):
self.send("setDatasourceIntConfig("+data_source+","+filename+","+option+","+str(value)+")")
else:
v = value
v.replace(',', '`')
self.send("setDatasourceStringConfig("+data_source+","+filename+","+option+","+str(v)+")")



class NamedObject:
""" Convenience class. You should not use it directly."""
def __init__(self,client):
Expand Down
7 changes: 7 additions & 0 deletions src/libkstapp/debugdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ DebugDialog::DebugDialog(QWidget *parent)
connect(_showNotice, SIGNAL(toggled(bool)), _log, SLOT(setShowNotice(bool)));
connect(_showTrace, SIGNAL(toggled(bool)), _log, SLOT(setShowTrace(bool)));

connect(_clearDSSettings, SIGNAL(clicked()), this, SLOT(clearDSSettings()));

if (!Debug::self()->kstRevision().isEmpty())
_buildInfo->setText(tr("<h1>Kst</h1> Version %1 (%2)").arg(KSTVERSION).arg(Debug::self()->kstRevision()));
else
Expand Down Expand Up @@ -93,6 +95,11 @@ void DebugDialog::show() {
QDialog::show();
}

void DebugDialog::clearDSSettings() {
DataSourcePluginManager::settingsObject().clear();
}


}

// vim: ts=2 sw=2 et
1 change: 1 addition & 0 deletions src/libkstapp/debugdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class DebugDialog : public QDialog, Ui::DebugDialog
public Q_SLOTS:
void clear();
void show();
void clearDSSettings();

protected:
bool event(QEvent *e);
Expand Down
35 changes: 30 additions & 5 deletions src/libkstapp/debugdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,23 @@
<item>
<widget class="QTabWidget" name="_tabs">
<property name="currentIndex">
<number>1</number>
<number>2</number>
</property>
<widget class="QWidget" name="_buildInfoTab">
<attribute name="title">
<string>Build Information</string>
</attribute>
<layout class="QGridLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
Expand Down Expand Up @@ -173,7 +182,16 @@
<string>Data Sources</string>
</attribute>
<layout class="QGridLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
Expand Down Expand Up @@ -202,6 +220,13 @@
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="_clearDSSettings">
<property name="text">
<string>Clear Datasource Settings</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
Expand Down Expand Up @@ -243,8 +268,8 @@
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
<x>591</x>
<y>405</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
Expand Down
1 change: 0 additions & 1 deletion src/libkstapp/logwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ void LogWidget::setShowTrace(bool show) {
setShowLevel(Debug::Trace, show);
}


void LogWidget::regenerate() {
clear();
const QList<Debug::LogMessage> messages = Debug::self()->messages();
Expand Down
75 changes: 75 additions & 0 deletions src/libkstapp/scriptserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
#include "dialog.h"
#include "editablematrix.h"

#include "datasourcepluginmanager.h"

#include <updatemanager.h>

#include <QLocalSocket>
Expand Down Expand Up @@ -201,6 +203,10 @@ ScriptServer::ScriptServer(ObjectStore *obj) : _server(new QLocalServer(this)),
_fnMap.insert("fileOpen()", &ScriptServer::fileOpen);
_fnMap.insert("fileSave()", &ScriptServer::fileSave);

_fnMap.insert("setDatasourceBoolConfig()", &ScriptServer::setDatasourceBoolConfig);
_fnMap.insert("setDatasourceIntConfig()", &ScriptServer::setDatasourceIntConfig);
_fnMap.insert("setDatasourceStringConfig()", &ScriptServer::setDatasourceStringConfig);

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

#if 0
Expand Down Expand Up @@ -975,5 +981,74 @@ QByteArray ScriptServer::cleanupLayout(QByteArray&command, QLocalSocket* s,Objec
return handleResponse("Done",s);
}

/*** Interface for changing datasource configuration settings ***/
QByteArray ScriptServer::setDatasourceBoolConfig(QByteArray& command, QLocalSocket* s, ObjectStore*) {
QStringList args = ScriptInterface::getArgs(command);
if (args.length()==4) {
QString ds_type = args[0]; // eg "Ascii File"
QString filename = args[1];
QString setting = args[2];
bool value = (args[3].trimmed().toLower() == "true");
bool set_default = (filename == "$DEFAULT");

DataSourcePluginManager::settingsObject().beginGroup(ds_type);
if (!set_default) {
DataSourcePluginManager::settingsObject().beginGroup(filename);
}
DataSourcePluginManager::settingsObject().setValue(setting, value);
if (!set_default) {
DataSourcePluginManager::settingsObject().endGroup();
}
DataSourcePluginManager::settingsObject().endGroup();
}
return handleResponse("Done",s);

}

QByteArray ScriptServer::setDatasourceIntConfig(QByteArray& command, QLocalSocket* s, ObjectStore*) {
QStringList args = ScriptInterface::getArgs(command);
if (args.length()==4) {
QString ds_type = args[0]; // eg "Ascii File"
QString filename = args[1];
QString setting = args[2];
int value = args[3].toInt();
bool set_default = (filename == "$DEFAULT");

DataSourcePluginManager::settingsObject().beginGroup(ds_type);
if (!set_default) {
DataSourcePluginManager::settingsObject().beginGroup(filename);
}
DataSourcePluginManager::settingsObject().setValue(setting, value);
if (!set_default) {
DataSourcePluginManager::settingsObject().endGroup();
}
DataSourcePluginManager::settingsObject().endGroup();
}
return handleResponse("Done",s);

}

QByteArray ScriptServer::setDatasourceStringConfig(QByteArray& command, QLocalSocket* s, ObjectStore*) {
QStringList args = ScriptInterface::getArgs(command);
if (args.length()==4) {
QString ds_type = args[0]; // eg "Ascii File"
QString filename = args[1];
QString setting = args[2];
QString value = args[3].replace('`', ','); // , is replaced with `. switch back.
bool set_default = (filename == "$DEFAULT");

DataSourcePluginManager::settingsObject().beginGroup(ds_type);
if (!set_default) {
DataSourcePluginManager::settingsObject().beginGroup(filename);
}
DataSourcePluginManager::settingsObject().setValue(setting, value);
if (!set_default) {
DataSourcePluginManager::settingsObject().endGroup();
}
DataSourcePluginManager::settingsObject().endGroup();
}
return handleResponse("Done",s);

}

}
3 changes: 3 additions & 0 deletions src/libkstapp/scriptserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ public slots:

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

QByteArray setDatasourceBoolConfig(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
QByteArray setDatasourceIntConfig(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
QByteArray setDatasourceStringConfig(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
};


Expand Down