[pod] If you define a variable named 'tableName' inside a table, it will be used to name the table. For information, with Calc, every spreadsheet is represented as a table; the table name is the name that appears in the corresponding tab, in the bottom of the screen.

This commit is contained in:
Gaetan Delannay 2015-01-14 11:46:25 +01:00
parent 1730ce3c19
commit ffb8bed189
2 changed files with 27 additions and 19 deletions

View file

@ -139,16 +139,23 @@ class Buffer:
def getLength(self): pass # To be overridden def getLength(self): pass # To be overridden
def patchColumnsRepeated(self, attrs): def patchTableElement(self, elem, attrs):
'''Every table column must have an attribute '''Convert the name of a table to an expression allowing the user to
"number-columns-repeated".''' define himself this name via variable "tableName".
key = self.env.tags['number-columns-repeated']
attrs = attrs._attrs Convert attribute "number-columns-repeated" of every table column
columnNumber = self.env.getTable().nbOfColumns -1 (or add it if it does not exist) to let the user define how he will
if key in attrs: repeat table columns via variable "columnsRepeated".'''
attrs[key] = ':columnsRepeated[%d]|%s' % (columnNumber, attrs[key]) if elem == self.env.tags['table']:
else: attrs = attrs._attrs
attrs[key] = ':columnsRepeated[%d]|1' % (columnNumber) name = self.env.tags['table-name']
attrs[name] = ':tableName|"%s"' % attrs[name]
elif elem == self.env.tags['table-column']:
attrs = attrs._attrs
key = self.env.tags['number-columns-repeated']
columnNumber = self.env.getTable().nbOfColumns -1
nb = (key in attrs) and attrs[key] or '1'
attrs[key] = ':columnsRepeated[%d]|%s' % (columnNumber, nb)
def dumpStartElement(self, elem, attrs={}, ignoreAttrs=(), hook=False, def dumpStartElement(self, elem, attrs={}, ignoreAttrs=(), hook=False,
noEndTag=False, renamedAttrs=None): noEndTag=False, renamedAttrs=None):
@ -166,8 +173,8 @@ class Buffer:
p_hook must be a tuple (s_attrName, s_expr). p_hook must be a tuple (s_attrName, s_expr).
''' '''
self.write('<%s' % elem) self.write('<%s' % elem)
if self.pod and (elem == self.env.tags['table-column']): # Some table elements must be patched (pod only)
self.patchColumnsRepeated(attrs) if self.pod: self.patchTableElement(elem, attrs)
for name, value in attrs.items(): for name, value in attrs.items():
if ignoreAttrs and (name in ignoreAttrs): continue if ignoreAttrs and (name in ignoreAttrs): continue
if renamedAttrs and (name in renamedAttrs): name=renamedAttrs[name] if renamedAttrs and (name in renamedAttrs): name=renamedAttrs[name]

View file

@ -192,6 +192,7 @@ class PodEnvironment(OdfEnvironment):
xmlElemDef.__init__(elemFullName) xmlElemDef.__init__(elemFullName)
# Create a table of names of used tags and attributes (precomputed, # Create a table of names of used tags and attributes (precomputed,
# including namespace, for performance). # including namespace, for performance).
table = ns[self.NS_TABLE]
self.tags = { self.tags = {
'tracked-changes': '%s:tracked-changes' % ns[self.NS_TEXT], 'tracked-changes': '%s:tracked-changes' % ns[self.NS_TEXT],
'change': '%s:change' % ns[self.NS_TEXT], 'change': '%s:change' % ns[self.NS_TEXT],
@ -199,17 +200,17 @@ class PodEnvironment(OdfEnvironment):
'change-start': '%s:change-start' % ns[self.NS_TEXT], 'change-start': '%s:change-start' % ns[self.NS_TEXT],
'change-end': '%s:change-end' % ns[self.NS_TEXT], 'change-end': '%s:change-end' % ns[self.NS_TEXT],
'conditional-text': '%s:conditional-text' % ns[self.NS_TEXT], 'conditional-text': '%s:conditional-text' % ns[self.NS_TEXT],
'table-cell': '%s:table-cell' % ns[self.NS_TABLE], 'table': '%s:table' % table,
'formula': '%s:formula' % ns[self.NS_TABLE], 'table-name': '%s:name' % table,
'table-cell': '%s:table-cell' % table,
'table-column': '%s:table-column' % table,
'formula': '%s:formula' % table,
'value-type': '%s:value-type' % ns[self.NS_OFFICE], 'value-type': '%s:value-type' % ns[self.NS_OFFICE],
'value': '%s:value' % ns[self.NS_OFFICE], 'value': '%s:value' % ns[self.NS_OFFICE],
'string-value': '%s:string-value' % ns[self.NS_OFFICE], 'string-value': '%s:string-value' % ns[self.NS_OFFICE],
'span': '%s:span' % ns[self.NS_TEXT], 'span': '%s:span' % ns[self.NS_TEXT],
'number-columns-spanned': '%s:number-columns-spanned' % \ 'number-columns-spanned': '%s:number-columns-spanned' % table,
ns[self.NS_TABLE], 'number-columns-repeated': '%s:number-columns-repeated' % table,
'number-columns-repeated': '%s:number-columns-repeated' % \
ns[self.NS_TABLE],
'table-column': '%s:table-column' % ns[self.NS_TABLE],
} }
self.ignorableElements = (self.tags['tracked-changes'], self.ignorableElements = (self.tags['tracked-changes'],
self.tags['change']) self.tags['change'])