# -*- coding: ISO-8859-1 -*- """ capellaScript -- (c) Peter Becker >>> Formatblocker Dieses Skript managt global das Attribut noAdjust und verhindert oder erlaubt so das automatische Formatieren bestimmter Grafikobjekte <<< Format Blocker

This script manages globally the attribute noAdjust and prevents or permits thus the automatic format of definite graphic objects.

Formatblocker

Dieses Skript managt global das Attribut noAdjust und verhindert oder erlaubt so das automatische Formatieren bestimmter Grafikobjekte.

Automatische opmaak blokkeren

Dit script stelt globaal het attribuut noAdjust in en voorkomt zo de automatische opmaak van bepaalde grafische objecten of laat dat juist toe.

History: 17.05.2012 - V 1.0.0 Erste Ausgabe 18.11.2017 - V 1.0.1 WW Internationalisierung 06.08.2020 - V 1.0.2 WW Eingabe wird gespeichert 13.08.2020 - V 1.0.3 WW - 'Help' hinzugefügt (= ± Info-Text) - Text: 'Triller' wurde 'Trillerschlange' 04.11.2020 - V 1.0.4 WW Grafische Notenlinien zugefügt """ english = { 'all' :'All undermentioned objects', 'notelines' :'Graphic Notelines', 'slur' :'Slur', 'crescDecr' :'Crescendo/Decrescendo', 'volta' :'Volta bracket', 'trill' :'Trill with wavy line', 'tupletBracket' :'Tuplet bracket', 'octaveClef' :'Oktave mark', 'wavyLine' :'Wavy line', 'object' :'Object', 'set' :'Set ( prevents automatic format )', 'setBack' :'Set back ( permits automatic format )', 'function' :'Function', 'title' :'Format Blocker Version = ', 'help' :'This script manages in the whole score the attribute \'noAdjust\' \ and thus it prevents or permits the automatic format ( i.e. \ adjustment to the position of the notes ) of definite graphic \ objects.\n\ \nThe option \'All\' concerns the total of the objects \ mentioned in this script.' } german = { 'all' :'Alle unten stehende Objekte', 'notelines' :'Grafische Notenlinien', 'slur' :'Bindebogen', 'crescDecr' :'Crescendo/Decrescendo', 'volta' :'Voltenklammer', 'trill' :'Trillerschlange', 'tupletBracket' :'Triolenklammer', 'octaveClef' :'Oktavklammer', 'wavyLine' :'Schlangenlinie', 'object' :'Objekt', 'set' :'setzen ( verhindert das automatische Formatieren )', 'setBack' :'zurücksetzen ( erlaubt das automatische Formatieren )', 'function' :'Funktion', 'title' :'Formatblocker Version = ', 'help' :'Dieses Skript managt in der ganzen Partitur das Attribut \ \'noAdjust\' und verhindert oder erlaubt so das automatische \ Formatieren ( d.h. Anpassen an die Lage der Noten ) \ bestimmter Grafikobjekte.\n\ \nDie Option \'Alle\' betrifft die Summe der in diesem Skript \ genannten Objekte.' } dutch = { 'all' :'Alle onderstaande objecten', 'notelines' :'Grafische notenlijnen', 'slur' :'Legatoboog', 'crescDecr' :'Crescendo/Decrescendo', 'volta' :'Herhalingshaak', 'trill' :'Triller met golflijn', 'tupletBracket' :'Triolenhaak', 'octaveClef' :'Octaveringshaak', 'wavyLine' :'Golflijn', 'object' :'Object', 'set' :'zetten ( houdt automatische opmaak tegen )', 'setBack' :'terugzetten ( laat automatische opmaak toe )', 'function' :'Functie', 'title' :'Automatische opmaak blokkeren Versie = ', 'help' :'Dit script schakelt in de gehele partituur het attribuut \ \'noAdjust\' in of uit en voorkomt zo de automatische opmaak \ ( d.w.z. aanpassing aan de ligging van de noten ) van \ bepaalde grafische objecten of laat dat juist toe.\n\ \nDe optie \'Alle\' betreft het totaal van de in dit script \ vemelde objecten.' } try: setStringTable( ("en", english), ("de", german), ("nl", dutch)) except: def tr(s): return german[s] #-------------------------------------------------------------------- from xml.dom.minidom import NodeList, Node, Element version = '1.0.4' 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 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 changeDoc(score): global object, function functions = ['notelines','slur','wedge','volta','trill','bracket','octaveClef','wavyLine'] dos = score.getElementsByTagName('drawObj') for do in range(dos.length): obj = dos[do] objList = getElementObjects(obj.childNodes) bas = obj.getElementsByTagName('basic') if not bas: xxx = addElementNode(obj,'basic') bas = obj.getElementsByTagName('basic') name = objList[0].nodeName if name in functions: ix = functions.index(name) #messageBox('bas',str(bas) + ' ' + str(name)) if object == 0: if function == 0: bas[0].setAttribute('noAdjust','true') else: if bas[0].hasAttribute('noAdjust'): bas[0].removeAttribute('noAdjust') else: #messageBox('einzel',str(name) + ' ' + str(ix) + ' ' + str(object+1)) if ix+1 == object: #messageBox('found',str(name) + ' ' + str(ix) + ' ' + str(object)) if function == 0: bas[0].setAttribute('noAdjust','true') else: if bas[0].hasAttribute('noAdjust'): bas[0].removeAttribute('noAdjust') def pqDialog(): global object, function options = ScriptOptions() opt = options.get() Aopt = [tr('all'),tr('notelines'),tr('slur'),tr('crescDecr'),tr('volta'),tr('trill'),tr('tupletBracket'),tr('octaveClef'),tr('wavyLine')] radioA = Radio(Aopt, value=int(opt.get('object', 0)),text=tr('object')) ##(WW) opt.get('pos') in opt.get('object') geändert Bopt = [tr('set'),tr('setBack')] radioB = Radio(Bopt, value=int(opt.get('function', 0)),text=tr('function')) ##(WW) opt.get('ber') in opt.get('function') geändert subbox1 = HBox([radioA,radioB],padding=4) box = VBox([subbox1],padding=4) dlg = Dialog(tr('title') + version, box, help=tr('help')) if dlg.run(): object = radioA.value() function = radioB.value() opt.update(dict(object=object, function=function)) options.set(opt) return True else: return False # Hauptprogramm: from caplib.capDOM import ScoreChange import tempfile class ScoreChange(ScoreChange): def changeScore(self, score): global doc doc = score.parentNode changeDoc(score) if pqDialog(): if activeScore(): activeScore().registerUndo('Formatblocker') tempInput = tempfile.mktemp('.capx') tempOutput = tempfile.mktemp('.capx') activeScore().write(tempInput) ScoreChange(tempInput, tempOutput) activeScore().read(tempOutput) os.remove(tempInput) os.remove(tempOutput)