[YLUG] Spreadsheets in Python?

Roger Leigh rleigh at whinlatter.ukfsn.org
Thu Jul 27 10:20:33 BST 2006


Simon Ward <simon at principia.demon.co.uk> writes:

> Arthur Clune wrote:
>>
>> On 23 Jul 2006, at 17:18, Simon Ward wrote:

>> Prehaps if you explain which bits of spreadsheet functionality you
>> want we could help? Is it the input functionality you want rather
>> than the calculation side of things?
>   Input/modification functionality is the key right now.
>   We have a bunch of data files which contain CSV data - nothing
> fancy, one set of parameters per line, each line contains three values
> which are comma separated.
>
>   What we're looking for is a tidy way of:
>
> a) reading in this data and displaying it in an Excel-like way (ie.
>    three columns) - each value would be in its own 'cell'
> b) allow the user move between cells, by tabbing or otherwise, to modify
>    values. Modification here means either 'adding extra lines of data',
>    'deleting spurious lines of data' or 'modifying single values'
> c) once the mods are finished, the user should be able to save the data
>    to a file.

Which UI toolkit are you currently using?  If you are using GTK+, the
TreeView widget is ideal for this task.  This has a model/view
separation, so you would have:

1 widget (a GtkTreeView)
3 cell renderers, one per column (CellRendererText); you'll need to
  use the CellEditable interface to allow live editing of the data in
  the model (use the "edited" signal, and set the "editable" property
  to true; you can also do validation in the handler for this).  You
  could also have a separate editing widget which gets filled with the
  data from the currently selected row.
1 list containing your data as objects/tuples (I'm not sure which are
  used in python--both may be fine).  The list is an object
  implementing the TreeModel interface, such as ListStore.  You attach
  members in your class to cell renderer "properties", such as the
  "text" property (there are many others as well).

If you are already doing this, and it is too slow, there is something
wrong with your use of signals; you can freeze the view during
updates, or detach and reattach the model to prevent huge UI hangs
when filling or manipulating the model.  Profiling will help show
where signals are being used inefficiently.

Lars has written a good tutorial here:
  http://liw.iki.fi/liw/texts/gtktreeview-tutorial.html

And a more comprehensive, but C-centric, one is here (and written by
(ex-?) YLUGer Tim-Philipp Müller to boot):
  http://scentric.net/tutorial/

> As I mentioned previously, we have an interim solution but it is
> horrible and slow and I'd rather avoid using something heavyweight
> like Gnumeric if I can avoid it *unless* there's away of allowing a
> regular Python interpreter to access Gnumeric's modules in order to
> open a workbook, load data etc. If there is such a way, I've yet to
> find it.

GNOME applications were one supposed to be fully scriptable with
scheme.  That was abandoned a few years ago, which is a great shame.
Gnumeric itself is all GObject-based C, so you would be able to re-use
the spreadsheet widget with an alternative front-end, but
would likely be quite a good bit of work, and you would need to write
it in C, or write python bindings.


Regards,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please sign and encrypt your mail.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
Url : http://mailman.lug.org.uk/pipermail/york/attachments/20060727/de9766cf/attachment.bin


More information about the York mailing list