forked from openlp/openlp
Started fixing up docstrings and doing some more of a code cleanup.
This commit is contained in:
parent
c8d5b7acb2
commit
e66fa9b87d
42
cnvdb.py
42
cnvdb.py
@ -21,27 +21,35 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
import codecs
|
import codecs
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
def convert_file(self, inname, outname):
|
||||||
|
"""
|
||||||
|
Convert a file from another encoding into UTF-8.
|
||||||
|
|
||||||
class Convert():
|
``inname``
|
||||||
def __init__(self):
|
The name of the file to be opened and converted.
|
||||||
pass
|
|
||||||
|
|
||||||
def process(self, inname, outname):
|
``outname``
|
||||||
infile = codecs.open(inname, 'r', encoding='iso-8859-1')
|
The output file name.
|
||||||
writefile = codecs.open(outname, 'w', encoding='utf-8')
|
"""
|
||||||
for line in infile:
|
infile = codecs.open(inname, 'r', encoding='iso-8859-1')
|
||||||
#replace the quotes with quotes
|
writefile = codecs.open(outname, 'w', encoding='utf-8')
|
||||||
line = line.replace(u'\'\'', u'\'')
|
for line in infile:
|
||||||
writefile.write(line)
|
#replace the quotes with quotes
|
||||||
infile.close()
|
line = line.replace(u'\'\'', u'\'')
|
||||||
writefile.close()
|
writefile.write(line)
|
||||||
|
infile.close()
|
||||||
|
writefile.close()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
"""
|
||||||
|
Run the conversion script.
|
||||||
|
"""
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
print 'No action specified.'
|
print 'No action specified.'
|
||||||
sys.exit()
|
sys.exit()
|
||||||
print u'Uncode conversion '
|
print 'Uncode conversion:'
|
||||||
print u'Input file = ', sys.argv[1:]
|
print 'Input file = ', sys.argv[1]
|
||||||
print u'Output file = ', sys.argv[2:]
|
print 'Output file = ', sys.argv[2]
|
||||||
mig = Convert()
|
print 'Converting...'
|
||||||
mig.process(sys.argv[1:],sys.argv[2:])
|
convert_file(sys.argv[1], sys.argv[2])
|
||||||
|
print 'Done.'
|
||||||
|
73
demo.py
73
demo.py
@ -16,12 +16,14 @@ 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 openlp.core import Renderer
|
|
||||||
from openlp.theme import Theme
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from PyQt4 import QtGui, QtCore
|
from PyQt4 import QtGui, QtCore
|
||||||
|
|
||||||
|
from openlp.core import Renderer
|
||||||
|
from openlp.theme import Theme
|
||||||
|
|
||||||
words="""How sweet the name of Jesus sounds
|
words="""How sweet the name of Jesus sounds
|
||||||
In a believer's ear!
|
In a believer's ear!
|
||||||
It soothes his sorrows, heals his wounds,
|
It soothes his sorrows, heals his wounds,
|
||||||
@ -29,53 +31,74 @@ And drives away his fear.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
class TstFrame(QtGui.QMainWindow):
|
class TstFrame(QtGui.QMainWindow):
|
||||||
""" We simply derive a new class of QMainWindow"""
|
"""
|
||||||
|
We simply derive a new class of QMainWindow
|
||||||
# {{{ init
|
"""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Create the DemoPanel."""
|
"""
|
||||||
|
Create the DemoPanel.
|
||||||
|
"""
|
||||||
QtGui.QMainWindow.__init__(self)
|
QtGui.QMainWindow.__init__(self)
|
||||||
self.resize(1024,768)
|
self.resize(1024, 768)
|
||||||
self.size=(1024,768)
|
self.size = (1024, 768)
|
||||||
|
self.v = 0
|
||||||
self.v=0
|
self._font = QtGui.QFont(u'Decorative', 32)
|
||||||
self._font=QtGui.QFont(u'Decorative', 32)
|
self.framecount = 0
|
||||||
self.framecount=0
|
|
||||||
self.totaltime = 0
|
self.totaltime = 0
|
||||||
self.dir=1
|
self.dir = 1
|
||||||
self.y=1
|
self.y = 1
|
||||||
# self.startTimer(10)
|
self.frame = QtGui.QFrame()
|
||||||
self.frame=QtGui.QFrame()
|
|
||||||
self.setCentralWidget(self.frame)
|
self.setCentralWidget(self.frame)
|
||||||
self.r=Renderer()
|
self.r = Renderer()
|
||||||
self.r.set_theme(Theme(u'demo_theme.xml'))
|
self.r.set_theme(Theme(u'demo_theme.xml'))
|
||||||
|
|
||||||
self.r.set_text_rectangle(self.frame.frameRect())
|
self.r.set_text_rectangle(self.frame.frameRect())
|
||||||
self.r.set_paint_dest(self)
|
self.r.set_paint_dest(self)
|
||||||
self.r.set_words_openlp(words)
|
self.r.set_words_openlp(words)
|
||||||
|
|
||||||
def timerEvent(self, event):
|
def timerEvent(self, event):
|
||||||
|
"""
|
||||||
|
Update the form on a timer event.
|
||||||
|
|
||||||
|
``event``
|
||||||
|
The event which triggered this update.
|
||||||
|
"""
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def paintEvent(self, event):
|
def paintEvent(self, event):
|
||||||
|
"""
|
||||||
|
Repaint the canvas.
|
||||||
|
|
||||||
|
``event``
|
||||||
|
The event which triggered this repaint.
|
||||||
|
"""
|
||||||
self.r.set_text_rectangle(self.frame.frameRect())
|
self.r.set_text_rectangle(self.frame.frameRect())
|
||||||
self.r.scale_bg_image()
|
self.r.scale_bg_image()
|
||||||
t1=time.clock()
|
t1 = time.clock()
|
||||||
self.r.render_screen(0)
|
self.r.render_screen(0)
|
||||||
t2 = time.clock()
|
t2 = time.clock()
|
||||||
deltat=t2-t1
|
deltat = t2 - t1
|
||||||
self.totaltime += deltat
|
self.totaltime += deltat
|
||||||
self.framecount+=1
|
self.framecount += 1
|
||||||
print "Timing result: %5.3ffps" %(self.framecount/float(self.totaltime))
|
print "Timing result: %5.3ffps" %(self.framecount/float(self.totaltime))
|
||||||
|
|
||||||
# }}}
|
|
||||||
|
|
||||||
class Demo:
|
class Demo(object):
|
||||||
|
"""
|
||||||
|
The demo application itself.
|
||||||
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Construct the application.
|
||||||
|
"""
|
||||||
app = QtGui.QApplication(sys.argv)
|
app = QtGui.QApplication(sys.argv)
|
||||||
main=TstFrame()
|
main = TstFrame()
|
||||||
main.show()
|
main.show()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
t=Demo()
|
"""
|
||||||
|
Run the demo.
|
||||||
|
"""
|
||||||
|
t = Demo()
|
||||||
|
18
openlp.pyw
18
openlp.pyw
@ -23,22 +23,29 @@ import sys
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
from openlp.core.lib import Receiver
|
from openlp.core.lib import Receiver
|
||||||
|
from openlp.core.resources import *
|
||||||
|
from openlp.core.ui import MainWindow, SplashScreen
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG,
|
logging.basicConfig(level=logging.DEBUG,
|
||||||
format=u'%(asctime)s:%(msecs)3d %(name)-15s %(levelname)-8s %(message)s',
|
format=u'%(asctime)s:%(msecs)3d %(name)-15s %(levelname)-8s %(message)s',
|
||||||
datefmt=u'%m-%d %H:%M:%S', filename=u'openlp.log', filemode=u'w')
|
datefmt=u'%m-%d %H:%M:%S', filename=u'openlp.log', filemode=u'w')
|
||||||
|
|
||||||
from openlp.core.resources import *
|
|
||||||
from openlp.core.ui import MainWindow, SplashScreen
|
|
||||||
|
|
||||||
class OpenLP(QtGui.QApplication):
|
class OpenLP(QtGui.QApplication):
|
||||||
|
"""
|
||||||
|
The core application class. This class inherits from Qt's QApplication
|
||||||
|
class in order to provide the core of the application.
|
||||||
|
"""
|
||||||
global log
|
global log
|
||||||
log = logging.getLogger(u'OpenLP Application')
|
log = logging.getLogger(u'OpenLP Application')
|
||||||
log.info(u'Application Loaded')
|
log.info(u'Application Loaded')
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
#set the default string encoding
|
"""
|
||||||
|
Run the OpenLP application.
|
||||||
|
"""
|
||||||
|
#set the default string encoding
|
||||||
try:
|
try:
|
||||||
sys.setappdefaultencoding(u'utf-8')
|
sys.setappdefaultencoding(u'utf-8')
|
||||||
except:
|
except:
|
||||||
@ -68,5 +75,8 @@ class OpenLP(QtGui.QApplication):
|
|||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
|
||||||
if __name__ == u'__main__':
|
if __name__ == u'__main__':
|
||||||
|
"""
|
||||||
|
Instantiate and run the application.
|
||||||
|
"""
|
||||||
app = OpenLP(sys.argv)
|
app = OpenLP(sys.argv)
|
||||||
app.run()
|
app.run()
|
||||||
|
@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License along with
|
|||||||
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
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 settingsmanager import SettingsManager
|
from settingsmanager import SettingsManager
|
||||||
from openlp.core.lib.pluginmanager import PluginManager
|
from openlp.core.lib.pluginmanager import PluginManager
|
||||||
|
|
||||||
|
@ -19,11 +19,13 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
|
|
||||||
For XML Schema see wiki.openlp.org
|
For XML Schema see wiki.openlp.org
|
||||||
"""
|
"""
|
||||||
import os, os.path
|
import os
|
||||||
from openlp.core.lib import str_to_bool
|
|
||||||
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
|
||||||
|
|
||||||
|
from openlp.core.lib import str_to_bool
|
||||||
|
|
||||||
blankthemexml=\
|
blankthemexml=\
|
||||||
'''<?xml version="1.0" encoding="iso-8859-1"?>
|
'''<?xml version="1.0" encoding="iso-8859-1"?>
|
||||||
<theme version="1.0">
|
<theme version="1.0">
|
||||||
@ -62,26 +64,38 @@ blankthemexml=\
|
|||||||
</theme>
|
</theme>
|
||||||
'''
|
'''
|
||||||
|
|
||||||
class ThemeXML():
|
class ThemeXML(object):
|
||||||
|
"""
|
||||||
|
A class to encapsulate the Theme XML.
|
||||||
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
"""
|
||||||
|
Initialise the theme object.
|
||||||
|
"""
|
||||||
# Create the minidom document
|
# Create the minidom document
|
||||||
self.theme_xml = Document()
|
self.theme_xml = Document()
|
||||||
|
|
||||||
def extend_image_filename(self, path):
|
def extend_image_filename(self, path):
|
||||||
"""
|
"""
|
||||||
Add the path name to the image name so the background can be rendered.
|
Add the path name to the image name so the background can be rendered.
|
||||||
|
|
||||||
|
``path``
|
||||||
|
The path name to be added.
|
||||||
"""
|
"""
|
||||||
if self.background_filename is not None:
|
if self.background_filename is not None and path is not None:
|
||||||
self.background_filename = os.path.join(path, self.theme_name, self.background_filename)
|
self.background_filename = os.path.join(path, self.theme_name,
|
||||||
|
self.background_filename)
|
||||||
|
|
||||||
def new_document(self, name):
|
def new_document(self, name):
|
||||||
|
"""
|
||||||
|
Create a new theme XML document.
|
||||||
|
"""
|
||||||
self.theme = self.theme_xml.createElement(u'theme')
|
self.theme = self.theme_xml.createElement(u'theme')
|
||||||
self.theme_xml.appendChild(self.theme)
|
self.theme_xml.appendChild(self.theme)
|
||||||
self.theme.setAttribute(u'version', u'1.0')
|
self.theme.setAttribute(u'version', u'1.0')
|
||||||
|
|
||||||
self.name = self.theme_xml.createElement(u'name')
|
self.name = self.theme_xml.createElement(u'name')
|
||||||
ctn = self.theme_xml.createTextNode(name)
|
text_node = self.theme_xml.createTextNode(name)
|
||||||
self.name.appendChild(ctn)
|
self.name.appendChild(text_node)
|
||||||
self.theme.appendChild(self.name)
|
self.theme.appendChild(self.name)
|
||||||
|
|
||||||
def add_background_transparent(self):
|
def add_background_transparent(self):
|
||||||
@ -95,23 +109,33 @@ class ThemeXML():
|
|||||||
def add_background_solid(self, bkcolor):
|
def add_background_solid(self, bkcolor):
|
||||||
"""
|
"""
|
||||||
Add a Solid background.
|
Add a Solid background.
|
||||||
|
|
||||||
|
``bkcolor``
|
||||||
|
The color of the background.
|
||||||
"""
|
"""
|
||||||
background = self.theme_xml.createElement(u'background')
|
background = self.theme_xml.createElement(u'background')
|
||||||
background.setAttribute(u'mode', u'opaque')
|
background.setAttribute(u'mode', u'opaque')
|
||||||
background.setAttribute(u'type', u'solid')
|
background.setAttribute(u'type', u'solid')
|
||||||
self.theme.appendChild(background)
|
self.theme.appendChild(background)
|
||||||
|
|
||||||
self.child_element(background, u'color', bkcolor)
|
self.child_element(background, u'color', bkcolor)
|
||||||
|
|
||||||
def add_background_gradient(self, startcolor, endcolor, direction):
|
def add_background_gradient(self, startcolor, endcolor, direction):
|
||||||
"""
|
"""
|
||||||
Add a gradient background.
|
Add a gradient background.
|
||||||
|
|
||||||
|
``startcolor``
|
||||||
|
The gradient's starting colour.
|
||||||
|
|
||||||
|
``endcolor``
|
||||||
|
The gradient's ending colour.
|
||||||
|
|
||||||
|
``direction``
|
||||||
|
The direction of the gradient.
|
||||||
"""
|
"""
|
||||||
background = self.theme_xml.createElement(u'background')
|
background = self.theme_xml.createElement(u'background')
|
||||||
background.setAttribute(u'mode', u'opaque')
|
background.setAttribute(u'mode', u'opaque')
|
||||||
background.setAttribute(u'type', u'gradient')
|
background.setAttribute(u'type', u'gradient')
|
||||||
self.theme.appendChild(background)
|
self.theme.appendChild(background)
|
||||||
|
|
||||||
# Create startColor element
|
# Create startColor element
|
||||||
self.child_element(background, u'startColor', startcolor)
|
self.child_element(background, u'startColor', startcolor)
|
||||||
# Create endColor element
|
# Create endColor element
|
||||||
@ -122,39 +146,63 @@ class ThemeXML():
|
|||||||
def add_background_image(self, filename):
|
def add_background_image(self, filename):
|
||||||
"""
|
"""
|
||||||
Add a image background.
|
Add a image background.
|
||||||
|
|
||||||
|
``filename``
|
||||||
|
The file name of the image.
|
||||||
"""
|
"""
|
||||||
background = self.theme_xml.createElement(u'background')
|
background = self.theme_xml.createElement(u'background')
|
||||||
background.setAttribute(u'mode', u'opaque')
|
background.setAttribute(u'mode', u'opaque')
|
||||||
background.setAttribute(u'type', u'image')
|
background.setAttribute(u'type', u'image')
|
||||||
self.theme.appendChild(background)
|
self.theme.appendChild(background)
|
||||||
|
|
||||||
#Create Filename element
|
#Create Filename element
|
||||||
self.child_element(background, u'filename', filename)
|
self.child_element(background, u'filename', filename)
|
||||||
|
|
||||||
def add_font(self, name, color, proportion, override, fonttype=u'main', xpos=0, ypos=0 ,width=0, height=0):
|
def add_font(self, name, color, proportion, override, fonttype=u'main',
|
||||||
|
xpos=0, ypos=0, width=0, height=0):
|
||||||
"""
|
"""
|
||||||
Add a Font.
|
Add a Font.
|
||||||
|
|
||||||
|
``name``
|
||||||
|
The name of the font.
|
||||||
|
|
||||||
|
``color``
|
||||||
|
The colour of the font.
|
||||||
|
|
||||||
|
``proportion``
|
||||||
|
The size of the font.
|
||||||
|
|
||||||
|
``override``
|
||||||
|
Whether or not to override the default positioning of the theme.
|
||||||
|
|
||||||
|
``fonttype``
|
||||||
|
The type of font, ``main`` or ``footer``. Defaults to ``main``.
|
||||||
|
|
||||||
|
``xpos``
|
||||||
|
The X position of the text block.
|
||||||
|
|
||||||
|
``ypos``
|
||||||
|
The Y position of the text block.
|
||||||
|
|
||||||
|
``width``
|
||||||
|
The width of the text block.
|
||||||
|
|
||||||
|
``height``
|
||||||
|
The height of the text block.
|
||||||
"""
|
"""
|
||||||
background = self.theme_xml.createElement(u'font')
|
background = self.theme_xml.createElement(u'font')
|
||||||
background.setAttribute(u'type',fonttype)
|
background.setAttribute(u'type',fonttype)
|
||||||
self.theme.appendChild(background)
|
self.theme.appendChild(background)
|
||||||
|
|
||||||
#Create Font name element
|
#Create Font name element
|
||||||
self.child_element(background, u'name', name)
|
self.child_element(background, u'name', name)
|
||||||
|
|
||||||
#Create Font color element
|
#Create Font color element
|
||||||
self.child_element(background, u'color', color)
|
self.child_element(background, u'color', color)
|
||||||
|
|
||||||
#Create Proportion name element
|
#Create Proportion name element
|
||||||
self.child_element(background, u'proportion', proportion)
|
self.child_element(background, u'proportion', proportion)
|
||||||
|
|
||||||
#Create Proportion name element
|
#Create Proportion name element
|
||||||
self.child_element(background, u'proportion', proportion)
|
self.child_element(background, u'proportion', proportion)
|
||||||
|
|
||||||
#Create Location element
|
#Create Location element
|
||||||
element = self.theme_xml.createElement(u'location')
|
element = self.theme_xml.createElement(u'location')
|
||||||
element.setAttribute(u'override',override)
|
element.setAttribute(u'override',override)
|
||||||
|
|
||||||
if override == u'True':
|
if override == u'True':
|
||||||
element.setAttribute(u'x', xpos)
|
element.setAttribute(u'x', xpos)
|
||||||
element.setAttribute(u'y', ypos)
|
element.setAttribute(u'y', ypos)
|
||||||
@ -162,79 +210,120 @@ class ThemeXML():
|
|||||||
element.setAttribute(u'height', height)
|
element.setAttribute(u'height', height)
|
||||||
background.appendChild(element)
|
background.appendChild(element)
|
||||||
|
|
||||||
def add_display(self, shadow, shadowColor, outline, outlineColor, horizontal, vertical, wrap):
|
def add_display(self, shadow, shadow_color, outline, outline_color,
|
||||||
|
horizontal, vertical, wrap):
|
||||||
"""
|
"""
|
||||||
Add a Display options.
|
Add a Display options.
|
||||||
|
|
||||||
|
``shadow``
|
||||||
|
Whether or not to show a shadow.
|
||||||
|
|
||||||
|
``shadow_color``
|
||||||
|
The colour of the shadow.
|
||||||
|
|
||||||
|
``outline``
|
||||||
|
Whether or not to show an outline.
|
||||||
|
|
||||||
|
``outline_color``
|
||||||
|
The colour of the outline.
|
||||||
|
|
||||||
|
``horizontal``
|
||||||
|
The horizontal alignment of the text.
|
||||||
|
|
||||||
|
``vertical``
|
||||||
|
The vertical alignment of the text.
|
||||||
|
|
||||||
|
``wrap``
|
||||||
|
Wrap style.
|
||||||
"""
|
"""
|
||||||
background = self.theme_xml.createElement(u'display')
|
background = self.theme_xml.createElement(u'display')
|
||||||
self.theme.appendChild(background)
|
self.theme.appendChild(background)
|
||||||
|
# Shadow
|
||||||
tagElement = self.theme_xml.createElement(u'shadow')
|
element = self.theme_xml.createElement(u'shadow')
|
||||||
|
element.setAttribute(u'color', shadow_color)
|
||||||
tagElement.setAttribute(u'color',shadowColor)
|
value = self.theme_xml.createTextNode(shadow)
|
||||||
tagValue = self.theme_xml.createTextNode(shadow)
|
element.appendChild(value)
|
||||||
tagElement.appendChild(tagValue)
|
background.appendChild(element)
|
||||||
background.appendChild(tagElement)
|
# Outline
|
||||||
|
element = self.theme_xml.createElement(u'outline')
|
||||||
tagElement = self.theme_xml.createElement(u'outline')
|
element.setAttribute(u'color', outline_color)
|
||||||
tagElement.setAttribute(u'color',outlineColor)
|
value = self.theme_xml.createTextNode(outline)
|
||||||
tagValue = self.theme_xml.createTextNode(outline)
|
element.appendChild(value)
|
||||||
tagElement.appendChild(tagValue)
|
background.appendChild(element)
|
||||||
background.appendChild(tagElement)
|
# Horizontal alignment
|
||||||
|
element = self.theme_xml.createElement(u'horizontalAlign')
|
||||||
tagElement = self.theme_xml.createElement(u'horizontalAlign')
|
value = self.theme_xml.createTextNode(horizontal)
|
||||||
tagValue = self.theme_xml.createTextNode(horizontal)
|
element.appendChild(value)
|
||||||
tagElement.appendChild(tagValue)
|
background.appendChild(element)
|
||||||
background.appendChild(tagElement)
|
# Vertical alignment
|
||||||
|
element = self.theme_xml.createElement(u'verticalAlign')
|
||||||
tagElement = self.theme_xml.createElement(u'verticalAlign')
|
value = self.theme_xml.createTextNode(vertical)
|
||||||
tagValue = self.theme_xml.createTextNode(vertical)
|
element.appendChild(value)
|
||||||
tagElement.appendChild(tagValue)
|
background.appendChild(element)
|
||||||
background.appendChild(tagElement)
|
# Wrap style
|
||||||
|
element = self.theme_xml.createElement(u'wrapStyle')
|
||||||
tagElement = self.theme_xml.createElement(u'wrapStyle')
|
value = self.theme_xml.createTextNode(wrap)
|
||||||
tagValue = self.theme_xml.createTextNode(wrap)
|
element.appendChild(value)
|
||||||
tagElement.appendChild(tagValue)
|
background.appendChild(element)
|
||||||
background.appendChild(tagElement)
|
|
||||||
|
|
||||||
def child_element(self, element, tag, value):
|
def child_element(self, element, tag, value):
|
||||||
|
"""
|
||||||
|
Generic child element creator.
|
||||||
|
"""
|
||||||
child = self.theme_xml.createElement(tag)
|
child = self.theme_xml.createElement(tag)
|
||||||
child.appendChild(self.theme_xml.createTextNode(value))
|
child.appendChild(self.theme_xml.createTextNode(value))
|
||||||
element.appendChild(child)
|
element.appendChild(child)
|
||||||
return child
|
return child
|
||||||
|
|
||||||
def dump_xml(self):
|
def dump_xml(self):
|
||||||
|
"""
|
||||||
|
Dump the XML to file.
|
||||||
|
"""
|
||||||
# Debugging aid to see what we have
|
# Debugging aid to see what we have
|
||||||
print self.theme_xml.toprettyxml(indent=u' ')
|
print self.theme_xml.toprettyxml(indent=u' ')
|
||||||
|
|
||||||
def extract_xml(self):
|
def extract_xml(self):
|
||||||
|
"""
|
||||||
|
Pull out the XML string.
|
||||||
|
"""
|
||||||
# Print our newly created XML
|
# Print our newly created XML
|
||||||
return self.theme_xml.toxml()
|
return self.theme_xml.toxml()
|
||||||
|
|
||||||
def parse(self, xml):
|
def parse(self, xml):
|
||||||
self.baseParseXml()
|
"""
|
||||||
|
Read in an XML string and parse it.
|
||||||
|
|
||||||
|
``xml``
|
||||||
|
The XML string to parse.
|
||||||
|
"""
|
||||||
|
self.base_parse_xml()
|
||||||
self.parse_xml(xml)
|
self.parse_xml(xml)
|
||||||
self.theme_filename_extended = False
|
self.theme_filename_extended = False
|
||||||
|
|
||||||
def baseParseXml(self):
|
def base_parse_xml(self):
|
||||||
|
"""
|
||||||
|
Pull in the blank theme XML as a starting point.
|
||||||
|
"""
|
||||||
self.parse_xml(blankthemexml)
|
self.parse_xml(blankthemexml)
|
||||||
|
|
||||||
def parse_xml(self, xml):
|
def parse_xml(self, xml):
|
||||||
|
"""
|
||||||
|
Parse an XML string.
|
||||||
|
|
||||||
|
``xml``
|
||||||
|
The XML string to parse.
|
||||||
|
"""
|
||||||
theme_xml = ElementTree(element=XML(xml))
|
theme_xml = ElementTree(element=XML(xml))
|
||||||
iter = theme_xml.getiterator()
|
iter = theme_xml.getiterator()
|
||||||
master = u''
|
master = u''
|
||||||
for element in iter:
|
for element in iter:
|
||||||
#print element.tag, element.text
|
|
||||||
if len(element.getchildren()) > 0:
|
if len(element.getchildren()) > 0:
|
||||||
master = element.tag + u'_'
|
master = element.tag + u'_'
|
||||||
if len(element.attrib) > 0:
|
if len(element.attrib) > 0:
|
||||||
#print "D", element.tag , element.attrib
|
|
||||||
for e in element.attrib.iteritems():
|
for e in element.attrib.iteritems():
|
||||||
#print "A", master, e[0], e[1]
|
|
||||||
if master == u'font_' and e[0] == u'type':
|
if master == u'font_' and e[0] == u'type':
|
||||||
master += e[1] + u'_'
|
master += e[1] + u'_'
|
||||||
elif master == u'display_' and (element.tag == u'shadow' or element.tag == u'outline'):
|
elif master == u'display_' and (element.tag == u'shadow' or element.tag == u'outline'):
|
||||||
#print "b", master, element.tag, element.text, e[0], e[1]
|
|
||||||
et = str_to_bool(element.text)
|
et = str_to_bool(element.text)
|
||||||
setattr(self, master + element.tag , et)
|
setattr(self, master + element.tag , et)
|
||||||
setattr(self, master + element.tag + u'_'+ e[0], e[1])
|
setattr(self, master + element.tag + u'_'+ e[0], e[1])
|
||||||
@ -245,12 +334,14 @@ class ThemeXML():
|
|||||||
e1 = str_to_bool(e[1])
|
e1 = str_to_bool(e[1])
|
||||||
setattr(self, field, e1)
|
setattr(self, field, e1)
|
||||||
else:
|
else:
|
||||||
#print "c", element.tag, element.text
|
|
||||||
if element.tag is not None:
|
if element.tag is not None:
|
||||||
field = master + element.tag
|
field = master + element.tag
|
||||||
setattr(self, field, element.text)
|
setattr(self, field, element.text)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
"""
|
||||||
|
Return a string representation of this object.
|
||||||
|
"""
|
||||||
s = u''
|
s = u''
|
||||||
for k in dir(self):
|
for k in dir(self):
|
||||||
if k[0:1] != u'_':
|
if k[0:1] != u'_':
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
||||||
"""
|
"""
|
||||||
@ -19,15 +18,19 @@ 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
|
||||||
"""
|
"""
|
||||||
import types
|
import types
|
||||||
|
import logging
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
import logging
|
|
||||||
|
|
||||||
class OpenLPToolbar(QtGui.QToolBar):
|
class OpenLPToolbar(QtGui.QToolBar):
|
||||||
"""
|
"""
|
||||||
Lots of toolbars around the place, so it makes sense to have a common way to manage them
|
Lots of toolbars around the place, so it makes sense to have a common way
|
||||||
|
to manage them. This is the base toolbar class.
|
||||||
"""
|
"""
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
|
"""
|
||||||
|
Initialise the toolbar.
|
||||||
|
"""
|
||||||
QtGui.QToolBar.__init__(self, None)
|
QtGui.QToolBar.__init__(self, None)
|
||||||
# useful to be able to reuse button icons...
|
# useful to be able to reuse button icons...
|
||||||
self.icons = {}
|
self.icons = {}
|
||||||
@ -37,6 +40,23 @@ class OpenLPToolbar(QtGui.QToolBar):
|
|||||||
def addToolbarButton(self, title, icon, tooltip=None, slot=None, objectname=None):
|
def addToolbarButton(self, title, icon, tooltip=None, slot=None, objectname=None):
|
||||||
"""
|
"""
|
||||||
A method to help developers easily add a button to the toolbar.
|
A method to help developers easily add a button to the toolbar.
|
||||||
|
|
||||||
|
``title``
|
||||||
|
The title of the button.
|
||||||
|
|
||||||
|
``icon``
|
||||||
|
The icon of the button. This can be an instance of QIcon, or a
|
||||||
|
string cotaining either the absolute path to the image, or an
|
||||||
|
internal resource path starting with ':/'.
|
||||||
|
|
||||||
|
``tooltip``
|
||||||
|
A hint or tooltip for this button.
|
||||||
|
|
||||||
|
``slot``
|
||||||
|
The method to run when this button is clicked.
|
||||||
|
|
||||||
|
``objectname``
|
||||||
|
The name of the object, as used in `<button>.setObjectName()`.
|
||||||
"""
|
"""
|
||||||
ButtonIcon = None
|
ButtonIcon = None
|
||||||
if type(icon) is QtGui.QIcon:
|
if type(icon) is QtGui.QIcon:
|
||||||
@ -58,6 +78,13 @@ class OpenLPToolbar(QtGui.QToolBar):
|
|||||||
self.icons[title] = ButtonIcon
|
self.icons[title] = ButtonIcon
|
||||||
|
|
||||||
def getIconFromTitle(self, title):
|
def getIconFromTitle(self, title):
|
||||||
|
"""
|
||||||
|
Search through the list of icons for an icon with a particular title,
|
||||||
|
and return that icon.
|
||||||
|
|
||||||
|
``title``
|
||||||
|
The title of the icon to search for.
|
||||||
|
"""
|
||||||
if self.icons.has_key(title):
|
if self.icons.has_key(title):
|
||||||
return self.icons[title]
|
return self.icons[title]
|
||||||
else:
|
else:
|
||||||
|
@ -22,81 +22,80 @@ import platform
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
from types import StringType, NoneType, UnicodeType
|
from types import StringType, NoneType, UnicodeType
|
||||||
sys.path.append(os.path.abspath(u'./../..'))
|
|
||||||
|
|
||||||
from xml.etree.ElementTree import ElementTree, XML
|
from xml.etree.ElementTree import ElementTree, XML
|
||||||
|
|
||||||
|
sys.path.append(os.path.abspath(os.path.join('.', '..', '..')))
|
||||||
|
|
||||||
class XmlRootClass(object):
|
class XmlRootClass(object):
|
||||||
"""Root class for themes, songs etc
|
|
||||||
|
|
||||||
provides interface for parsing xml files into object attributes
|
|
||||||
|
|
||||||
if you overload this class and provide a function called
|
|
||||||
post_tag_hook, it will be called thusly for each tag,value pair:
|
|
||||||
|
|
||||||
(element.tag, val) = self.post_tag_hook(element.tag, val)
|
|
||||||
"""
|
"""
|
||||||
def _setFromXml(self, xml, rootTag):
|
Root class for themes, songs etc
|
||||||
"""Set song properties from given xml content
|
|
||||||
|
|
||||||
xml (string) -- formatted as xml tags and values
|
This class provides interface for parsing xml files into object attributes.
|
||||||
rootTag -- main tag of the xml
|
|
||||||
|
If you overload this class and provide a function called `post_tag_hook`,
|
||||||
|
it will be called thusly for each `tag, value` pair::
|
||||||
|
|
||||||
|
(element.tag, val) = self.post_tag_hook(element.tag, val)
|
||||||
|
"""
|
||||||
|
def _setFromXml(self, xml, root_tag):
|
||||||
|
"""
|
||||||
|
Set song properties from given xml content.
|
||||||
|
|
||||||
|
``xml``
|
||||||
|
Formatted xml tags and values.
|
||||||
|
``root_tag``
|
||||||
|
The root tag of the xml.
|
||||||
"""
|
"""
|
||||||
root = ElementTree(element=XML(xml))
|
root = ElementTree(element=XML(xml))
|
||||||
iter = root.getiterator()
|
iter = root.getiterator()
|
||||||
for element in iter:
|
for element in iter:
|
||||||
if element.tag != rootTag:
|
if element.tag != root_tag:
|
||||||
t = element.text
|
text = element.text
|
||||||
#print element.tag, t, type(t)
|
if type(text) is NoneType:
|
||||||
if type(t) == NoneType:
|
val = text
|
||||||
# easy!
|
elif type(text) is UnicodeType :
|
||||||
val=t
|
val = text
|
||||||
elif type(t) == UnicodeType :
|
elif type(text) is StringType:
|
||||||
val=t
|
# Strings need special handling to sort the colours out
|
||||||
elif type(t) == StringType:
|
if text[0] == '$':
|
||||||
# strings need special handling to sort the colours out
|
# This might be a hex number, let's try to convert it.
|
||||||
#print "str",
|
|
||||||
if t[0] == '$':
|
|
||||||
# might be a hex number
|
|
||||||
#print "hex",
|
|
||||||
try:
|
try:
|
||||||
val = int(t[1:], 16)
|
val = int(text[1:], 16)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# nope
|
|
||||||
#print "nope",
|
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
#print "last chance",
|
# Let's just see if it's a integer.
|
||||||
try:
|
try:
|
||||||
val=int(t)
|
val = int(text)
|
||||||
#print "int",
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
#print "give up",
|
# Ok, it seems to be a string.
|
||||||
val=t
|
val = text
|
||||||
if hasattr(self, u'post_tag_hook'):
|
if hasattr(self, u'post_tag_hook'):
|
||||||
(element.tag, val) = self.post_tag_hook(element.tag, val)
|
(element.tag, val) = self.post_tag_hook(element.tag, val)
|
||||||
setattr(self, element.tag, val)
|
setattr(self, element.tag, val)
|
||||||
pass
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Return string with all public attributes
|
"""
|
||||||
|
Return string with all public attributes
|
||||||
|
|
||||||
The string is formatted with one attribute per line
|
The string is formatted with one attribute per line
|
||||||
If the string is split on newline then the length of the
|
If the string is split on newline then the length of the
|
||||||
list is equal to the number of attributes
|
list is equal to the number of attributes
|
||||||
"""
|
"""
|
||||||
l = []
|
attributes = []
|
||||||
for k in dir(self):
|
for attrib in dir(self):
|
||||||
if not k.startswith(u'_'):
|
if not attrib.startswith(u'_'):
|
||||||
l.append(u'%30s : %s' %(k,getattr(self,k)))
|
attributes.append(u'%30s : %s' % (attrib, getattr(self, attrib)))
|
||||||
return u'\n'.join(l)
|
return u'\n'.join(attributes)
|
||||||
|
|
||||||
def _get_as_string(self):
|
def _get_as_string(self):
|
||||||
"""Return one string with all public attributes"""
|
"""
|
||||||
s=""
|
Return one string with all public attributes
|
||||||
for k in dir(self):
|
"""
|
||||||
if not k.startswith(u'_'):
|
result = u''
|
||||||
s+= u'_%s_' %(getattr(self,k))
|
for attrib in dir(self):
|
||||||
return s
|
if not attrib.startswith(u'_'):
|
||||||
|
result += u'_%s_' % getattr(self, attrib)
|
||||||
|
return result
|
||||||
|
|
||||||
|
@ -19,5 +19,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
class SettingsManager(object):
|
class SettingsManager(object):
|
||||||
def __init__(self):
|
"""
|
||||||
pass
|
A base settings manager class.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
@ -1,4 +1,23 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
||||||
|
"""
|
||||||
|
OpenLP - Open Source Lyrics Projection
|
||||||
|
Copyright (c) 2008 Raoul Snyman
|
||||||
|
Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley,
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; version 2 of the License.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@ -17,20 +36,30 @@ logging.basicConfig(level=logging.DEBUG,
|
|||||||
filename='openlp-migration.log',
|
filename='openlp-migration.log',
|
||||||
filemode='w')
|
filemode='w')
|
||||||
|
|
||||||
class Migration():
|
class Migration(object):
|
||||||
|
"""
|
||||||
|
A class to take care of the migration process.
|
||||||
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
|
Initialise the process.
|
||||||
"""
|
"""
|
||||||
self.display = Display()
|
self.display = Display()
|
||||||
self.stime = time.strftime(u'%Y-%m-%d-%H%M%S', time.localtime())
|
self.stime = time.strftime(u'%Y-%m-%d-%H%M%S', time.localtime())
|
||||||
self.display.output(u'OpenLp v1.9.0 Migration Utility Started')
|
self.display.output(u'OpenLp v1.9.0 Migration Utility Started')
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
|
"""
|
||||||
|
Perform the conversion.
|
||||||
|
"""
|
||||||
#MigrateFiles(self.display).process()
|
#MigrateFiles(self.display).process()
|
||||||
MigrateSongs(self.display).process()
|
MigrateSongs(self.display).process()
|
||||||
#MigrateBibles(self.display).process()
|
#MigrateBibles(self.display).process()
|
||||||
|
|
||||||
def move_log_file(self):
|
def move_log_file(self):
|
||||||
|
"""
|
||||||
|
Move the log file to a new location.
|
||||||
|
"""
|
||||||
fname = 'openlp-migration.log'
|
fname = 'openlp-migration.log'
|
||||||
c = os.path.splitext(fname)
|
c = os.path.splitext(fname)
|
||||||
b = (c[0]+'-'+ unicode(self.stime) + c[1])
|
b = (c[0]+'-'+ unicode(self.stime) + c[1])
|
||||||
|
Loading…
Reference in New Issue
Block a user