column widths of a TABLE when using xhtml()

Asked by Luc Saffre on 2012-02-11

Hi,

when I generate myself some XHTML code of a table, for example

s = """
<TABLE>
<TR><TD width="20">foo</TD><TD width="100">bar</TD></TR>
</TABLE>
"""

and then insert it into a document using:

do text
from xhtml(s)

then the result is a beautiful table, but all columns have same width.
It seems that the width values are ignored. Is that true?
Or am I missing something?
If that feature is not yet implemented, is there some workaround to specify column widths?

Luc

Question information

Language:
English Edit question
Status:
Solved
For:
Appy Edit question
Assignee:
No assignee Edit question
Solved by:
Luc Saffre
Solved:
2012-04-19
Last query:
2012-04-19
Last reply:
2012-02-12

Hi Luc,
Indeed, not yet implemented, sorry ;-)
The workaround for generating more "complex" tables is to create it programmatically via the class appy.pod.parts.OdtTable. Once you have an instance of this class you can write

do text
from odtTableInstance.get()

But the problem is that OdtTable does not manage cell widths... Maybe if you take a look to this class, you could improve it?

Cheers,
Gaetan

Luc Saffre (luc-saffre) said : #2

Gaëtan, I had a look at this during the week-end.

`do text from <http://appyframework.org/podWritingAdvancedTemplates.html>`_
currently simply expects a chunk of XML to be inserted at that place of the template.
But it seems that we need more.
In order to specify widths of table columns,
we also need to be able add styles to the document:
at least one automatic style for each column that has a width specified.
This cannot be done using a simple XML chunk.
The `appy.pod.parts.OdtTable´ is useless as long as it cannot do more than returning an XML chunk.

My suggestion for :term:`appy.pod` is to extend the `do text from` clause so that
the user function may return something else than a string.
For example a `dict` with different keys "content", "styles", "automaticstyles"...

or an `odf.opendocument.OpenDocumentText
<https://joinup.ec.europa.eu/svn/odfpy/trunk/odf/opendocument.py>`_
instance, and in that case appy.pod would
(1) inspect the `styles` and `automaticstyles`
of this instance and add them to the styles and automatic styles
of the template, (2) consider the whole `text` part
of the document instance as the XML chunk to be inserted.

Luc Saffre (luc-saffre) said : #3

Uff, I have a working solution. Not really beautiful but working. Besides generating the correct chunks of XML, we also need to add “dynamic” styles (i.e. which get generated only while rendering the content). The work is done by the finalizeFunction of the appy.pod renderer which inserts these additional styles afterwards (when the document has been processed).

Concretely this is done in http://code.google.com/p/lino/source/browse/lino/utils/appy_pod.py
and demonstrated in file /tests/appy/20120419/test.py.

This implementation is partly Lino specific since it is a generic solution for rendering any Lino table, but the principal method should be reusable.

Any comments are welcome.

Luc