eea / odfpy

API for OpenDocument in Python
GNU General Public License v2.0
311 stars 64 forks source link

Use tabs int various styles #96

Closed exodehm closed 4 years ago

exodehm commented 4 years ago

Hello

It is possible to use a tabs in different styles. I mean that:

        tabstops_style = TabStops()
    #Cada tabulador
    tabstop_style = TabStop(position="2.5cm")
    tabstops_style.addElement(tabstop_style)
    tabstop_style = TabStop(position="4.6cm")
    tabstops_style.addElement(tabstop_style)
    tabstop_style = TabStop(position="5.5cm")
    tabstops_style.addElement(tabstop_style)
    tabstop_style = TabStop(position="12.5cm")
    tabstops_style.addElement(tabstop_style)    
    tabstop_style = TabStop(position="14cm")
    tabstops_style.addElement(tabstop_style)    
    tabstoppar = ParagraphProperties()
    tabstoppar.addElement(tabstops_style)
    tabparagraphstyle = Style(name="Question", family="paragraph")
    tabparagraphstyle.addElement(TextProperties(attributes={'fontsize':"10pt",'fontfamily' : "helvetica"}))
    tabparagraphstyle.addElement(tabstoppar)
    s.addElement(tabparagraphstyle)

And forward (it doesn work):

        anotherstyle = Style(name="Question", family="paragraph")
    anotherstyle.addElement(TextProperties(attributes={'fontsize':"12pt",'fontfamily' : "helvetica", 'fontweight':"bold"}))
    anotherstyle.addElement(tabstoppar)
    s.addElement(anotherstyle)

Thanks!

exodehm commented 4 years ago

Ok I must to use the parent style for inherit the propertys. The base style has the property name="Tabuladores Base" and the derived styles has the property parentstylename = "Tabuladores Base" I put a complete example:

tabstops_list = TabStops()
tabstop = TabStop(position="2.5cm")
tabstops_list.addElement(tabstop)
tabstop = TabStop(position="12.5cm")
tabstops_list.addElement(tabstop)
tabstop = TabStop(position="14cm")
tabstops_list.addElement(tabstop)
tabstoppar = ParagraphProperties()
tabstoppar.addElement(tabstops_list)
tabstyle = Style(name="Tabuladores Base", family="paragraph")
tabstyle.addElement(tabstoppar)
s.addElement(tabstyle)
#bold with tabs
boldtabstyle = Style(name="Negritas con tabuladores", family="paragraph", parentstylename = "Tabuladores Base")
boldtabstyle.addElement(TextProperties(fontweight ="bold", fontfamily="helvetica"))
s.addElement(boldtabstyle)
#normal con tabs
normaltabstyle = Style(name="Normal con tabuladores", family="paragraph", parentstylename = "Tabuladores Base")
normaltabstyle.addElement(TextProperties(fontweight ="light", fontfamily="helvetica", fontsize="10pt"))
s.addElement(normaltabstyle)