# -*- coding: ISO-8859-1 -*- """ capellaScript -- Copyright (c) 2008 Peter Becker >>> Textzuweisung Dieses Script weisst den an der Seite verankerten Einfachtexten einen Label zu. Dieser Label kann dann im Rohformatierer verwendet werden.|| || Bei Problemen bitte eine Mail an peter_becker@freenet.de <<< """ # 03.11.2008 Erste Version # 24.11.2008 Menu eliminiert, erweitert um Textfelder und Metafiles import xml.dom, tempfile from caplib.capDOM import ScoreChange, firstChildElement from xml.dom.minidom import * doc = [] # parentNode von score class Textzuweisung(ScoreChange): def changeScore(self, score): getPageObjects(score) def setCount(count,score,el): #tx = 'T'+tagList[bezeichnung] tag = '2086-' + str(int(count)) basic = addElementNode(el.parentNode,'basic',score) #messageBox('TAG',str(tag) + '\n' + str(basic)) basic.setAttribute('tag',str(tag)) def getPageObjects(score): global Textfeld,bezeichnung maxElements = 30 count = 70 for POs in score.getElementsByTagName('pageObjects'): #messageBox('POs',str(POs)) for doS in POs.getElementsByTagName('drawObj'): #messageBox('doS',str(doS) + '\n' + str((doS.firstChild))) for tx in doS.getElementsByTagName('text'): #messageBox('text',str(tx)) setCount(count,score,tx) count = count + 1 break for rt in doS.getElementsByTagName('richText'): #messageBox('richText',str(rt)) setCount(count,score,rt) count = count + 1 break for mf in doS.getElementsByTagName('metafile'): #messageBox('metafile',str(mf)) setCount(count,score,mf) count = count + 1 break def addElementNode(el,tagName,score): # Neue Node zu "el" hinzufügen wenn Node "tagName" nicht existiert # ansonsten existierende Node zurückmelden global doc childs = el.childNodes for n in range(childs.length): if childs[n].nodeType ==childs[n].ELEMENT_NODE and childs[n].tagName == tagName: return childs[n] newChild = score.parentNode.createElement(tagName) el.appendChild(newChild) return newChild # Hauptprogramm: if activeScore(): activeScore().registerUndo("Textzuweisung") tempInput = tempfile.mktemp('.capx') tempOutput = tempfile.mktemp('.capx') activeScore().write(tempInput) Textzuweisung(tempInput, tempOutput) activeScore().read(tempOutput) os.remove(tempInput) os.remove(tempOutput)