4 changes: 4 additions & 0 deletions pyKst/demo/plot_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@

client.cleanup_layout(3)

client.set_tab_text("First")

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

# manual grid
client.new_tab()
client.set_tab_text("Second")

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))
Expand Down
6 changes: 6 additions & 0 deletions pyKst/pykst.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ def set_tab(self,tab):
"""
self.send("setTab("+b2str(tab)+")")

def set_tab_text(self,new_name):
""" Set the text of the current tab.
"""
self.send("renameTab("+new_name+")")

def cleanup_layout(self, columns="Auto"):
""" Cleanup layout in the current tab.
Expand Down
2 changes: 1 addition & 1 deletion src/libkst/datasourcepluginmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class KSTCORE_EXPORT DataSourcePluginManager
//static QStringList matrixListForSource(const QString& filename, const QString& type = QString(), QString *outType = 0L, bool *complete = 0L);
static QStringList scalarListForSource(const QString& filename, const QString& type = QString(), QString *outType = 0L, bool *complete = 0L);
static QStringList stringListForSource(const QString& filename, const QString& type = QString(), QString *outType = 0L, bool *complete = 0L);
static QSettings& settingsObject();


private:
static QSettings& settingsObject();
static QMap<QString,QString> url_map;
static QString obtainFile(const QString& source);

Expand Down
4 changes: 2 additions & 2 deletions src/libkst/scriptinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class KSTCORE_EXPORT ScriptInterface : public QObject
static QString doNamedObjectCommand(QString command, NamedObject *n);
static QString doObjectCommand(QString command, ObjectPtr ob);

QStringList getArgs(const QString &command);
QString getArg(const QString &command);
static QStringList getArgs(const QString &command);
static QString getArg(const QString &command);

};

Expand Down
102 changes: 99 additions & 3 deletions src/libkstapp/commandlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
#include <config.h>

#include "commandlineparser.h"
#include "datasource.h"
//#include "datasource.h"
#include "datasourcepluginmanager.h"
#include "objectstore.h"
#include "colorsequence.h"
#ifdef KST_HAVE_REVISION_H
Expand Down Expand Up @@ -69,7 +70,18 @@ namespace Kst {
" -n <numframes> default: 'end' reads to end of file\n"
" -s <frames per sample> default: 0 (read every sample)\n"
" -a apply averaging filter: requires -s\n\n"

"Ascii File Options - for ascii files only: these are all stick\n"
" --asciiDataStart <Line> Data starts here. Files start at line 1.\n"
" --asciiFieldNames <Line> Field names are in this row.\n"
" --asciiNoFieldNames Fields are named for their data column\n"
" --asciiReadUnits <Line> Read units from line <Line>\n"
" --asciiNoUnits Do not read units\n"
" --asciiSpaceDelim Columns are Space/tab delimited\n"
" --asciiDelim <char> Columns are dlimited with <char>\n"
" --asciiFixedWidth <w> Columns have width <w>\n"
" --asciiNoFixedWidth Columns are delimited, not fixed width\n"
" --asciiDecimalDot Use a . as a decimal separator (ie, 10.1)\n"
" --asciiDecimalComma Use a , as a decimal separator (ie, 10,1)\n"
"Position:\n"
" -P <plot name>: Place curves in one plot.\n"
" -A Place future curves in individual plots.\n"
Expand Down Expand Up @@ -151,7 +163,12 @@ CommandLineParser::CommandLineParser(Document *doc, MainWindow* mw) :
_useLines(true), _usePoints(false), _overrideStyle(false), _sampleRate(1.0),
_numFrames(-1), _startFrame(-1),
_skip(0), _plotName(), _errorField(), _fileName(), _xField(QString("INDEX")),
_pngFile(QString()), _printFile(QString()), _landscape(false), _plotItem(0), _num_cols(0) {
_pngFile(QString()), _printFile(QString()), _landscape(false), _plotItem(0),
_num_cols(0), _asciiFirstLine(-1), _asciiFieldLine(-1), _asciiNoFieldNames(false),
_asciiUnitsLine(-1), _asciiNoUnits(false), _asciiSpaceDelim(false),
_asciiDelim('\0'), _asciiFixedWidth(-1), _asciiNoFixedWidth(false),
_asciiDecimalDot(false), _asciiDecimalComma(false)
{

Q_ASSERT(QCoreApplication::instance());
_arguments = QCoreApplication::instance()->arguments();
Expand Down Expand Up @@ -514,6 +531,15 @@ bool CommandLineParser::processCommandLine(bool *ok) {
DataVectorPtr xv = createOrFindDataVector(_xField, ds);
DataVectorPtr yv = createOrFindDataVector(field, ds);

/*
DataSourcePluginManager::settingsObject().beginGroup("ASCII file");
DataSourcePluginManager::settingsObject().beginGroup(file);
qDebug() << "ds settings: " << file << DataSourcePluginManager::settingsObject().allKeys();
qDebug() << "Use Dot: " << file << DataSourcePluginManager::settingsObject().value("Use Dot");
DataSourcePluginManager::settingsObject().endGroup();
DataSourcePluginManager::settingsObject().endGroup();
*/

DataVectorPtr ev;
if (!_errorField.isEmpty()) {
ev = createOrFindDataVector(_errorField, ds);
Expand Down Expand Up @@ -659,6 +685,30 @@ bool CommandLineParser::processCommandLine(bool *ok) {
}
} else if (arg == "-F") {
*ok = _setStringArg(_document->objectStore()->override.fileName, tr("Usage: -F <datafile>\n"));
} else if (arg == "--asciiDataStart") {
*ok = _setIntArg(&_asciiFirstLine, tr("Usage: --asciiDataStart <Line Number>\n"));
} else if (arg == "--asciiFieldNames") {
*ok = _setIntArg(&_asciiFieldLine, tr("Usage: --asciiFieldNames <Line Number>\n"));
} else if (arg == "--asciiNoFieldNames") {
_asciiNoFieldNames = true;
} else if (arg == "--asciiReadUnits") {
*ok = _setIntArg(&_asciiUnitsLine, tr("Usage: --asciiReadUnits <Line Number>\n"));
} else if (arg == "--asciiNoUnits") {
_asciiNoUnits = true;
} else if (arg == "--asciiSpaceDelim") {
_asciiSpaceDelim = true;
} else if (arg == "--asciiDelim") {
QString arg;
*ok = _setStringArg(arg, tr("Usage: --asciiDelim <delimiter>\n"));
_asciiDelim = arg.at(0).toAscii();
} else if (arg == "--asciiFixedWidth") {
*ok = _setIntArg(&_asciiFixedWidth, tr("Usage: --asciiFixedWidth <width>\n"));
} else if (arg == "--asciiNoFixedWidth") {
_asciiNoFixedWidth = true;
} else if (arg == "--asciiDecimalDot") {
_asciiDecimalDot = true;
} else if (arg == "--asciiDecimalComma") {
_asciiDecimalComma = true;
} else if (arg == "--png") {
*ok = _setStringArg(_pngFile, tr("Usage: --png <filename>\n"));
#ifndef KST_NO_PRINTER
Expand All @@ -684,6 +734,52 @@ bool CommandLineParser::processCommandLine(bool *ok) {
new_fileList = false;
}
_fileNames.append(arg);
if (!arg.endsWith(".kst")) {
DataSourcePluginManager::settingsObject().beginGroup("ASCII file");
DataSourcePluginManager::settingsObject().beginGroup(arg);

if (_asciiFirstLine>0) {
DataSourcePluginManager::settingsObject().setValue("Data Start", _asciiFirstLine-1);
}
if (_asciiFieldLine>0) {
DataSourcePluginManager::settingsObject().setValue("Fields Line", _asciiFieldLine-1);
DataSourcePluginManager::settingsObject().setValue("Read Fields", true);
}
if (_asciiNoFieldNames) {
DataSourcePluginManager::settingsObject().setValue("Read Fields", false);
}
if (_asciiUnitsLine>0) {
DataSourcePluginManager::settingsObject().setValue("Units Line", _asciiUnitsLine-1);
DataSourcePluginManager::settingsObject().setValue("Read Units", true);
}
if (_asciiNoUnits) {
DataSourcePluginManager::settingsObject().setValue("Read Units", false);
}
if (_asciiDelim != '\0') {
DataSourcePluginManager::settingsObject().setValue("Column Delimiter", QString(_asciiDelim));
DataSourcePluginManager::settingsObject().setValue("Column Type", 2); //FIXME: AsciiSourceConfig::ColumnType::Custom
}
if (_asciiSpaceDelim) {
DataSourcePluginManager::settingsObject().setValue("Column Type", 0); //FIXME: AsciiSourceConfig::ColumnType::Whitespace
}
if (_asciiFixedWidth>0) {
DataSourcePluginManager::settingsObject().setValue("Column Type", 1); //FIXME: AsciiSourceConfig::ColumnType::Fixed
DataSourcePluginManager::settingsObject().setValue("Column Width", _asciiFixedWidth);
DataSourcePluginManager::settingsObject().setValue("Column Width is const", true);
}
if (_asciiNoFixedWidth) {
DataSourcePluginManager::settingsObject().setValue("Column Width is const", false);
}
if (_asciiDecimalDot) {
DataSourcePluginManager::settingsObject().setValue("Use Dot", true);
}
if (_asciiDecimalComma) {
DataSourcePluginManager::settingsObject().setValue("Use Dot", false);
}

DataSourcePluginManager::settingsObject().endGroup();
DataSourcePluginManager::settingsObject().endGroup();
}

if (!arg.endsWith(".kst") && _arguments.count() == 0) {
// try loading data without user interaction
Expand Down
12 changes: 12 additions & 0 deletions src/libkstapp/commandlineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ class CommandLineParser:QObject

int _num_cols;

int _asciiFirstLine;
int _asciiFieldLine;
bool _asciiNoFieldNames;
int _asciiUnitsLine;
bool _asciiNoUnits;
bool _asciiSpaceDelim;
char _asciiDelim;
int _asciiFixedWidth;
bool _asciiNoFixedWidth;
bool _asciiDecimalDot;
bool _asciiDecimalComma;

bool _setIntArg(int *arg, QString Message, bool accept_end=false);
bool _setDoubleArg(double *arg, QString Message);
bool _setStringArg(QString &arg, QString Message);
Expand Down
9 changes: 9 additions & 0 deletions src/libkstapp/scriptserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ ScriptServer::ScriptServer(ObjectStore *obj) : _server(new QLocalServer(this)),
_fnMap.insert("tabCount()",&ScriptServer::tabCount);
_fnMap.insert("newTab()",&ScriptServer::newTab);
_fnMap.insert("setTab()",&ScriptServer::setTab);
_fnMap.insert("renameTab()",&ScriptServer::renameTab);
_fnMap.insert("screenBack()",&ScriptServer::screenBack);
_fnMap.insert("screenForward()",&ScriptServer::screenForward);
_fnMap.insert("countFromEnd()",&ScriptServer::countFromEnd);
Expand Down Expand Up @@ -889,6 +890,14 @@ QByteArray ScriptServer::setTab(QByteArray&command, QLocalSocket* s,ObjectStore*
return handleResponse("Done",s);
}

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

int index = kstApp->mainWindow()->tabWidget()->currentIndex();
QString new_name = ScriptInterface::getArg(command);
kstApp->mainWindow()->tabWidget()->setTabText(index, new_name);
return handleResponse("Done",s);
}

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

kstApp->mainWindow()->_backAct->trigger();
Expand Down
1 change: 1 addition & 0 deletions src/libkstapp/scriptserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public slots:
QByteArray tabCount(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
QByteArray newTab(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
QByteArray setTab(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
QByteArray renameTab(QByteArray& command, QLocalSocket* s,ObjectStore*_store);

QByteArray screenBack(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
QByteArray screenForward(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
Expand Down