forked from openlp/openlp
Fixed Tim Bentley's problem with the loading sequence of modules.
Changed some names and quotes in xml1.py. bzr-revno: 415
This commit is contained in:
parent
b525734702
commit
eaa1aa81fd
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE UserProject SYSTEM "UserProject-4.0.dtd">
|
<!DOCTYPE UserProject SYSTEM "UserProject-4.0.dtd">
|
||||||
<!-- eric4 user project file for project openlp.org 2.0 -->
|
<!-- eric4 user project file for project openlp.org 2.0 -->
|
||||||
<!-- Saved: 2009-03-10, 19:41:39 -->
|
<!-- Saved: 2009-03-13, 00:02:12 -->
|
||||||
<!-- Copyright (C) 2009 Raoul Snyman, raoulsnyman@openlp.org -->
|
<!-- Copyright (C) 2009 Raoul Snyman, raoulsnyman@openlp.org -->
|
||||||
<UserProject version="4.0">
|
<UserProject version="4.0">
|
||||||
</UserProject>
|
</UserProject>
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE Tasks SYSTEM "Tasks-4.2.dtd">
|
<!DOCTYPE Tasks SYSTEM "Tasks-4.2.dtd">
|
||||||
<!-- eric4 tasks file for project openlp.org 2.0 -->
|
<!-- eric4 tasks file for project openlp.org 2.0 -->
|
||||||
<!-- Saved: 2009-03-10, 19:41:39 -->
|
<!-- Saved: 2009-03-13, 00:02:14 -->
|
||||||
<Tasks version="4.2">
|
<Tasks version="4.2">
|
||||||
<Task priority="1" completed="False" bugfix="False">
|
<Task priority="1" completed="False" bugfix="False">
|
||||||
<Summary>TODO: what is the tags for bridge, pre-chorus?</Summary>
|
<Summary>TODO: what is the tags for bridge, pre-chorus?</Summary>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE Project SYSTEM "Project-4.6.dtd">
|
<!DOCTYPE Project SYSTEM "Project-4.6.dtd">
|
||||||
<!-- eric4 project file for project openlp.org 2.0 -->
|
<!-- eric4 project file for project openlp.org 2.0 -->
|
||||||
<!-- Saved: 2009-03-09, 22:34:51 -->
|
<!-- Saved: 2009-03-11, 21:25:53 -->
|
||||||
<!-- Copyright (C) 2009 Raoul Snyman, raoulsnyman@openlp.org -->
|
<!-- Copyright (C) 2009 Raoul Snyman, raoulsnyman@openlp.org -->
|
||||||
<Project version="4.6">
|
<Project version="4.6">
|
||||||
<Language>en</Language>
|
<Language>en</Language>
|
||||||
@ -152,11 +152,7 @@
|
|||||||
<Source>openlp/plugins/custom/lib/manager.py</Source>
|
<Source>openlp/plugins/custom/lib/manager.py</Source>
|
||||||
<Source>openlp/plugins/images/lib/mediaitem.py</Source>
|
<Source>openlp/plugins/images/lib/mediaitem.py</Source>
|
||||||
<Source>openlp/plugins/songs/lib/mediaitem.py</Source>
|
<Source>openlp/plugins/songs/lib/mediaitem.py</Source>
|
||||||
<Source>resources/forms/Ui_editsongdialog.py</Source>
|
<Source>xml1.py</Source>
|
||||||
<Source>resources/forms/Ui_editversedialog.py</Source>
|
|
||||||
<Source>resources/forms/Ui_settings.py</Source>
|
|
||||||
<Source>resources/forms/Ui_authorsdialog.py</Source>
|
|
||||||
<Source>resources/forms/Ui_songbookdialog.py</Source>
|
|
||||||
</Sources>
|
</Sources>
|
||||||
<Forms>
|
<Forms>
|
||||||
<Form>resources/forms/openlpexportform.ui</Form>
|
<Form>resources/forms/openlpexportform.ui</Form>
|
||||||
|
@ -18,10 +18,10 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|||||||
Place, Suite 330, Boston, MA 02111-1307 USA
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from textlistdata import TextListData
|
||||||
from manager import CustomManager
|
from manager import CustomManager
|
||||||
from customtab import CustomTab
|
from customtab import CustomTab
|
||||||
from mediaitem import CustomMediaItem
|
from mediaitem import CustomMediaItem
|
||||||
from textlistdata import TextListData
|
|
||||||
|
|
||||||
__all__ = ['CustomManager', 'CustomTab', 'CustomMediaItem', 'TextListData']
|
__all__ = ['CustomManager', 'CustomTab', 'CustomMediaItem', 'TextListData']
|
||||||
|
|
||||||
|
53
xml1.py
53
xml1.py
@ -1,4 +1,4 @@
|
|||||||
from xml.dom.minidom import Document
|
from xml.dom.minidom import Document
|
||||||
from xml.etree.ElementTree import ElementTree, XML, dump
|
from xml.etree.ElementTree import ElementTree, XML, dump
|
||||||
"""
|
"""
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
@ -13,67 +13,67 @@ from xml.etree.ElementTree import ElementTree, XML, dump
|
|||||||
"""
|
"""
|
||||||
class SongXMLBuilder():
|
class SongXMLBuilder():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Create the minidom document
|
# Create the minidom document
|
||||||
self.song_xml = Document()
|
self.song_xml = Document()
|
||||||
|
|
||||||
def new_document(self):
|
def new_document(self):
|
||||||
# Create the <song> base element
|
# Create the <song> base element
|
||||||
self.song = self.song_xml.createElement("song")
|
self.song = self.song_xml.createElement(u'song')
|
||||||
self.song_xml.appendChild(self.song)
|
self.song_xml.appendChild(self.song)
|
||||||
self.song.setAttribute("version", "1.0")
|
self.song.setAttribute(u'version', u'1.0')
|
||||||
|
|
||||||
def add_lyrics_to_song(self):
|
def add_lyrics_to_song(self):
|
||||||
# Create the main <lyrics> element
|
# Create the main <lyrics> element
|
||||||
self.lyrics = self.song_xml.createElement("lyrics")
|
self.lyrics = self.song_xml.createElement(u'lyrics')
|
||||||
self.lyrics.setAttribute("language", "en")
|
self.lyrics.setAttribute(u'language', u'en')
|
||||||
self.song.appendChild(self.lyrics)
|
self.song.appendChild(self.lyrics)
|
||||||
|
|
||||||
def add_verse_to_lyrics(self, type, number, content):
|
def add_verse_to_lyrics(self, type, label, content):
|
||||||
"""
|
"""
|
||||||
type - type of verse (Chorus, Verse , Bridge, Custom etc
|
type - type of verse (Chorus, Verse , Bridge, Custom etc
|
||||||
number - number of item eg verse 1
|
label - label of item eg verse 1
|
||||||
content - the text to be stored
|
content - the text to be stored
|
||||||
"""
|
"""
|
||||||
verse = self.song_xml.createElement("verse")
|
verse = self.song_xml.createElement(u'verse')
|
||||||
verse.setAttribute("type", type)
|
verse.setAttribute(u'type', type)
|
||||||
verse.setAttribute('label', number)
|
verse.setAttribute(u'label', label)
|
||||||
self.lyrics.appendChild(verse)
|
self.lyrics.appendChild(verse)
|
||||||
|
|
||||||
# add data as a CDATA section
|
# add data as a CDATA section
|
||||||
cds = self.song_xml.createCDATASection(content)
|
cds = self.song_xml.createCDATASection(content)
|
||||||
verse.appendChild(cds)
|
verse.appendChild(cds)
|
||||||
|
|
||||||
def dump_xml(self):
|
def dump_xml(self):
|
||||||
# Debugging aid to see what we have
|
# Debugging aid to see what we have
|
||||||
print self.song_xml.toprettyxml(indent=" ")
|
print self.song_xml.toprettyxml(indent=u' ')
|
||||||
|
|
||||||
def extract_xml(self):
|
def extract_xml(self):
|
||||||
# Print our newly created XML
|
# Print our newly created XML
|
||||||
return self.song_xml.toxml()
|
return self.song_xml.toxml()
|
||||||
|
|
||||||
class SongXMLParser():
|
class SongXMLParser():
|
||||||
def __init__(self, xml):
|
def __init__(self, xml):
|
||||||
self.song_xml = ElementTree(element=XML(xml))
|
self.song_xml = ElementTree(element=XML(xml))
|
||||||
|
|
||||||
def get_verses(self):
|
def get_verses(self):
|
||||||
#return a list of verse's and attributes
|
#return a list of verse's and attributes
|
||||||
iter=self.song_xml.getiterator()
|
iter=self.song_xml.getiterator()
|
||||||
verse_list = []
|
verse_list = []
|
||||||
for element in iter:
|
for element in iter:
|
||||||
if element.tag == 'verse':
|
if element.tag == u'verse':
|
||||||
verse_list.append([element.attrib, element.text])
|
verse_list.append([element.attrib, element.text])
|
||||||
return verse_list
|
return verse_list
|
||||||
|
|
||||||
def dump_xml(self):
|
def dump_xml(self):
|
||||||
# Debugging aid to see what we have
|
# Debugging aid to see what we have
|
||||||
print dump(self.song_xml)
|
print dump(self.song_xml)
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__ == '__main__':
|
||||||
sxml=SongXMLBuilder()
|
sxml=SongXMLBuilder()
|
||||||
sxml.new_document()
|
sxml.new_document()
|
||||||
sxml.add_lyrics_to_song()
|
sxml.add_lyrics_to_song()
|
||||||
sxml.add_verse_to_lyrics(u'chorus', u'1', u'The is\n is \nsome\n text')
|
sxml.add_verse_to_lyrics(u'chorus', u'1', u'The is\n is \nsome\n text')
|
||||||
sxml.add_verse_to_lyrics(u'verse', u'2', u'The is\n is \nmore\n text')
|
sxml.add_verse_to_lyrics(u'verse', u'2', u'The is\n is \nmore\n text')
|
||||||
sxml.dump_xml()
|
sxml.dump_xml()
|
||||||
x1 = sxml.extract_xml()
|
x1 = sxml.extract_xml()
|
||||||
print x1
|
print x1
|
||||||
@ -81,6 +81,3 @@ if __name__=="__main__":
|
|||||||
spra=SongXMLParser(x1)
|
spra=SongXMLParser(x1)
|
||||||
vl = spra.get_verses()
|
vl = spra.get_verses()
|
||||||
print vl
|
print vl
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user