[PyKDE] an example of simple python scripting of Kspread?

Jim Bublitz jbublitz at nwinternet.com
Sun Feb 2 23:05:01 GMT 2003


On 01-Feb-03 blake wrote:
> I am running RH8.0 and KDE.  I would like to have a python
> program call up Kspread, open a spreadsheet (or two), calculate
> the results and then save the result.  This would seem like a
> simple task, but the several examples given for the PyKDE
> v3.3.2 package seem to emphasize writing a new application 
> rather than manipulating an existing one (like Kword, kspread
> etc).  Can anyone point me to any documentation that would have
> examples of doing such simple scipting?  

The PyKDE examples are KParts examples and probably not what you
want. There are two possible ways I can see to accomplish what
you're asking (there may be other ways too - be creative):

1. Use DCOP. PyKDE has support for DCOP, although I've never
personally used it or tested it (it's mostly there for symbol
resolution at the moment). I'm not sure that what's there is
sufficient (but I think it is). Additionally, you can dig through
the KDE docs and code (the KDE SDK I think) and look for examples
of interfacing to DCOP via Python *without* PyKDE. Sorry for being
vague, but I've never investigated this area much.

2. Write Python plugins for KSpread. I've actually done this (for
KSpread 1.1) and it's extremely cool. I've also just sent some old
crappy code off (this morning in fact) to a KSpread developer who
requested it, but I think he has something different in mind. This
requires coding some C++, but isn't too hard. The code I did
allowed a) scripting of KSpread via Python, which requires a
wrapper for KSpread classes and Python bindings for the wrapper,
and b) writing KSpread formulas in Python - eg put "=someFormula
(x)" in a cell, which doesn't require a wrapper or bindings - just
a fairly simple (after you spend a few weeks deciphering KSpread)
pair of plugins (one for the formula mechanism and one for the
Python interpreter). 

Note that you *can't* use PyKDE to write KDE plugins, because the
KDE plugin mechanism requires a libtool library (there may be ways
around that too however).

The code I did was only for KSpread 1.1 - won't work at all with
later versions because the KSpread internals changed significantly.
At the moment I'm working on PyKDE for KDE 3.1 full time, along
with a releated project. KSpread 1.3 (with yet more interface
changes, I'm told) will be out around April, and Python itself
looks like it will switch from a static (.a) lib to dynamic (.so)
some time soon, so I'll be digging back into this then I hope.

Otherwise, if you can't wait, understand C++ fairly well and want
to dig through some bad code, I'll be happy to send you what I have.
Just drop me an email directly. The tarball is about 600KB,
probably won't compile, and won't work if it does. Or look into
DCOP - unfortunately the KDE docs seem a little sparse though.

Just to be fair, I believe this is supposed to be possible already
with Gnumeric (although I've never tried that either). OpenOffice
also has some stuff about Python scripting, but last time I looked
it was also vaporware (similar to DCOP, too, I think). I think this
would be a significant, important addition to KDE and wish I had
time to get to it sooner. I'll get to it eventually if no one else
does.

Jim




More information about the PyQt mailing list