[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/kspread/plugins/scripting
From: Sebastian Sauer <mail () dipe ! org>
Date: 2007-11-28 3:12:25
Message-ID: 1196219545.622413.20209.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 742455 by sebsauer:
Added the rpyfunctions.py python script that provides 45 new functions to access the \
R programming environment for data analysis and graphics ( http://www.r-project.org ) \
using the RPy python module ( http://rpy.sourceforge.net ). We support all r.* \
functions Gnumeric knows about now btw :)
FEATURE
M +61 -7 ScriptingFunction.cpp
M +15 -0 ScriptingFunction.h
M +1 -0 scripts/CMakeLists.txt
AM scripts/rpyfunctions.py
M +7 -1 scripts/scripts.rc
M +55 -40 scripts/snippetsdocker.rb
--- trunk/koffice/kspread/plugins/scripting/ScriptingFunction.cpp #742454:742455
@@ -28,6 +28,7 @@
//#include <Doc.h>
//#include <View.h>
#include <Value.h>
+#include <Number.h>
#include <Functions.h>
//#define KROSS_MAIN_EXPORT KDE_EXPORT
@@ -60,13 +61,40 @@
kDebug() << QString("ScriptingFunctionImpl::callback name=%1 \
argcount=%2").arg(funcimpl->m_function->name()).arg(args.count());
+KSpread::FunctionDescription *description = \
KSpread::FunctionRepository::self()->functionInfo( funcimpl->name() ); +kDebug()<<"0 \
==================> name="<<description->name()<<" type="<<description->type(); +
QVariantList list;
- int size = args.size();
+ for(int i = 0; i < args.size(); ++i) {
+ switch( description->param(i).type() ) {
+ case KSpread::KSpread_Int:
+ list << int( args[i].asInteger() );
+ break;
+ case KSpread::KSpread_Float: {
+ list << double( args[i].asFloat() );
+ } break;
+ case KSpread::KSpread_String:
+ list << args[i].asString();
+ break;
+ case KSpread::KSpread_Boolean:
+ list << args[i].asBoolean();
+ break;
+ case KSpread::KSpread_Any:
+ default:
+ list << args[i].asVariant();
+ break;
+ }
+ //kDebug()<<"1 ==================> \
helpText="<<description->param(i).helpText()<<" type="<<description->param(i).type(); \
+ } +
+/*
for(int i = 0; i < size; ++i) {
+kDebug()<<"2 ==================> "<<args[i].asString();
//TODO needs to be more generic!
- list.append( args[i].asString() );
+ //list << args[i].asVariant();
+ list << args[i].asString();
}
-
+*/
funcimpl->m_function->setError( QString() );
funcimpl->m_function->setResult( QVariant() );
@@ -90,9 +118,31 @@
return err;
}
- kDebug() <<"result=" << result.toString();
- return KSpread::Value( result.toString() );
- //return KSpread::Value( result );
+ KSpread::Value resultvalue;
+ switch( description->type() ) {
+ case KSpread::KSpread_Int:
+ resultvalue = KSpread::Value( result.toInt() );
+ break;
+ case KSpread::KSpread_Float:
+ resultvalue = KSpread::Value( (double) result.toDouble() );
+ break;
+ case KSpread::KSpread_String:
+ resultvalue = KSpread::Value( result.toString() );
+ break;
+ case KSpread::KSpread_Boolean:
+ resultvalue = KSpread::Value( result.toBool() );
+ break;
+ case KSpread::KSpread_Any:
+ default:
+ //TODO make more generic
+ //resultvalue = KSpread::Value( result );
+ resultvalue = KSpread::Value( result.toString() );
+ break;
+ }
+
+ //kDebug() <<"result=" << result.toString();
+ //return KSpread::Value( result.toString() );
+ return resultvalue;
}
ScriptingFunctionImpl(ScriptingFunction* function, const QDomElement& \
description) @@ -130,6 +180,7 @@
{
public:
QString name;
+ QString typeName;
int minparam;
int maxparam;
QString comment;
@@ -148,6 +199,7 @@
, d(new Private())
{
kDebug() <<"ScriptingFunction::ScriptingFunction";
+ d->typeName = "String";
d->funcElement = d->document.createElement("Function");
d->helpElement = d->document.createElement("Help");
}
@@ -160,6 +212,8 @@
QString ScriptingFunction::name() const { return d->name; }
void ScriptingFunction::setName(const QString& name) { d->name = name; }
+QString ScriptingFunction::typeName() const { return d->typeName; }
+void ScriptingFunction::setTypeName(const QString& typeName) { d->typeName = \
typeName; } int ScriptingFunction::minParam() const { return d->minparam; }
void ScriptingFunction::setMinParam(int minparam) { d->minparam = minparam; }
int ScriptingFunction::maxParam() const { return d->maxparam; }
@@ -206,7 +260,7 @@
d->funcElement.appendChild(nameelem);
QDomElement typeelem = d->document.createElement("Type");
- typeelem.appendChild( d->document.createTextNode("String") );
+ typeelem.appendChild( d->document.createTextNode(d->typeName) );
d->funcElement.appendChild(typeelem);
QDomElement helpTextElem = d->document.createElement("Text");
--- trunk/koffice/kspread/plugins/scripting/ScriptingFunction.h #742454:742455
@@ -60,6 +60,11 @@
Q_PROPERTY(QString name READ name)
/**
+ * Set the name of the return-type. Could be e.g. "String", "int", "bool" or \
"float". + */
+ Q_PROPERTY(QString typeName READ typeName WRITE setTypeName)
+
+ /**
* Minimum number of parameters the function expects.
*/
Q_PROPERTY(int minparam READ minParam WRITE setMinParam)
@@ -97,6 +102,12 @@
QString name() const;
/// Set the name the function has.
void setName(const QString& name);
+
+ /// \return the name the function has.
+ QString typeName() const;
+ /// Set the name the function has.
+ void setTypeName(const QString& typeName);
+
/// \return the minimum number of parameters the function expects.
int minParam() const;
/// Set the minimum number of parameters the function expects.
@@ -105,18 +116,22 @@
int maxParam() const;
/// Set the maximum number of parameters the function expects.
void setMaxParam(int maxparam);
+
/// \return the comment that describes what the function does.
QString comment() const;
/// Set the comment that describes what the function does.
void setComment(const QString& comment);
+
/// \return the syntax string the function looks like.
QString syntax() const;
/// Set the syntax string the function looks like.
void setSyntax(const QString& syntax);
+
/// \return the error-message if there was an error.
QString error() const;
/// Set the error-message.
void setError(const QString& error = QString());
+
/// \return the result of the function call.
QVariant result() const;
/// Set the result of the function call.
--- trunk/koffice/kspread/plugins/scripting/scripts/CMakeLists.txt #742454:742455
@@ -15,6 +15,7 @@
install(FILES
functions.py
+ rpyfunctions.py
yfinance.py yweather.py
pytime.py pyregexp.py
DESTINATION ${DATA_INSTALL_DIR}/kspread/scripts/functions)
** trunk/koffice/kspread/plugins/scripting/scripts/rpyfunctions.py #property \
svn:executable + *
--- trunk/koffice/kspread/plugins/scripting/scripts/scripts.rc #742454:742455
@@ -50,6 +50,12 @@
<collection name="functions" text="Functions" comment="Scripting formula \
functions"> <script
+ name="rpyfunctions"
+ text="R-Project"
+ comment="Functions for the R programming environment for data analysis \
and graphics" + interpreter="python"
+ file="functions/rpyfunctions.py" />
+ <script
name="yfinance"
text="YFinance"
comment="Yahoo! Finance formula function"
@@ -110,7 +116,7 @@
name="rbsnippets"
text="Ruby Snippets"
comment="Ruby Snippets"
- enabled="false"
+ enabled="true"
interpreter="ruby"
file="docker/snippetsdocker.rb" />
</collection>
--- trunk/koffice/kspread/plugins/scripting/scripts/snippetsdocker.rb #742454:742455
@@ -72,13 +72,18 @@
action.setInterpreter(@interpreterCombo.currentText)
action.setCode(@edit.plainText)
action.trigger()
+ #action.destroyLater()
puts "EXECUTE DONE"
end
end
class Snippet_Informations < Base
def initialize(parent)
- super(parent, "Informations", "Details about the Environment")
+ super(parent, "Informations", "Environment Details")
+
+ ObjectSpace.define_finalizer(self,
+ self.class.method(:finalize).to_proc)
+
end
def slotExecute()
text = "<h3>Ruby</h3><table>"
@@ -100,6 +105,7 @@
text += "<tr><td>" + n + "</td><td>" + ENV[n] + "</td></tr>"
end
text += "</table>"
+
dialog = Qt::Dialog.new(self)
layout = Qt::VBoxLayout.new(dialog)
layout.setMargin(0)
@@ -111,60 +117,69 @@
dialog.resize(560,400)
dialog.exec()
end
+def Snippet_Informations.finalize(id)
+ puts "Object #{id} dying at #{Time.new}"
+end
+
end
end
-class WidgetListBox < Qt::TableWidget
- def initialize(parent)
- super(parent)
- setRowCount(0)
- setColumnCount(1)
- horizontalHeader().hide()
- verticalHeader().hide()
- setSelectionMode(Qt::AbstractItemView::SingleSelection)
- setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff)
- horizontalHeader().setStretchLastSection(true)
- setAlternatingRowColors(true)
- @snippets = {}
- end
- def addItem(snippetClazzName)
- snippet = Snippets.const_get(snippetClazzName).new(self)
- @snippets[snippetClazzName] = snippet #this is a hack which seems to be \
needed to keep the qwidget-instance alive. +class SnippetsWidget < Qt::Widget
- row = rowCount()
- setRowCount(row + 1)
- widget = Qt::Widget.new(self)
- layout = Qt::GridLayout.new(widget)
- layout.setMargin(2)
- layout.setSpacing(0)
- layout.setColumnStretch(0, 1)
- widget.setLayout(layout)
+ class WidgetListBox < Qt::TableWidget
+ def initialize(parent, scriptaction)
+ super(parent)
+ setRowCount(0)
+ setColumnCount(1)
+ horizontalHeader().hide()
+ verticalHeader().hide()
+ setSelectionMode(Qt::AbstractItemView::SingleSelection)
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff)
+ horizontalHeader().setStretchLastSection(true)
+ setAlternatingRowColors(true)
+ @scriptaction = scriptaction
+ @snippets = {}
+ end
+ def scriptAction
+ return @scriptaction
+ end
+ def addItem(snippetClazzName)
+ snippet = Snippets.const_get(snippetClazzName).new(self)
+ @snippets[snippetClazzName] = snippet #this is a hack which seems to be \
needed to keep the qwidget-instance alive.
- caption = snippet.instance_variable_get("@caption")
- layout.addWidget(Qt::Label.new(caption, widget), 0, 0)
+ row = rowCount()
+ setRowCount(row + 1)
+ widget = Qt::Widget.new(self)
+ layout = Qt::GridLayout.new(widget)
+ layout.setMargin(2)
+ layout.setSpacing(0)
+ layout.setColumnStretch(0, 1)
+ widget.setLayout(layout)
- runbtn = Qt::PushButton.new('Run', widget)
- runbtn.setProperty("snippetClazzName", Qt::Variant.new(snippetClazzName))
- connect(runbtn, SIGNAL('clicked()'), snippet, SLOT('slotExecute()'))
- layout.addWidget(runbtn, 0, 1, 2, 1)
+ caption = snippet.instance_variable_get("@caption")
+ layout.addWidget(Qt::Label.new(caption, widget), 0, 0)
- description = snippet.instance_variable_get("@description")
- layout.addWidget(Qt::Label.new("<i>" + description + "</i>", widget), 1, 0)
+ runbtn = Qt::PushButton.new('Run', widget)
+ runbtn.setProperty("snippetClazzName", \
Qt::Variant.new(snippetClazzName)) + connect(runbtn, SIGNAL('clicked()'), \
snippet, SLOT('slotExecute()')) + layout.addWidget(runbtn, 0, 1, 2, 1)
- setCellWidget(row, 0, widget)
- setRowHeight(row, widget.height() + 8)
+ description = snippet.instance_variable_get("@description")
+ layout.addWidget(Qt::Label.new("<i>" + description + "</i>", widget), 1, \
0) +
+ setCellWidget(row, 0, widget)
+ setRowHeight(row, widget.height() + 8)
+ end
end
-end
-class SnippetsWidget < Qt::Widget
- def initialize(parent)
+ def initialize(parent, scriptaction)
super(parent)
layout = Qt::VBoxLayout.new(self)
layout.setMargin(0)
layout.setSpacing(0)
setLayout(layout)
- @listbox = WidgetListBox.new(self)
+ @listbox = WidgetListBox.new(self, scriptaction)
layout.addWidget(@listbox)
Snippets.constants.each do |n|
if n.index('Snippet_') == 0
@@ -177,7 +192,7 @@
$voidptr = KoDocker.toVoidPtr()
$wdg = Qt::Internal.kross2smoke($voidptr, Qt::DockWidget)
-$label = SnippetsWidget.new($wdg)
+$label = SnippetsWidget.new($wdg, self)
$wdg.setWidget($label)
puts "Ruby Docker Script 'snippetsdocker.rb' Loaded!"
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic