<div class="gmail_quote">2012/1/28 Rob Oakes <span dir="ltr"><<a href="mailto:LyX-Devel@oak-tree.us">LyX-Devel@oak-tree.us</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Do you know of any methods to look at the properties of styles?</blockquote></div><br><font>I do a script that read the SLA as XML</font> and get styles from it:<br><br><span style="font-family:courier new,monospace">import xml.parsers.expat
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">################################################
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"># Code to handle elements of XML Scribus doc
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"># Convert default points values to current units
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">################################################
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"># Dictionaries to hold style sheets
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">styles = {}
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">charstyles = {}
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">document = {}
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">pages = {}
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">def start_element(name, attrs):
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> '''Build dictonaries from SLA doc file.'''
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> # print 'Start element:', name, attrs #debug
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> global styles, charstyles, document, pages
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> if name == 'DOCUMENT':
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> document = attrs
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> if name == 'STYLE':
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> #print '=====\n',name,attrs,attrs[u'NAME']
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> # A bug in style editor:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> # sometimes create a anomale style definition <STYLE LANGUAGE="Portuguese"/>
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> # So we need to catch errors and ignore it
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> try: styles[attrs[u'NAME']] = attrs
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> except: pass
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> if name == 'CHARSTYLE':
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> try: charstyles[attrs[u'CNAME']] = attrs
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> except: pass
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> if name == 'PAGE':
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> try: pages[attrs[u'NUM']] = attrs
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> except: pass
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">def getParagraphStyle(styleName):
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> '''Return a dictionary with paragraph style parameters.
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> If style don't exist, create it with default paragraph parameters.'''
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> try:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = styles[styleName]
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> except:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> print styleName,'not in style sheet. Creating it.'
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> scribus.createParagraphStyle(styleName)
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> styles[styleName] = styles[defaultParagraphStyle]
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = styles[defaultParagraphStyle]
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> return res
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">def getParagraphAttribute(styleName,attrName):
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> '''Return value of given attribute of given style
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> ***in current mesurement units.*** '''
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = 0
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> # Find parameter in parent style, if not in current style, up to 10 levels.
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> for n in range(10):
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> dic = getParagraphStyle(styleName)
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> if attrName in dic:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = dic[attrName]
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> # Convert points to current units
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> unit = scribus.getUnit()
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = float(res)*unitDict[unit]
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> print "Find",attrName,"=",res,'in',styleName,"."
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> break
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> else:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> print "\nI don't find",attrName,"in",styleName,"."
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> if 'PARENT' in dic:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> styleName = dic['PARENT']
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> print "I will search in his father,",styleName,"."
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> else:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> print "I don't find any value. Setting to zero..."
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> break
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> else:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = 0
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> return res
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">def getStyleLineSpacing(styleName):
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> '''Return line spacing of given style.'''
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> # Need test line spacing mode
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> # If line space mode is automatic,
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> # line space is equal font size times line space percent
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = float(getParagraphAttribute(styleName,'LINESP'))
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> return res
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">def getStyleLineSpaceMode(styleName):
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> '''0=fixed, 1=proportional.'''
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = int(getParagraphAttribute(styleName,'LINESPMode'))
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> return res
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">def getStyleSpaceAbove(styleName):
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> '''Return space above of given paragraph style.'''
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = float(getParagraphAttribute(styleName,'VOR'))
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> return res
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">def getStyleSpaceBelow(styleName):
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> '''Return space below of given paragraph style.'''
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = float(getParagraphAttribute(styleName,'NACH'))
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> return res
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">def getBaselineGrid():
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> '''Get document baseline grid.'''
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> global document
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> if document == {}:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = 0
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> else:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = float(document['BASEGRID'])
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> unit = scribus.getUnit()
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = res*unitDict[unit]
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> return res
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">def getBaselineOffset():
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> '''Get document baseline offset.'''
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> global document
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> if document == {}:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = 0
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> else:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = float(document['BASEO'])
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> unit = scribus.getUnit()
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = res*unitDict[unit]
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> return res
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">def getAutoLineSpace():
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> '''Get automatic line space percentage of current document.'''
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> global document
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> if document == {}:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = 0
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> else:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = float(document['AUTOL'])
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> unit = scribus.getUnit()
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = res*unitDict[unit]
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> return res
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">def getPageAttributes(page):
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> page = page - 1
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> try: res = pages[str(unicode(page))]
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> except:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> print 'Page',page,'not in document.'
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = {}
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> return res
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">def getVAutoGap():
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> page = scribus.currentPage()
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> pdic = getPageAttributes(page)
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> if pdic == {}:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = 0
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> else:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> try:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = float(pdic['AGverticalAutoGap'])
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> unit = scribus.getUnit()
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> res = res*unitDict[unit]
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> except:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> print 'AGverticalAutoGap','not in page',page
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> return res
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> </span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">def parseDoc():
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> ''' Get attributes from current Scribus doc.'''
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> debug()
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> global styleList
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> parser = xml.parsers.expat.ParserCreate('UTF-8')
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> parser.StartElementHandler = start_element
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> try:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> docName = scribus.saveDoc()
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> # Undocumented Scribus 1.3.9 function:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> docName = unicode(scribus.getDocName())
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> file = open(docName,'r')
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> parser.ParseFile(file)
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> file.close()
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> except:
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> print "Error analising doc."
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> earlyExit()
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> styleList = scribus.getAllStyles()
</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> styleList.sort()
</span><br style="font-family:courier new,monospace"><br clear="all"><br>-- <br>
<font style="font-family:Helvetica,Arial,sans-serif" color="#888888"><font style="font-family:Helvetica,Arial,sans-serif" color="#888888"><font style="font-family:Helvetica,Arial,sans-serif" color="#888888"><font size="1"><font><img style="width:75px;min-height:100px" alt="Meira" src="http://lh4.ggpht.com/_75EesisxR5g/TENbAQVXMLI/AAAAAAAADHs/ChNQzn8eOT0/meira-75x100.jpg" hspace="8" align="left" vspace="6"></font></font></font></font><hr>
</font><span style="font-family:Helvetica,Arial,sans-serif">nome: "</span><span style="font-weight:bold;font-family:Helvetica,Arial,sans-serif">José Antonio Meira da Rocha</span><span style="font-family:Helvetica,Arial,sans-serif">" </span><br style="font-family:Helvetica,Arial,sans-serif">
<small style="font-family:Helvetica,Arial,sans-serif">googletalk: email: MSN: <a href="mailto:joseantoniorocha@gmail.com" target="_blank">joseantoniorocha@gmail.com</a><br>
veículo: [ <a href="http://meiradarocha.jor.br/" target="_blank">http://meiradarocha.jor.br</a>
] <br></small>
<hr style="width:100%;height:2px;font-family:Helvetica,Arial,sans-serif">
<br>