Skip to content

Instantly share code, notes, and snippets.

@lasconic
Created December 21, 2018 16:02
Show Gist options
  • Save lasconic/167157e8e3f32329028726c890e8b4a0 to your computer and use it in GitHub Desktop.
Save lasconic/167157e8e3f32329028726c890e8b4a0 to your computer and use it in GitHub Desktop.
generate .h file for MuseScore's tours
#!/usr/bin/env python
import os
import xml.etree.ElementTree as ET
def addMessage(f, text, comment=''):
text = text.replace('"', r'\"')
if (comment):
f.write('QT_TRANSLATE_NOOP3("TourXML", "' + text.encode('utf8') + '", "' + comment.encode('utf8') + '"),\n')
else:
f.write('QT_TRANSLATE_NOOP("TourXML", "' + text.encode('utf8') + '"),\n')
scriptPath = os.path.dirname(os.path.realpath(__file__))
#find all tours
tours = []
for file in os.listdir(scriptPath):
if file.endswith(".tour"):
print(os.path.join(scriptPath, file))
tours.append(os.path.join(scriptPath, file))
# create tourxml.h
f = open(scriptPath + '/' + 'tourxml.h', 'w')
for tour in tours:
tree = ET.parse(tour)
root = tree.getroot()
tourName = root.attrib["name"]
for child in root:
if child.tag == "Message":
t = child.find("Text")
print t.text
addMessage(f, t.text, tourName)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment