# -*- coding: ISO-8859-1 -*- """ capellaScript -- Copyright (c) 2007 Peter Becker >>> Pausen_Zaehler : Ganztaktpausen durchnummerieren. Die zu nummerierenden Ganztaktpausen mit dem Cursor markieren, und dann das Script aufrufen|| Bitte nur aufeinanderfolgende Ganztaktpausen markieren !|| Bei Problemen bitte eine Mail an peter_becker@freenet.de <<< Numbering consecutive full-measure rests

Mark the full-measure rests to be numbered with the cursor, and then open the script.

Please mark only successive full-measure rests!

In case of problems please send a mail to peter_becker@freenet.de

Pausenzähler : Ganztaktpausen durchnummerieren.

Die zu nummerierenden Ganztaktpausen mit dem Cursor markieren, und dann das Script aufrufen.

Bitte nur aufeinanderfolgende Ganztaktpausen markieren !

Bei Problemen bitte eine Mail an peter_becker@freenet.de

Helemaatsrusten doornummeren

Markeer de te nummeren rusten met de cursor en open daarna het script.

S.v.p alleen opeenvolgende rusten markeren!

Bij problemen graag een mail naar peter_becker@freenet.de

Tags : 2086-61 History: 01.12.07 - PB Erste Ausgabe 04.12.07 - PB freie Schriftwahl 22.12.18 - WW Internationalierung (En-De-Nl) + 'help'(=Infotext) 17.12.21 - WW Font 'Capella3' verwendbar, sodann y=-3 27.12.21 - PB y Wert generell auf -3 gesetzt """ english = { 'error' :'Error', 'noScore' :'No active score', 'standard' :'Standard', 'italic' :'Italic', 'bold' :'Bold', 'boldItalic' :'Bold Italic', 'counter1stRest':'Number for the first rest ', 'charStyle' :'Character style', 'fontSize' :'Font size', 'font' :'Font', 'format' :'Format', 'counter' :'Numbering rests', 'title' :'Numbering consecutive full-measure rests', 'help' :'Mark the full-measure rests to be numbered with the cursor,\ \nand then open the script.\n\ \nPlease mark only consecutive full-measure rests!\n\ \nIn case of problems please send a mail to peter_becker@freenet.de' } german = { 'error' :'Fehler', 'noScore' :'keine aktive Partitur', 'standard' :'Standard', 'italic' :'Kursiv', 'bold' :'Fett', 'boldItalic' :'Fett Kursiv', 'counter1stRest':'Zähler für erste Pause ', 'charStyle' :'Schriftschnitt', 'fontSize' :'Schriftgröße', 'font' :'Schriftart', 'format' :'Schrift', 'counter' :'Pausenzähler', 'title' :'Pausenzaehler : Ganztaktpausen durchnummerieren', 'help' :'Die zu nummerierenden Ganztaktpausen mit dem Cursor markieren,\ \nund dann das Script aufrufen.\n\ \nBitte nur aufeinanderfolgende Ganztaktpausen markieren !\n\ \nBei Problemen bitte eine Mail an peter_becker@freenet.de' } dutch = { 'error' :'fout', 'noScore' :'Geen actieve partituur', 'standard' :'Standaard', 'italic' :'Cursief', 'bold' :'Vet', 'boldItalic' :'Vet Cursief', 'counter1stRest':'Nummer boven de eerste rust ', 'charStyle' :'Tekenstijl', 'fontSize' :'Lettergrootte', 'font' :'Lettertype', 'format' :'Opmaak', 'counter' :'Nummering rusten', 'title' :'Helemaatsrusten doornummeren', 'help' :'Markeer de te nummeren rusten met de cursor en\ \nopen daarna het script.\n\ \nS.v.p alleen opeenvolgende rusten markeren!\n\ \nBij problemen graag een mail naar peter_becker@freenet.de' } try: setStringTable( ("en", english), ("de", german), ("nl", dutch)) except: def tr(s): return german[s] #-------------------------------------------------- import xml.dom, tempfile import tkFont import Tkinter from caplib.capDOM import ScoreChange from xml.dom.minidom import NodeList, Node, Element doc = [] # parentNode von score def latin1_e(u): # WW16.12.21 wie bei Faulenzezaehler; 13.7.21 PB unwirksam, da sonst bei bestimmten Zeichen Absturz return u #return u.encode('Latin-1') def getCursor(): sel = curSelection() result = None if sel == 0: messageBox(tr('error'), tr('noScore')) return result return sel 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 addCount(score,chord,count): global doc, Font, Hoehe, Schriftschnitt #messageBox('XX',str(Font) + '\n' + str(Hoehe) + '\n' + str(Schriftschnitt)) drawObjects = addElementNode(chord,'drawObjects') drawObjectL = getElementObjects(drawObjects.childNodes) ix = 0 while ix < len(drawObjectL): basic = findElementNode(drawObjectL[ix],'basic') if basic <> 'NONE' and basic.hasAttribute('tag'): tag = basic.getAttribute('tag') if tag == '2086-61': drawObjectL[ix].parentNode.removeChild(drawObjectL[ix]) ix = ix+1 drawObj = addNewElementNode(drawObjects,'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) if Font == 'Capella3': ##(ww) capella3 muss höher positioniert werden text.setAttribute('y','-3') else: text.setAttribute('y','-3') text.setAttribute('x','0.1') if int(count) >= 10: text.setAttribute('x','-0.3125') basic = addNewElementNode(drawObj,'basic') basic.setAttribute('tag','2086-61') #messageBox('ADD',str(score) + '\n' + str(chord) + '\n' + str(count)) content.appendChild(score.parentNode.createTextNode(str(count))) return def changeDoc(score): global doc, startcnt doc = score.parentNode sel = getCursor() if sel == None: # return else: selvon = sel[0] selbis = sel[1] ix = 0 while selvon[3]+ix < selbis[3]: system = score.getElementsByTagName('system')[selvon[0]] staff = system.getElementsByTagName('staff')[selvon[1]] voice = staff.getElementsByTagName('voice')[selvon[2]] noteObject = voice.getElementsByTagName('noteObjects')[0] objList = getElementObjects(noteObject.childNodes) if objList.length <= selvon[3]: ix = ix + 1 return obj = objList[selvon[3]+ix] ix = ix + 1 #messageBox('OBJ',str(obj.tagName)) if obj.tagName == 'rest': duration = obj.getElementsByTagName('duration') lng = duration[0].getAttribute('base') if lng == '1' or lng == '1/1': #messageBox('Duration',str(lng)) addCount(score, obj, str(startcnt)) startcnt = startcnt + 1 else: return else: return 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 startcnt, Hoehe, Font, Schriftschnitt 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 = [tr('standard'),tr('italic'),tr('bold'),tr('boldItalic')] sc = '1' # Startcount placeholder0 = Label(' ',width=1) placeholder1 = Label(' ',width=1) placeholder2 = Label(' ',width=1) placeholder3 = Label(' ',width=1) placeholder4 = Label(' ',width=1) #labFont = Label('Schriftart', width = 16) lablSc = Label(tr('counter1stRest'),width=6) editSc = Edit (sc,width=10) subboxSc = HBox([lablSc,editSc],padding=0) box1 = HBox([subboxSc,placeholder4],padding=4) radSchnitt = Radio(Schriftschnitte, value=int(opt.get(tr('charStyle'),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=tr('charStyle')) box1bb = VBox([editHeight], padding = 0,text='') box1bb = HBox([box1bb, placeholder2], padding = 5,text=tr('fontSize')) box1bc = VBox([comboFont], padding = 0,text='') box1bc = HBox([box1bc], padding = 50,text=tr('font')) box1bd = HBox([box1ba,box1bb], padding = 8, text = '') box1be = VBox([box1bd, box1bc], padding = 8,text='') box1b = HBox([box1be], padding = 8,text=tr('format')) mainboxSc = VBox([box1],text=tr('counter')) box = VBox([mainboxSc,box1b,placeholder1],padding=1) dlg = Dialog(tr('title'), box, help=tr('help')) if dlg.run(): startcnt = int(editSc.value()) 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): #global FontList changeDoc(score) if activeScore(): global tempInput, tempOutput #FontList = ['unverändert'] FontList = getFonts() if pqDialog(FontList): activeScore().registerUndo("Pausen_Zaehler") tempInput = tempfile.mktemp('.capx') tempOutput = tempfile.mktemp('.capx') activeScore().write(tempInput) ScoreChange(tempInput, tempOutput) activeScore().read(tempOutput) os.remove(tempInput) os.remove(tempOutput)