cleanups of files not used

fixes to bibles to handle unicode better
This commit is contained in:
Tim Bentley 2009-07-09 06:15:26 +01:00
commit 36113b0d90
15 changed files with 378 additions and 203 deletions

View File

@ -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
View File

@ -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()

View File

@ -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()

View File

@ -1,17 +0,0 @@
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 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
"""

View File

@ -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
# #

View File

@ -3,7 +3,7 @@
""" """
OpenLP - Open Source Lyrics Projection OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley
This program is free software; you can redistribute it and/or modify it under 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 the terms of the GNU General Public License as published by the Free Software
@ -24,4 +24,10 @@ class SettingsManager(object):
This class is created by the main window and then calculates the size of individual components This class is created by the main window and then calculates the size of individual components
""" """
def __init__(self, screen): def __init__(self, screen):
pass self.screen = screen[0]
self.width = self.screen[u'size'].width()
self.height = self.screen[u'size'].height()
self.mainwindow_width = self.width * 0.8
self.mainwindow_height = self.height * 0.8
self.mainwindow_docbars = self.width / 3
self.mainwindow_slidecontroller = self.width / 6

View File

@ -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'_':

View File

@ -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:

View File

@ -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

View File

@ -174,7 +174,7 @@ class MainWindow(object):
Set up the user interface Set up the user interface
""" """
self.mainWindow.setObjectName(u'mainWindow') self.mainWindow.setObjectName(u'mainWindow')
self.mainWindow.resize(1087, 847) self.mainWindow.resize(self.settingsmanager.width, self.settingsmanager.height)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding) QtGui.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0) sizePolicy.setHorizontalStretch(0)

View File

@ -157,7 +157,7 @@ class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog):
self.close() self.close()
def onImportButtonClicked(self): def onImportButtonClicked(self):
self.message = u'Bible import completed' message = u'Bible import completed'
if self.biblemanager != None: if self.biblemanager != None:
if not self.bible_type == None and len(self.BibleNameEdit.displayText()) > 0: if not self.bible_type == None and len(self.BibleNameEdit.displayText()) > 0:
self.MessageLabel.setText(u'Import Started') self.MessageLabel.setText(u'Import Started')
@ -165,14 +165,16 @@ class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog):
self.setMax(65) self.setMax(65)
self.ProgressBar.setValue(0) self.ProgressBar.setValue(0)
self.biblemanager.process_dialog(self) self.biblemanager.process_dialog(self)
self.importBible() status, msg = self.importBible()
self.MessageLabel.setText(u'Import Complete') if msg is not None:
message = msg
self.MessageLabel.setText(message)
self.ProgressBar.setValue(self.barmax) self.ProgressBar.setValue(self.barmax)
# tell bibleplugin to reload the bibles # tell bibleplugin to reload the bibles
Receiver().send_message(u'openlpreloadbibles') Receiver().send_message(u'openlpreloadbibles')
reply = QtGui.QMessageBox.information(self, reply = QtGui.QMessageBox.information(self,
translate(u'BibleMediaItem', u'Information'), translate(u'BibleMediaItem', u'Information'),
translate(u'BibleMediaItem', self.message)) translate(u'BibleMediaItem', message))
def setMax(self, max): def setMax(self, max):
log.debug(u'set Max %s', max) log.debug(u'set Max %s', max)
@ -185,7 +187,8 @@ class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog):
self.ProgressBar.setValue(self.ProgressBar.value()+1) self.ProgressBar.setValue(self.ProgressBar.value()+1)
def importBible(self): def importBible(self):
log.debug(u'Import Bible ') log.debug(u'Import Bible')
message = None
if self.bible_type == u'OSIS': if self.bible_type == u'OSIS':
loaded = self.biblemanager.register_osis_file_bible(unicode(self.BibleNameEdit.displayText()), loaded = self.biblemanager.register_osis_file_bible(unicode(self.BibleNameEdit.displayText()),
self.OSISLocationEdit.displayText()) self.OSISLocationEdit.displayText())
@ -207,11 +210,14 @@ class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog):
unicode(self.VersionNameEdit.displayText()), unicode(self.VersionNameEdit.displayText()),
unicode(self.CopyrightEdit.displayText()), unicode(self.CopyrightEdit.displayText()),
unicode(self.PermisionEdit.displayText())) unicode(self.PermisionEdit.displayText()))
else:
message = u'Bible import failed'
self.bible_type = None self.bible_type = None
# free the screen state restrictions # free the screen state restrictions
self.resetScreenFieldStates() self.resetScreenFieldStates()
# reset all the screen fields # reset all the screen fields
self.resetEntryFields() self.resetEntryFields()
return loaded, message
def checkOsis(self): def checkOsis(self):
if len(self.BooksLocationEdit.displayText()) > 0 or len(self.VerseLocationEdit.displayText()) > 0: if len(self.BooksLocationEdit.displayText()) > 0 or len(self.VerseLocationEdit.displayText()) > 0:
@ -286,4 +292,4 @@ class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog):
self.OSISLocationEdit.setText(u'') self.OSISLocationEdit.setText(u'')
self.BibleNameEdit.setText(u'') self.BibleNameEdit.setText(u'')
self.LocationComboBox.setCurrentIndex(0) self.LocationComboBox.setCurrentIndex(0)
self.BibleComboBox.setCurrentIndex(0) self.BibleComboBox.setCurrentIndex(0)

View File

@ -18,6 +18,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
import os import os
import os.path import os.path
import logging import logging
import chardet
from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl from openlp.plugins.bibles.lib.bibleDBimpl import BibleDBImpl
from openlp.core.lib import Receiver from openlp.core.lib import Receiver
from PyQt4 import QtCore from PyQt4 import QtCore
@ -45,34 +46,31 @@ class BibleOSISImpl():
QtCore.QObject.connect(Receiver().get_receiver(),QtCore.SIGNAL(u'openlpstopimport'),self.stop_import) QtCore.QObject.connect(Receiver().get_receiver(),QtCore.SIGNAL(u'openlpstopimport'),self.stop_import)
def stop_import(self): def stop_import(self):
self.loadbible= False self.loadbible = False
def load_data(self, osisfile, dialogobject=None):
osis=open(osisfile, u'r')
def load_data(self, osisfile_record, dialogobject=None):
osis = open(osisfile_record, u'r')
book_ptr = None book_ptr = None
id = 0 id = 0
count = 0 count = 0
verseText = u'<verse osisID=' verseText = u'<verse osisID='
testament = 1 testament = 1
for file in osis.readlines(): for file_record in osis.readlines():
# cancel pressed on UI # cancel pressed on UI
if self.loadbible == False: if self.loadbible == False:
break break
# print file details = chardet.detect(file_record)
pos = file.find(verseText) file_record = unicode(file_record, details['encoding'])
pos = file_record.find(verseText)
if pos > -1: # we have a verse if pos > -1: # we have a verse
epos= file.find(u'>', pos) epos= file_record.find(u'>', pos)
ref = file[pos+15:epos-1] # Book Reference ref = file_record[pos+15:epos-1] # Book Reference
#lets find the bible text only #lets find the bible text only
# find start of text # find start of text
pos = epos + 1 pos = epos + 1
# end of text # end of text
epos = file.find(u'</verse>', pos) epos = file_record.find(u'</verse>', pos)
text = unicode(file[pos : epos], u'utf8') text = file_record[pos : epos]
#print pos, e, f[pos:e] # Found Basic Text
#remove tags of extra information #remove tags of extra information
text = self.remove_block(u'<title', u'</title>', text) text = self.remove_block(u'<title', u'</title>', text)
text = self.remove_block(u'<note', u'</note>', text) text = self.remove_block(u'<note', u'</note>', text)
@ -82,7 +80,6 @@ class BibleOSISImpl():
text = self.remove_tag(u'<q', text) text = self.remove_tag(u'<q', text)
text = self.remove_tag(u'<l', text) text = self.remove_tag(u'<l', text)
text = self.remove_tag(u'<lg', text) text = self.remove_tag(u'<lg', text)
# Strange tags where the end is not the same as the start # Strange tags where the end is not the same as the start
# The must be in this order as at least one bible has them # The must be in this order as at least one bible has them
# crossing and the removal does not work. # crossing and the removal does not work.
@ -95,17 +92,14 @@ class BibleOSISImpl():
else: else:
text = text[:pos] + text[epos + 4: ] text = text[:pos] + text[epos + 4: ]
pos = text.find(u'<FI>') pos = text.find(u'<FI>')
pos = text.find(u'<RF>') pos = text.find(u'<RF>')
while pos > -1: while pos > -1:
epos = text.find(u'<Rf>', pos) epos = text.find(u'<Rf>', pos)
text = text[:pos] + text[epos + 4: ] text = text[:pos] + text[epos + 4: ]
#print "X", pos, epos, text #print "X", pos, epos, text
pos = text.find(u'<RF>') pos = text.find(u'<RF>')
# split up the reference
p = ref.split(u'.', 3) # split up the reference p = ref.split(u'.', 3)
#print p, ">>>", text
if book_ptr != p[0]: if book_ptr != p[0]:
# first time through # first time through
if book_ptr == None: if book_ptr == None:
@ -138,7 +132,6 @@ class BibleOSISImpl():
while pos > -1: while pos > -1:
epos = text.find(end_tag, pos) epos = text.find(end_tag, pos)
if epos == -1: if epos == -1:
#print "Y", pos, epos
pos = -1 pos = -1
else: else:
text = text[:pos] + text[epos + len(end_tag): ] text = text[:pos] + text[epos + len(end_tag): ]

View File

@ -49,7 +49,6 @@ class BibleManager():
self.proxyname = self.config.get_config(u'proxy name') #get proxy name for screen self.proxyname = self.config.get_config(u'proxy name') #get proxy name for screen
self.bibleSuffix = u'sqlite' self.bibleSuffix = u'sqlite'
self.dialogobject = None self.dialogobject = None
self.reload_bibles() self.reload_bibles()
def reload_bibles(self): def reload_bibles(self):

View File

@ -42,8 +42,8 @@ class PresentationPlugin(Plugin):
QtGui.QIcon.Normal, QtGui.QIcon.Off) QtGui.QIcon.Normal, QtGui.QIcon.Off)
def get_settings_tab(self): def get_settings_tab(self):
#self.presentation_tab = PresentationTab() self.presentation_tab = PresentationTab()
return None #self.presentation_tab return self.presentation_tab
def get_media_manager_item(self): def get_media_manager_item(self):
# Create the MediaManagerItem object # Create the MediaManagerItem object

View File

@ -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])