# -*- coding: ISO-8859-1 -*- """ capellaScript -- Copyright (c) 2011 Peter Becker >>> Dateiname einfügen Der Dateiname wird an der Seite verankert eingefügt|| Bei Problemen bitte eine Mail an peter_becker@freenet.de <<< History: 19.02.11 - Erste Ausgabe """ import xml.dom, tempfile import tkFont import Tkinter from caplib.capDOM import ScoreChange from xml.dom.minidom import * doc = [] # parentNode von score version = "1.0.0" def latin1_e(u): return u.encode('Latin-1') def getElementObjects(objList): # returns a List newList = NodeList() for n in range(objList.length): if objList[n].nodeType == objList[n].ELEMENT_NODE: newList.append(objList[n]) return newList def findElementNode(el,tagName): 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] return 'NONE' def addElementNode(el,tagName): # 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 = doc.createElement(tagName) el.appendChild(newChild) return newChild def addNewElementNode(el,tagName): # add new Node with tagName "tagName" to el global doc newChild = doc.createElement(tagName) el.appendChild(newChild) return newChild def getElementObjects(objList): # returns a List newList = NodeList() for n in range(objList.length): if objList[n].nodeType == objList[n].ELEMENT_NODE: newList.append(objList[n]) return newList def addFileName(score,file): global doc, Font, Hoehe, Schriftschnitt pOs = score.getElementsByTagName('pageObjects') #messageBox('POs',str(pOs)) if not pOs: sys = findElementNode(score,'systems') newChild = doc.createElement('pageObjects') score.insertBefore(newChild,sys) pOs = score.getElementsByTagName('pageObjects') #messageBox('SYS',str(pOs)) drawObj = addNewElementNode(pOs[0],'drawObj') text = addNewElementNode(drawObj,'text') font = addNewElementNode(text,'font') content = addNewElementNode(text,'content') font.setAttribute('face',Font) font.setAttribute('height',str(Hoehe)) font.setAttribute('pitchAndFamily','0') if Schriftschnitt == 0: weight = '0' elif Schriftschnitt == 1: weight = '0' font.setAttribute('italic','true') elif Schriftschnitt == 2: weight = '700' elif Schriftschnitt == 3: weight = '700' font.setAttribute('italic','true') font.setAttribute('weight',weight) text.setAttribute('y','-2.5') text.setAttribute('x','0.1') content.appendChild(score.parentNode.createTextNode(str(file))) return def changeDoc(score): global doc doc = score.parentNode file = activeScore().pathName() if len(file) == 0: messageBox('ERROR','Die Datei wurde noch nicht gespeichert') else: #messageBox('NAME',str(file)) addFileName(score, file) return def getFonts(): root = Tkinter.Tk() FontListT= tkFont.families() FontList = [] FontList2 = [] i=0 while i < len(FontListT): FontList += [latin1_e(FontListT[i])] i+=1 j=0 while j < len(FontList): FontName = FontList[j] FontList[j] = FontName[0].upper() + FontName[1:] j+=1 FontList.sort() root.destroy() return FontList def pqDialog(FontList): global Hoehe, Font, Schriftschnitt sc = '2' # Startcount options = ScriptOptions() opt = options.get() Font = 'Times New Roman' Hoehe = '8' Schriftschnitt = '0' if opt: Font = opt.get('FontTyp',Font) Hoehe = opt.get('FontHigh',Hoehe) Schriftschnitt = opt.get('FontWeight',Schriftschnitt) FontList = [Font] + FontList Schriftschnitte = ['Standard','Kursiv','Fett','Fett Kursiv'] placeholder1 = Label(' ',width=1) placeholder2 = Label(' ',width=1) placeholder3 = Label(' ',width=1) placeholder4 = Label(' ',width=1) #lablSc = Label('Zähler für ersten Faulenzer ',width=6) #editSc = Edit (sc,width=10) #subboxSc = HBox([lablSc,editSc,placeholder4],padding=0) #box1 = HBox([subboxSc,placeholder4],padding=4) radSchnitt = Radio(Schriftschnitte, value=int(opt.get('Schriftschnitt',str(Schriftschnitt))), padding = 0) editHeight = Edit(Hoehe, width=4, min = 1, max = 99) comboFont = ComboBox(FontList, width=20, value=0) box1ba = HBox([radSchnitt], padding = 0,text='Schriftschnitt') box1bb = VBox([editHeight], padding = 0,text='') box1bb = HBox([box1bb, placeholder2], padding = 5,text='Schriftgröße') box1bc = VBox([comboFont], padding = 0,text='') box1bc = HBox([box1bc], padding = 50,text='Schriftart') box1bd = HBox([box1ba,box1bb], padding = 8, text = '') box1be = VBox([box1bd, box1bc], padding = 8,text='') box1b = HBox([box1be], padding = 8,text='Schrift') #mainboxSc = VBox([box1],text='Faulenzerzähler') box = VBox([box1b,placeholder1],padding=1) dlg = Dialog('Dateiname einfügen (Version ' + version + ')', box) if dlg.run(): Hoehe = editHeight.value() Font = FontList[comboFont.value()] Schriftschnitt = radSchnitt.value() opt = dict( FontTyp = str(Font), FontHigh = str(Hoehe), FontWeight = str(Schriftschnitt) ) options.set(opt) return True else: return False # Hauptprogramm: from caplib.capDOM import ScoreChange import tempfile class ScoreChange(ScoreChange): def changeScore(self, score): changeDoc(score) if activeScore(): FontList = getFonts() if pqDialog(FontList): global tempInput, tempOutput activeScore().registerUndo("Dateiname einfügen") tempInput = tempfile.mktemp('.capx') tempOutput = tempfile.mktemp('.capx') activeScore().write(tempInput) ScoreChange(tempInput, tempOutput) activeScore().read(tempOutput) os.remove(tempInput) os.remove(tempOutput)