[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-07-06 1:25:22
Message-ID: 1183685122.794385.26655.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 684060 by sebsauer:
* 2 more scripting formula function samples
* dox++
M +1 -2 ScriptingFunction.cpp
M +39 -3 ScriptingFunction.h
M +2 -1 scripts/CMakeLists.txt
AM scripts/pyregexp.py
AM scripts/pytime.py
M +14 -0 scripts/scripts.rc
--- trunk/koffice/kspread/plugins/scripting/ScriptingFunction.cpp #684059:684060
@@ -1,7 +1,7 @@
/*
* This file is part of KSpread
*
- * Copyright (c) 2006 Sebastian Sauer <mail@dipe.org>
+ * Copyright (c) 2006, 2007 Sebastian Sauer <mail@dipe.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
@@ -136,7 +136,6 @@
QString syntax;
QString error;
QVariant result;
-
QDomDocument document;
QDomElement funcElement;
QDomElement helpElement;
--- trunk/koffice/kspread/plugins/scripting/ScriptingFunction.h #684059:684060
@@ -1,7 +1,7 @@
/*
* This file is part of KSpread
*
- * Copyright (c) 2006 Sebastian Sauer <mail@dipe.org>
+ * Copyright (c) 2006, 2007 Sebastian Sauer <mail@dipe.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
@@ -29,8 +29,26 @@
* functionality to deal with formula functions that are written in
* a scripting language like Python or Ruby.
*
- * For an example how to use scripted formula functions see;
- * \see http://websvn.kde.org/trunk/koffice/kspread/plugins/scripting/scripts/functions.py?view=markup
+ * The following sample scripting formula function written in python
+ * displays the current datetime.
+ * \code
+ * import time, Kross, KSpread
+ * func = KSpread.function("PYTIME")
+ * func.minparam = 0
+ * func.maxparam = 1
+ * func.comment = "The PYTIME() function displays the current datetime."
+ * func.syntax = "PYTIME(string)"
+ * func.addParameter("String", "The datetime format string.")
+ * func.addExample("PYTIME()")
+ * func.addExample("PYTIME(\"%Y-%M-%d %H:%M.%S\")")
+ * def update(args):
+ * try:
+ * func.result = time.strftime(args[0] or "%H:%M.%S")
+ * except:
+ * func.error = "Invalid format"
+ * func.connect("called(QVariantList)", update)
+ * func.registerFunction()
+ * \endcode
*/
class ScriptingFunction : public QObject
{
@@ -48,27 +66,45 @@
explicit ScriptingFunction(QObject* parent);
virtual ~ScriptingFunction();
+ /// \return the name the function has.
QString name() const;
+ /// Set the name the function has.
void setName(const QString& name);
+ /// \return the minimum number of parameters the function expects.
int minParam() const;
+ /// Set the minimum number of parameters the function expects.
void setMinParam(int minparam);
+ /// \return the maximum number of parameters the function expects.
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.
void setResult(const QVariant& result);
public slots:
+ /// An an example to demonstrate the usage of the function.
void addExample(const QString& example);
+ /// An details about a parameter the function may expect.
void addParameter(const QString& typeName, const QString& comment);
+ /// Register this function.
bool registerFunction();
signals:
+ /// This signal is emitted if the function got called.
void called(QVariantList args);
private:
--- trunk/koffice/kspread/plugins/scripting/scripts/CMakeLists.txt #684059:684060
@@ -3,8 +3,8 @@
DESTINATION ${DATA_INSTALL_DIR}/kspread/scripts)
install(FILES
+ csvimport.py csvexport.py csvoptions.ui
kexidbimport.py kexidbexport.py
- csvimport.py csvexport.py csvoptions.ui
htmlexport.py htmlexportinfos.ui
odfpyexport.py
DESTINATION ${DATA_INSTALL_DIR}/kspread/scripts/extensions)
@@ -12,4 +12,5 @@
install(FILES
functions.py
yfinance.py yweather.py
+ pytime.py pyregexp.py
DESTINATION ${DATA_INSTALL_DIR}/kspread/scripts/functions)
** trunk/koffice/kspread/plugins/scripting/scripts/pyregexp.py #property svn:executable
+ *
** trunk/koffice/kspread/plugins/scripting/scripts/pytime.py #property svn:executable
+ *
--- trunk/koffice/kspread/plugins/scripting/scripts/scripts.rc #684059:684060
@@ -55,6 +55,20 @@
comment="Yahoo! Weather formula function"
interpreter="python"
file="functions/yweather.py" />
+ <script
+ name="pytime"
+ text="PyTime"
+ comment="Time formula function"
+ enabled="false"
+ interpreter="python"
+ file="functions/pytime.py" />
+ <script
+ name="pyregexp"
+ text="PyRegExp"
+ comment="Regular Expression formula function"
+ enabled="false"
+ interpreter="python"
+ file="functions/pyregexp.py" />
</collection>
</KrossScripting>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic