Fix None testing and general cleanups

This commit is contained in:
Jon Tibble 2009-09-26 00:06:54 +01:00
parent d5a3cf705b
commit 8a44484aee
30 changed files with 292 additions and 281 deletions

View File

@ -24,9 +24,10 @@
###############################################################################
import sys
import logging, logging.handlers
from optparse import OptionParser
import logging
import logging.handlers
from optparse import OptionParser
from PyQt4 import QtCore, QtGui
from openlp.core.lib import Receiver, str_to_bool

View File

@ -28,6 +28,7 @@ OpenLP work.
"""
import types
from PyQt4 import QtCore, QtGui
def translate(context, text):

View File

@ -107,17 +107,17 @@ class PluginConfig(object):
files = os.listdir(self.get_data_path())
except:
return []
if suffix != None:
if suffix is not None:
return_files = []
for f in files:
if f.find(u'.') != -1:
nme = f.split(u'.')
bname = nme[0]
sfx = nme[1].lower()
sfx = sfx.lower()
for file in files:
if file.find(u'.') != -1:
filename = file.split(u'.')
#bname = nme[0]
filesuffix = filename[1].lower()
filesuffix = filesuffix.lower()
# only load files with the correct suffix
if suffix.find(sfx) > -1 :
return_files.append(f)
if suffix.find(filesuffix) > -1 :
return_files.append(file)
return return_files
else:
# no filtering required

View File

@ -151,7 +151,6 @@ class Renderer(object):
The footer of the slide.
"""
log.debug(u'format_slide - Start')
verses = []
words = words.replace(u'\r\n', u'\n')
verses_text = words.split(u'\n')
text = []
@ -174,7 +173,6 @@ class Renderer(object):
split_pages = []
page = []
split_lines = []
count = 0
for line in text:
#Must be a blank line so keep it.
if len(line) == 0:

View File

@ -88,7 +88,7 @@ class ServiceItem(object):
self.frames = []
if self.service_item_type == ServiceType.Text:
log.debug(u'Formatting slides')
if self.theme == None:
if self.theme is None:
self.RenderManager.set_override_theme(None)
else:
self.RenderManager.set_override_theme(self.theme)
@ -114,7 +114,7 @@ class ServiceItem(object):
def render_individual(self, row):
log.debug(u'render individual')
if self.theme == None:
if self.theme is None:
self.RenderManager.set_override_theme(None)
else:
self.RenderManager.set_override_theme(self.theme)

View File

@ -48,7 +48,7 @@ class SettingsTab(QtGui.QWidget):
self.setupUi()
self.retranslateUi()
self.initialise()
if section == None:
if section is None:
self.config = PluginConfig(title)
else:
self.config = PluginConfig(section)

View File

@ -17,12 +17,13 @@ Place, Suite 330, Boston, MA 02111-1307 USA
"""
import sys
import os, os.path
import os
import os.path
from PyQt4 import QtGui, QtCore
from openlp.core.theme import Theme
from openlp.core import Renderer
from openlp.core.lib import Renderer
mypath = os.path.split(os.path.abspath(__file__))[0]
sys.path.insert(0, (os.path.join(mypath, '..', '..', '..')))
@ -104,8 +105,8 @@ class TestRender_base:
frame = TstFrame(size = self.size)
self.frame = frame
self.paintdest = frame.GetPixmap()
self.r=Renderer()
self.r.set_paint_dest(self.paintdest)
self.renderer = Renderer()
self.renderer.set_paint_dest(self.paintdest)
self.expected_answer = "Don't know yet"
self.answer = None
print "--------------- Setup Done -------------"
@ -119,24 +120,27 @@ class TestRender(TestRender_base):
def setup_method(self, method):
TestRender_base.setup_method(self, method)
self.r.set_debug(1)
self.renderer.set_debug(1)
themefile = os.path.abspath(u'data_for_tests/render_theme.xml')
self.r.set_theme(Theme(themefile)) # set default theme
self.r._render_background()
self.r.set_text_rectangle(QtCore.QRect(0,0, self.size.width()-1,
self.size.height()-1))
self.renderer.set_theme(Theme(themefile)) # set default theme
self.renderer._render_background()
self.renderer.set_text_rectangle(QtCore.QRect(
0,0, self.size.width()-1, self.size.height()-1))
self.msg = None
def test_easy(self):
answer = self.r._render_single_line(u'Test line', tlcorner = (0,100))
answer = self.renderer._render_single_line(
u'Test line', tlcorner = (0,100))
assert(answer == (219,163))
def test_longer(self):
answer = self.r._render_single_line(
answer = self.renderer._render_single_line(
u'Test line with more words than fit on one line',
tlcorner = (10,10))
assert(answer == (753,136))
def test_even_longer(self):
answer = self.r._render_single_line(
answer = self.renderer._render_single_line(
u'Test line with more words than fit on either one or two lines',
tlcorner = (10,10))
assert(answer == (753,199))
@ -146,7 +150,7 @@ class TestRender(TestRender_base):
lines.append(u'Line Two')
lines.append(u'Line Three and should be long enough to wrap')
lines.append(u'Line Four and should be long enough to wrap also')
answer = self.r._render_lines(lines)
answer = self.renderer._render_lines(lines)
assert(answer == QtCore.QRect(0,0,741,378))
def test_set_words_openlp(self):
@ -161,7 +165,7 @@ Verse 3: Line 1
Line 2
Line 3"""
expected_answer = ["Verse 1: Line 1\nLine 2","Verse 2: Line 1\nLine 2","Verse 3: Line 1\nLine 2\nLine 3"]
answer = self.r.set_words_openlp(words)
answer = self.renderer.set_words_openlp(words)
assert(answer == expected_answer)
def test_render_screens(self):
@ -175,14 +179,14 @@ Line 2
Verse 3: Line 1
Line 2
Line 3"""
verses = self.r.set_words_openlp(words)
verses = self.renderer.set_words_openlp(words)
expected_answer = ["Verse 1: Line 1\nLine 2","Verse 2: Line 1\nLine 2","Verse 3: Line 1\nLine 2\nLine 3"]
assert(verses == expected_answer)
expected_answer = [QtCore.QRect(0,0,397,126), QtCore.QRect(0,0,397,126),
QtCore.QRect(0,0,397,189)]
for v in range(len(verses)):
answer=self.r.render_screen(v)
answer=self.renderer.render_screen(v)
# print v, answer.x(), answer.y(), answer.width(), answer.height()
assert(answer == expected_answer[v])
@ -194,11 +198,11 @@ Line 3"""
if i == 51: # make an extra long line on line 51 to test wrapping
extra = "Some more words to make it wrap around don't you know until it wraps so many times we don't know what to do"
lines.append(u'Line %d %s' % (i, extra))
result = self.r.split_set_of_lines(lines)
result = self.renderer.split_set_of_lines(lines)
print "results---------------__", result
for i in range(len(result)):
self.setup_method(None)
answer = self.r._render_lines(result[i])
answer = self.renderer._render_lines(result[i])
print answer
self.write_to_file(self.frame.GetPixmap(), "split_test_%03d"% i)
print number, i, answer.x(), answer.y(), answer.width(), \

View File

@ -15,6 +15,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
Place, Suite 330, Boston, MA 02111-1307 USA
"""
import sys
import os
@ -33,7 +34,7 @@ def compare_images(goldenim, testim, threshold=0.01):
# how close are they? Calculated the sum of absolute differences in
# each channel of each pixel and divide by the number of pixels in the image
# if this sum is < threshold, the images are deemed to be "close enough"
sad=0;
sad = 0;
for x in range(goldenim.width()):
for y in range(goldenim.height()):
p1=goldenim.pixel(x,y)
@ -44,10 +45,8 @@ def compare_images(goldenim, testim, threshold=0.01):
sad /= float(goldenim.width()*goldenim.height())
if (sad < threshold):
return 1
return 0
class TestRenderTheme(TestRender_base):
# {{{ Basics
@ -58,15 +57,15 @@ class TestRenderTheme(TestRender_base):
TestRender_base.setup_method(self, method)
print "Theme setup", method
# print "setup theme"
self.r.set_theme(Theme(u'blank_theme.xml')) # set "blank" theme
self.r.set_text_rectangle(QtCore.QRect(0,0, self.size.width(),
self.renderer.set_theme(Theme(u'blank_theme.xml')) # set "blank" theme
self.renderer.set_text_rectangle(QtCore.QRect(0,0, self.size.width(),
self.size.height()))
words = """How sweet the name of Jesus sounds
In a believer's ear!
It soothes his sorrows, heals his wounds,
And drives away his fear.
"""
verses = self.r.set_words_openlp(words)
verses = self.renderer.set_words_openlp(words)
# usually the same
self.expected_answer = QtCore.QRect(0, 0, 559, 342)
self.msg = None
@ -75,9 +74,9 @@ And drives away his fear.
def teardown_method(self, method):
print "============ teardown =============", method, self.bmpname
if self.bmpname != None:
if self.bmpname is not None:
assert (self.compare_DC_to_file(self.bmpname))
if self.expected_answer != None: # result=None => No result to check
if self.expected_answer is not None: # result=None => Nothing to check
assert self.expected_answer == self.answer
print "============ teardown done ========="
@ -104,9 +103,9 @@ And drives away his fear.
return False
def test_theme_basic(self):
self.answer = self.r.render_screen(0)
self.answer = self.renderer.render_screen(0)
self.bmpname = whoami()
print self.r._theme.FontProportion
print self.renderer._theme.FontProportion
print self.answer, self.expected_answer, \
self.answer == self.expected_answer
# self.msg=self.bmpname
@ -116,20 +115,20 @@ And drives away his fear.
# {{{ Gradients
def test_gradient_h(self):
# normally we wouldn't hack with these directly!
self.r._theme.BackgroundType = 1
self.r._theme.BackgroundParameter1 = QtGui.QColor(255,0,0)
self.r._theme.BackgroundParameter2 = QtGui.QColor(255,255,0)
self.r._theme.BackgroundParameter3 = 1
self.answer = self.r.render_screen(0)
self.renderer._theme.BackgroundType = 1
self.renderer._theme.BackgroundParameter1 = QtGui.QColor(255,0,0)
self.renderer._theme.BackgroundParameter2 = QtGui.QColor(255,255,0)
self.renderer._theme.BackgroundParameter3 = 1
self.answer = self.renderer.render_screen(0)
self.bmpname = whoami()
def test_gradient_v(self):
# normally we wouldn't hack with these directly!
self.r._theme.BackgroundType = 1
self.r._theme.BackgroundParameter1 = QtGui.QColor(255,0,0)
self.r._theme.BackgroundParameter2 = QtGui.QColor(255,255,0)
self.r._theme.BackgroundParameter3 = 0
self.answer = self.r.render_screen(0)
self.renderer._theme.BackgroundType = 1
self.renderer._theme.BackgroundParameter1 = QtGui.QColor(255,0,0)
self.renderer._theme.BackgroundParameter2 = QtGui.QColor(255,255,0)
self.renderer._theme.BackgroundParameter3 = 0
self.answer = self.renderer.render_screen(0)
self.bmpname = whoami()
# }}}
@ -142,9 +141,9 @@ And drives away his fear.
t.BackgroundParameter2 = QtGui.QColor(0,0,64)
t.BackgroundParameter3 = 0
t.Name = "stretch y"
self.r.set_theme(t)
self.renderer.set_theme(t)
print "render"
self.answer = self.r.render_screen(0)
self.answer = self.renderer.render_screen(0)
print "whoami"
self.bmpname = whoami()
print "fone"
@ -156,8 +155,8 @@ And drives away his fear.
t.BackgroundParameter2 = QtGui.QColor(0,0,64)
t.BackgroundParameter3 = 0
t.Name = "shrink y"
self.r.set_theme(t)
self.answer = self.r.render_screen(0)
self.renderer.set_theme(t)
self.answer = self.renderer.render_screen(0)
self.bmpname = whoami()
def test_bg_stretch_x(self):
@ -169,8 +168,8 @@ And drives away his fear.
t.BackgroundParameter3 = 0
t.VerticalAlign = 2
t.Name = "stretch x"
self.r.set_theme(t)
self.answer = self.r.render_screen(0)
self.renderer.set_theme(t)
self.answer = self.renderer.render_screen(0)
self.expected_answer = QtCore.QRect(0, 129, 559, 342)
self.bmpname = whoami()
@ -183,9 +182,9 @@ And drives away his fear.
t.BackgroundParameter3 = 0
t.VerticalAlign = 2
t.Name = "shrink x"
self.r.set_theme(t)
self.renderer.set_theme(t)
self.expected_answer = QtCore.QRect(0, 129, 559, 342)
self.answer = self.r.render_screen(0)
self.answer = self.renderer.render_screen(0)
self.bmpname = whoami()
# }}}
@ -196,8 +195,8 @@ And drives away his fear.
t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.VerticalAlign = 0
t.Name = "valign top"
self.r.set_theme(t)
self.answer = self.r.render_screen(0)
self.renderer.set_theme(t)
self.answer = self.renderer.render_screen(0)
self.bmpname = whoami()
def test_theme_vertical_align_bot(self):
@ -206,8 +205,8 @@ And drives away his fear.
t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.VerticalAlign = 1
t.Name = "valign bot"
self.r.set_theme(t)
self.answer = self.r.render_screen(0)
self.renderer.set_theme(t)
self.answer = self.renderer.render_screen(0)
self.expected_answer = QtCore.QRect(0, 257, 559, 342)
self.bmpname = whoami()
@ -217,8 +216,8 @@ And drives away his fear.
t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.VerticalAlign = 2
t.Name = "valign cen"
self.r.set_theme(t)
self.answer = self.r.render_screen(0)
self.renderer.set_theme(t)
self.answer = self.renderer.render_screen(0)
self.expected_answer = QtCore.QRect(0, 129, 559, 342)
self.bmpname = whoami()
# }}}
@ -231,8 +230,8 @@ And drives away his fear.
t.VerticalAlign = 0
t.HorizontalAlign = 0
t.Name = "halign left"
self.r.set_theme(t)
self.answer = self.r.render_screen(0)
self.renderer.set_theme(t)
self.answer = self.renderer.render_screen(0)
self.bmpname = whoami()
def test_theme_horizontal_align_right(self):
@ -242,9 +241,9 @@ And drives away his fear.
t.VerticalAlign = 0
t.HorizontalAlign = 1
t.Name = "halign right"
self.r.set_theme(t)
self.renderer.set_theme(t)
self.expected_answer = QtCore.QRect(0, 0, 800, 342)
self.answer = self.r.render_screen(0)
self.answer = self.renderer.render_screen(0)
self.bmpname = whoami()
def test_theme_horizontal_align_centre(self):
@ -254,8 +253,8 @@ And drives away his fear.
t.VerticalAlign = 0
t.HorizontalAlign = 2
t.Name = "halign centre"
self.r.set_theme(t)
self.answer = self.r.render_screen(0)
self.renderer.set_theme(t)
self.answer = self.renderer.render_screen(0)
self.expected_answer = QtCore.QRect(0, 0, 679, 342)
self.bmpname = whoami()
@ -267,8 +266,8 @@ And drives away his fear.
t.HorizontalAlign = 0
t.WrapStyle = 1
t.Name = "halign left lyric"
self.r.set_theme(t)
self.answer = self.r.render_screen(0)
self.renderer.set_theme(t)
self.answer = self.renderer.render_screen(0)
self.expected_answer = QtCore.QRect(0, 0, 778, 342)
self.bmpname = whoami()
# }}}
@ -284,11 +283,11 @@ And drives away his fear.
t.Outline = 1
t.ShadowColor = QtGui.QColor(64,128,0)
t.OutlineColor = QtGui.QColor(128,0,0)
self.r.set_debug(1)
self.r.set_theme(t)
self.answer = self.r.render_screen(0)
hoffset = self.r._shadow_offset+2*(self.r._outline_offset)
voffset = hoffset * (len(self.r.words[0])+1)
self.renderer.set_debug(1)
self.renderer.set_theme(t)
self.answer = self.renderer.render_screen(0)
hoffset = self.renderer._shadow_offset+2*(self.renderer._outline_offset)
voffset = hoffset * (len(self.renderer.words[0])+1)
self.expected_answer = QtCore.QRect(0, 0, 559+hoffset, 342+voffset)
self.bmpname = whoami()
@ -300,15 +299,14 @@ And drives away his fear.
t.BackgroundParameter1 = QtGui.QColor(0,0,64)
t.Name = "font"
t.FontName = "Times New Roman"
self.r.set_theme(t)
self.answer = self.r.render_screen(0)
self.renderer.set_theme(t)
self.answer = self.renderer.render_screen(0)
self.expected_answer = QtCore.QRect(0, 0, 499, 336)
self.bmpname=whoami()
if __name__ == "__main__":
t = TestRenderTheme()
t.setup_class()
t.setup_method(None)
t.test_bg_stretch_y()
t.teardown_method(None)
test_render_theme = TestRenderTheme()
test_render_theme.setup_class()
test_render_theme.setup_method(None)
test_render_theme.test_bg_stretch_y()
test_render_theme.teardown_method(None)

View File

@ -1,55 +1,57 @@
import os
import os.path
import sys
mypath=os.path.split(os.path.abspath(__file__))[0]
sys.path.insert(0,(os.path.join(mypath, '..' ,'..', '..', '..')))
print sys.path
from PyQt4 import QtGui
from openlp.core.theme import Theme
import os.path
from PyQt4 import QtGui
mypath = os.path.split(os.path.abspath(__file__))[0]
sys.path.insert(0, (os.path.join(mypath, '..', '..', '..', '..')))
print sys.path
def test_read_theme():
dir=os.path.split(__file__)[0]
dir = os.path.split(__file__)[0]
# test we can read a theme
t=Theme(os.path.join(dir, 'test_theme.xml'))
print t
assert(t.BackgroundParameter1 == 'sunset1.jpg')
assert(t.BackgroundParameter2 == None)
assert(t.BackgroundParameter3 == None)
assert(t.BackgroundType == 2)
assert(t.FontColor == QtGui.QColor(255,255,255))
assert(t.FontName == 'Tahoma')
assert(t.FontProportion == 16)
assert(t.FontUnits == 'pixels')
assert(t.HorizontalAlign == 2)
assert(t.Name == 'openlp.org Packaged Theme')
assert(t.Outline == -1)
assert(t.OutlineColor == QtGui.QColor(255,0,0))
assert(t.Shadow == -1)
assert(t.ShadowColor == QtGui.QColor(0,0,1))
assert(t.VerticalAlign == 0)
theme = Theme(os.path.join(dir, 'test_theme.xml'))
print theme
assert(theme.BackgroundParameter1 == 'sunset1.jpg')
assert(theme.BackgroundParameter2 is None)
assert(theme.BackgroundParameter3 is None)
assert(theme.BackgroundType == 2)
assert(theme.FontColor == QtGui.QColor(255,255,255))
assert(theme.FontName == 'Tahoma')
assert(theme.FontProportion == 16)
assert(theme.FontUnits == 'pixels')
assert(theme.HorizontalAlign == 2)
assert(theme.Name == 'openlp.org Packaged Theme')
assert(theme.Outline == -1)
assert(theme.OutlineColor == QtGui.QColor(255,0,0))
assert(theme.Shadow == -1)
assert(theme.ShadowColor == QtGui.QColor(0,0,1))
assert(theme.VerticalAlign == 0)
def test_theme():
# test we create a "blank" theme correctly
t=Theme()
print t
assert(t.BackgroundParameter1 == QtGui.QColor(0,0,0))
assert(t.BackgroundParameter2 == None)
assert(t.BackgroundParameter3 == None)
assert(t.BackgroundType == 0)
assert(t.FontColor == QtGui.QColor(255,255,255))
assert(t.FontName == 'Arial')
assert(t.FontProportion == 30)
assert(t.HorizontalAlign == 0)
assert(t.FontUnits == 'pixels')
assert(t.Name == 'BlankStyle')
assert(t.Outline == 0)
assert(t.Shadow == 0)
assert(t.VerticalAlign == 0)
theme = Theme()
print theme
assert(theme.BackgroundParameter1 == QtGui.QColor(0,0,0))
assert(theme.BackgroundParameter2 is None)
assert(theme.BackgroundParameter3 is None)
assert(theme.BackgroundType == 0)
assert(theme.FontColor == QtGui.QColor(255,255,255))
assert(theme.FontName == 'Arial')
assert(theme.FontProportion == 30)
assert(theme.HorizontalAlign == 0)
assert(theme.FontUnits == 'pixels')
assert(theme.Name == 'BlankStyle')
assert(theme.Outline == 0)
assert(theme.Shadow == 0)
assert(theme.VerticalAlign == 0)
print "Tests passed"
if __name__ == "__main__":
test_read_theme()
test_theme()

View File

@ -23,7 +23,8 @@
###############################################################################
import logging
import os, os.path
import os
import os.path
from PyQt4 import QtCore, QtGui
@ -178,7 +179,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
def loadTheme(self, theme):
log.debug(u'LoadTheme %s', theme)
if theme == None:
if theme is None:
self.theme.parse(self.thememanager.baseTheme())
else:
xml_file = os.path.join(self.path, theme, theme + u'.xml')

View File

@ -420,8 +420,6 @@ class ServiceManager(QtGui.QWidget):
self.config.set_last_dir(filename)
try:
zip = zipfile.ZipFile(unicode(filename))
filexml = None
themename = None
for file in zip.namelist():
if os.name == u'nt':
winfile = string.replace(file, '/', os.path.sep)

View File

@ -292,7 +292,7 @@ class SlideController(QtGui.QWidget):
label = QtGui.QLabel()
label.setMargin(8)
#It is a Image
if frame[u'text'] == None:
if frame[u'text'] is None:
pixmap = self.parent.RenderManager.resize_image(frame[u'image'])
label.setScaledContents(True)
label.setPixmap(QtGui.QPixmap.fromImage(pixmap))
@ -340,7 +340,7 @@ class SlideController(QtGui.QWidget):
label = self.PreviewListWidget.cellWidget(row, 0)
frame = self.serviceitem.frames[row][u'image']
before = time.time()
if frame == None:
if frame is None:
frame = self.serviceitem.render_individual(row)
self.SlidePreview.setPixmap(QtGui.QPixmap.fromImage(frame))
log.info(u'Slide Rendering took %4s' % (time.time() - before))

View File

@ -17,7 +17,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
"""
import sys
import os, os.path
import os
import os.path
import logging
from PyQt4 import QtGui

View File

@ -26,7 +26,7 @@ import logging
class Display():
global log
log=logging.getLogger(u'Display Logger')
log = logging.getLogger(u'Display Logger')
log.info(u'Display Class loaded')
@staticmethod
@ -36,6 +36,6 @@ class Display():
@staticmethod
def sub_output(string):
if not string == None:
if not string is None:
log.debug(u' '+string);
print (u' '+string)

View File

@ -168,7 +168,6 @@ class MigrateSongs():
author.first_name = u''
author.last_name = u''
else:
id = int(bb[0])
author = self.session.query(Author).get(bb[0])
song.authors.append(author)
try:

View File

@ -23,7 +23,8 @@
###############################################################################
import logging
import os, os.path
import os
import os.path
from PyQt4 import QtCore, QtGui
@ -33,7 +34,7 @@ from openlp.core.lib import Receiver, translate
class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog):
global log
log=logging.getLogger(u'BibleImportForm')
log = logging.getLogger(u'BibleImportForm')
log.info(u'BibleImportForm loaded')
"""
Class documentation goes here.
@ -136,13 +137,16 @@ class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog):
self.checkOsis()
def onProxyAddressEditLostFocus(self):
self.config.set_config(u'proxy_address', unicode(self.AddressEdit.displayText()))
self.config.set_config(
u'proxy_address', unicode(self.AddressEdit.displayText()))
def onProxyUsernameEditLostFocus(self):
self.config.set_config(u'proxy_username', unicode(self.UsernameEdit.displayText()))
self.config.set_config(
u'proxy_username', unicode(self.UsernameEdit.displayText()))
def onProxyPasswordEditLostFocus(self):
self.config.set_config(u'proxy_password', unicode(self.PasswordEdit.displayText()))
self.config.set_config(
u'proxy_password', unicode(self.PasswordEdit.displayText()))
def onLocationComboBoxSelected(self):
self.checkHttp()
@ -161,8 +165,9 @@ class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog):
def onImportButtonClicked(self):
message = u'Bible import completed'
if self.biblemanager != None:
if not self.bible_type == None and len(self.BibleNameEdit.displayText()) > 0:
if self.biblemanager is not None:
if not self.bible_type is None and \
len(self.BibleNameEdit.displayText()) > 0:
self.MessageLabel.setText(u'Import Started')
self.ProgressBar.setMinimum(0)
self.setMax(65)
@ -286,7 +291,7 @@ class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog):
def resetScreenFieldStates(self):
# only reset if no bible type set.
if self.bible_type == None:
if self.bible_type is None:
self.BooksLocationEdit.setReadOnly(False)
self.VerseLocationEdit.setReadOnly(False)
self.BooksFileButton.setEnabled(True)

View File

@ -137,12 +137,12 @@ class BibleDBImpl(BibleCommon):
def get_bible_book(self, bookname):
log.debug(u'get_bible_book %s', bookname)
bk = self.session.query(Book).filter(
book = self.session.query(Book).filter(
Book.name.like(bookname + u'%')).first()
if bk == None:
bk = self.session.query(Book).filter(
if book is None:
book = self.session.query(Book).filter(
Book.abbreviation.like(bookname + u'%')).first()
return bk
return book
def get_bible_chapter(self, id, chapter):
log.debug(u'get_bible_chapter %s, %s', id, chapter)

View File

@ -195,19 +195,19 @@ class BibleHTTPImpl():
Init confirms the bible exists and stores the database path.
"""
bible = {}
biblesource = ''
proxyurl = None
bibleid = None
#bible = {}
self.biblesource = ''
self.proxyurl = None
self.bibleid = None
def set_proxy(self,proxyurl):
def set_proxy(self, proxyurl):
"""
Set the Proxy Url
"""
log.debug(u'set_proxy %s', proxyurl)
self.proxyurl = proxyurl
def set_bibleid(self,bibleid):
def set_bibleid(self, bibleid):
"""
Set the bible id.
The shore identifier of the the bible.
@ -215,7 +215,7 @@ class BibleHTTPImpl():
log.debug(u'set_bibleid %s', bibleid)
self.bibleid = bibleid
def set_bible_source(self,biblesource):
def set_bible_source(self, biblesource):
"""
Set the source of where the bible text is coming from
"""
@ -235,6 +235,5 @@ class BibleHTTPImpl():
else:
ev = BGExtract(self.proxyurl)
return ev.get_bible_chapter(self.bibleid, bookid, bookname, chapter)
except Exception, e:
log.error(u'Error thrown = %s', e.args[0])
print e
except:
log.exception("Failed to get bible chapter")

View File

@ -90,7 +90,7 @@ class BibleOSISImpl():
detect_file.close()
osis = codecs.open(osisfile_record, u'r', details['encoding'])
book_ptr = None
id = 0
#id = 0
count = 0
verseText = u'<verse osisID='
testament = 1
@ -138,7 +138,7 @@ class BibleOSISImpl():
p = ref.split(u'.', 3)
if book_ptr != p[0]:
# first time through
if book_ptr == None:
if book_ptr is None:
# set the max book size depending on the first book read
if p[0] == u'Gen':
dialogobject.setMax(65)

View File

@ -39,7 +39,7 @@ class BibleManager(object):
The Bible manager which holds and manages all the Bibles.
"""
global log
log=logging.getLogger(u'BibleManager')
log = logging.getLogger(u'BibleManager')
log.info(u'Bible manager loaded')
def __init__(self, config):
@ -102,7 +102,7 @@ class BibleManager(object):
# look to see if lazy load bible exists and get create getter.
meta = self.bible_db_cache[bname].get_meta(u'proxy')
proxy = None
if meta != None:
if meta is not None:
proxy = meta.value
# tell The Server where to get the verses from.
nhttp.set_proxy(proxy)
@ -177,14 +177,14 @@ class BibleManager(object):
nbible.save_meta(u'WEB', biblesource)
# store the web id of the bible
nbible.save_meta(u'bibleid', bibleid)
if proxyurl != None and proxyurl != "":
if proxyurl is not None and proxyurl != "":
# store the proxy URL
nbible.save_meta(u'proxy', proxyurl)
nhttp.set_proxy(proxyurl)
if proxyid != None and proxyid != "":
if proxyid is not None and proxyid != "":
# store the proxy userid
nbible.save_meta(u'proxyid', proxyid)
if proxypass != None and proxypass != "":
if proxypass is not None and proxypass != "":
# store the proxy password
nbible.save_meta(u'proxypass', proxypass)
return True
@ -329,8 +329,8 @@ c
# check to see if book/chapter exists fow HTTP bibles and load cache
# if necessary
if self.bible_http_cache[bible] is not None:
book= self.bible_db_cache[bible].get_bible_book(bookname)
if book == None:
book = self.bible_db_cache[bible].get_bible_book(bookname)
if book is None:
self.media.setQuickMsg1(u'Downloading')
log.debug(u'get_verse_text : new book')
for chapter in range(schapter, echapter + 1):
@ -347,7 +347,7 @@ c
# check to see if book/chapter exists
book = self.bible_db_cache[bible].get_bible_book(
bookname)
if book == None:
if book is None:
## Then create book, chapter and text
book = self.bible_db_cache[bible].create_book(
bookname, self.book_abbreviations[bookname],
@ -361,7 +361,7 @@ c
## Book exists check chapter and texts only.
v = self.bible_db_cache[bible].get_bible_chapter(
book.id, chapter)
if v == None:
if v is None:
self.media.setQuickMsg2(u'%s: %s'% (
bookname, chapter))
self.bible_db_cache[bible].create_chapter(
@ -372,7 +372,7 @@ c
for chapter in range(schapter, echapter + 1):
v = self.bible_db_cache[bible].get_bible_chapter(
book.id, chapter)
if v == None:
if v is None:
try:
self.media.setQuickMsg1(u'Downloading')
self.media.setQuickMsg2(u'%s: %s'% \
@ -411,8 +411,8 @@ c
"""
Check cache to see if new bible
"""
for b, o in self.bible_db_cache.iteritems():
log.debug(u'Bible from cache in is_new_bible %s', b )
if b == name :
for bible, o in self.bible_db_cache.iteritems():
log.debug(u'Bible from cache in is_new_bible %s', bible)
if bible == name:
return False
return True

View File

@ -315,14 +315,14 @@ class BibleMediaItem(MediaManagerItem):
self.adjustComboBox(frm, self.verses, self.AdvancedToVerse)
def onAdvancedToChapter(self):
t1 = self.AdvancedFromChapter.currentText()
t2 = self.AdvancedToChapter.currentText()
if t1 != t2:
text1 = self.AdvancedFromChapter.currentText()
text2 = self.AdvancedToChapter.currentText()
if text1 != text2:
bible = unicode(self.AdvancedVersionComboBox.currentText())
book = unicode(self.AdvancedBookComboBox.currentText())
# get the verse count for new chapter
verses = self.parent.biblemanager.get_book_verse_count(
bible, book, int(t2))[0]
bible, book, int(text2))[0]
self.adjustComboBox(1, verses, self.AdvancedToVerse)
def onAdvancedSearchButton(self):
@ -482,7 +482,7 @@ class BibleMediaItem(MediaManagerItem):
start_verse = u''
end_verse = u''
search = search.replace(u' ', u' ').strip()
original = search
#original = search
message = None
# Remove book beware 0 index arrays
for i in range (len(search)-1, 0, - 1):
@ -547,7 +547,7 @@ class BibleMediaItem(MediaManagerItem):
log.debug(u'results = %s @ %s : %s @ %s : %s'% \
(unicode(book), unicode(start_chapter), unicode(end_chapter),
unicode(start_verse), unicode(end_verse)))
if message == None:
if message is None:
self.search_results = None
self.search_results = self.parent.biblemanager.get_verse_text(
bible, book, int(start_chapter), int(end_chapter),

View File

@ -17,7 +17,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
"""
import logging
import os, os.path
import os
import os.path
import sys
from openlp.plugins.bibles.lib.biblemanager import BibleManager

View File

@ -17,7 +17,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
"""
import logging
import os, os.path
import os
import os.path
import sys
from openlp.plugins.biblemanager.bibleManager import BibleManager

View File

@ -17,7 +17,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
"""
import logging
import os, os.path
import os
import os.path
import sys
from openlp.plugins.bibles.lib.biblemanager import BibleManager

View File

@ -17,7 +17,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
"""
import logging
import os, os.path
import os
import os.path
import sys
from openlp.plugins.bibles.lib.biblemanager import BibleManager

View File

@ -112,7 +112,7 @@ class ImpressController(object):
context = uno.getComponentContext()
resolver = context.ServiceManager.createInstanceWithContext(
u'com.sun.star.bridge.UnoUrlResolver', context)
while ctx == None and loop < 3:
while ctx is None and loop < 3:
try:
ctx = resolver.resolve(u'uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext')
except:

View File

@ -47,9 +47,9 @@ class PowerPointApp(object):
self._app.WindowState = 2
def getApp(self):
if self._app == None:
if self._app is None:
self.createApp()
if self._app == None:
if self._app is None:
return None
if self._app.Windows.Count == 0:
self.createApp()
@ -69,17 +69,17 @@ class PowerPointPres(object):
self.open()
def getPres(self):
if self._pres == None:
if self._pres is None:
for p in self.pptApp.app.Presentations:
if p.FullName == self.filename:
self._pres = p
break
if self._pres != None:
if self._pres is not None:
try:
x = self._pres.Name
except:
self._pres = None
if self._pres == None:
if self._pres is None:
self.openPres()
return self._pres
@ -94,9 +94,9 @@ class PowerPointPres(object):
self._pres = None
def isActive(self):
if self.pres.SlideShowWindow == None:
if self.pres.SlideShowWindow is None:
return False
if self.pres.SlideShowWindow.View == None:
if self.pres.SlideShowWindow.View is None:
return False
return True
@ -157,7 +157,7 @@ class PowerPointSlide(object):
self.slide = pres.Slides[index]
def preview(self):
if self.preview == None:
if self.preview is None:
self.slide.Copy
# import win32clipboard as w
# import win32con
@ -165,4 +165,3 @@ class PowerPointSlide(object):
# self.preview = w.GetClipboardData.GetData(win32con.CF_BITMAP)
# w.CloseClipboard()
return self.preview

View File

@ -219,7 +219,7 @@ class SongManager():
self.session.add(book)
self.session.commit()
return True
except Exception, e:
except:
self.session.rollback()
log.exception(u'Could not save book to song database')
return False

View File

@ -270,7 +270,7 @@ class SongMediaItem(MediaManagerItem):
self.ListView.takeItem(row)
def generateSlideData(self, service_item):
raw_slides =[]
#raw_slides =[]
raw_footer = []
author_list = u''
author_audit = []
@ -297,7 +297,7 @@ class SongMediaItem(MediaManagerItem):
author_list = author_list + u', '
author_list = author_list + unicode(author.display_name)
author_audit.append(unicode(author.display_name))
if song.ccli_number == None or len(song.ccli_number) == 0:
if song.ccli_number is None or len(song.ccli_number) == 0:
ccl = self.parent.settings.GeneralTab.CCLNumber
else:
ccl = unicode(song.ccli_number)

View File

@ -24,7 +24,8 @@
import sys
import os
from types import StringType, ListType, NoneType
from types import StringType, ListType
sys.path.append(os.path.abspath(u'./../../../..'))
@ -84,7 +85,7 @@ class _OpenSong(XmlRootClass):
def from_buffer(self, xmlContent):
"""Initialize from buffer(string) with xml content"""
self._reset()
if xmlContent != None :
if xmlContent is not None:
self._setFromXml(xmlContent, 'song')
def get_author_list(self):
@ -94,9 +95,9 @@ class _OpenSong(XmlRootClass):
return as a string
"""
res = []
if self.author != None :
if self.author is not None:
lst = self.author.split(u' and ')
for l in lst :
for l in lst:
res.append(l.strip())
s = u', '.join(res)
return s
@ -107,9 +108,9 @@ class _OpenSong(XmlRootClass):
return as a string
"""
res = []
if self.theme != None :
if self.theme is not None:
res.append(self.theme)
if self.alttheme != None :
if self.alttheme is not None:
res.append(self.alttheme)
s = u', u'.join(res)
return s
@ -123,25 +124,25 @@ class _OpenSong(XmlRootClass):
res = []
for c in '1234567890 ':
tagPending = True
for l in tmpVerse :
if l.startswith(c) :
if tagPending :
for l in tmpVerse:
if l.startswith(c):
if tagPending:
tagPending = False
t = tag.strip(u'[]').lower()
if 'v' == t :
if 'v' == t:
newtag = "Verse"
elif 'c' == t :
elif 'c' == t:
newtag = "Chorus"
elif 'b' == t :
elif 'b' == t:
newtag = "Bridge"
elif 'p' == t :
elif 'p' == t:
newtag = "Pre-chorus"
else :
else:
newtag = t
s = (u'# %s %s'%(newtag, c)).rstrip()
res.append(s)
res.append(l[1:])
if (len(l) == 0) and (not tagPending) :
if (len(l) == 0) and (not tagPending):
res.append(l)
return res
@ -156,13 +157,13 @@ class _OpenSong(XmlRootClass):
tag = ""
for l in lyrics:
line = l.rstrip()
if not line.startswith(u'.') :
if not line.startswith(u'.'):
# drop all chords
tmpVerse.append(line)
if len(line) > 0 :
if len(line) > 0:
if line.startswith(u'['):
tag = line
else :
else:
r = self._reorder_verse(tag, tmpVerse)
finalLyrics.extend(r)
tag = ""
@ -173,12 +174,12 @@ class _OpenSong(XmlRootClass):
return finalLyrics
class Song(object) :
class Song(object):
"""Handling song properties and methods
handles all conversions between various input and output formats
CCLI :
CCLI:
from_ccli_text_file
to_ccli_text_file
from_ccli_text_buffer
@ -195,13 +196,13 @@ class Song(object) :
get_preview_slide
get_render_slide
openlp1 :
openlp1:
from_openlp1_lyrics_buffer
to_openlp1_lyrics_buffer
set_author_list
get_author_list
editing and openlp2 :
editing and openlp2:
set_*
get_*
"""
@ -263,13 +264,13 @@ class Song(object) :
"""Initialize from buffer(string) of xml lines in opensong format"""
self._reset()
opensong = _OpenSong(xmlcontent)
if opensong.title != None:
if opensong.title is not None:
self.set_title(opensong.title)
if opensong.copyright != None :
if opensong.copyright is not None:
self.set_copyright(opensong.copyright)
if opensong.presentation != None:
if opensong.presentation is not None:
self.set_verse_order(opensong.presentation)
if opensong.ccli != None:
if opensong.ccli is not None:
self.set_song_cclino(opensong.ccli)
self.set_author_list(opensong.get_author_list())
self.set_category_array(opensong.get_category_array())
@ -282,7 +283,7 @@ class Song(object) :
"""
lst = []
f = open(xmlfilename, 'r')
for line in f :
for line in f:
lst.append(line)
f.close()
xml = "".join(lst)
@ -295,7 +296,7 @@ class Song(object) :
"""
punctuation = ".,:;!?&%#'\"/\\@`$|^~*-"
s = title
for c in punctuation :
for c in punctuation:
s = s.replace(c, '')
return s
@ -308,9 +309,9 @@ class Song(object) :
"""
self.title = title.strip()
self.search_title = self._remove_punctuation(title).strip()
if len(self.title) < 1 :
if len(self.title) < 1:
raise SongTitleError(u'The title is empty')
if len(self.search_title) < 1 :
if len(self.search_title) < 1:
raise SongTitleError(u'The searchable title is empty')
def get_title(self):
@ -340,32 +341,32 @@ class Song(object) :
n = 0
metMisc = False
lyrics = []
for l in textList :
for l in textList:
n += 1
if lastpart > 0 :
if lastpart > 0:
lastpart += 1
if lastpart == 2 :
if lastpart == 2:
sCopyright = l[1:].strip()
if lastpart == 3 :
if lastpart == 3:
sAuthor = l
elif l.startswith(u'CCLI Song') :
elif l.startswith(u'CCLI Song'):
sCcli = l[13:].strip()
lastpart = 1
else :
if metMisc :
else:
if metMisc:
metMisc = False
if l.upper().startswith(u'(BRIDGE)') :
if l.upper().startswith(u'(BRIDGE)'):
lyrics.append(u'# Bridge')
# otherwise unknown misc keyword
elif l.startswith(u'Misc') :
elif l.startswith(u'Misc'):
metMisc = True
elif l.startswith(u'Verse') or l.startswith(u'Chorus'):
lyrics.append(u'# %s'%l)
else :
else:
# should we remove multiple blank lines?
if n == 1 :
if n == 1:
sName = l
else :
else:
lyrics.append(l)
# split on known separators
lst = sAuthor.split(u'/')
@ -390,33 +391,33 @@ class Song(object) :
f.close()
self.from_ccli_text_buffer(lines)
def _assure_string(self, s):
def _assure_string(self, string_in):
"""Force a string is returned"""
if s == None :
r = ""
else :
r = unicode(s)
return r
if string_in is None:
string_out = ""
else:
string_out = unicode(s)
return string_out
def _split_to_list(self, aString):
"""Split a string into a list - comma separated"""
res = []
if aString != None :
if aString is not None:
lst = aString.split(u',')
for l in lst :
for l in lst:
# remove whitespace
res.append(l.strip())
return res
def _list_to_string(self, strOrList):
"""Force a possibly list into a string"""
if type(strOrList) == StringType :
if type(strOrList) == StringType:
lst = self._split_to_list(strOrList)
elif type(strOrList) == ListType :
elif type(strOrList) == ListType:
lst = strOrList
elif type(strOrList) == NoneType :
elif strOrList is None:
lst = []
else :
else:
raise SongTypeError(u'Variable not String or List')
s = u', '.join(lst)
return s
@ -486,9 +487,9 @@ class Song(object) :
False -- list of strings
["John Newton", u'A Parker"]
"""
if asOneString :
if asOneString:
res = self._assure_string(self.author_list)
else :
else:
res = self._split_to_list(self.author_list)
return res
@ -497,9 +498,9 @@ class Song(object) :
author_list -- a string or list of strings
"""
if author_list == None :
if author_list is None:
self.author_list = None
else :
else:
self.author_list = self._list_to_string(author_list)
def get_category_array(self, asOneString = True):
@ -511,9 +512,9 @@ class Song(object) :
False -- list of strings
["Hymn", u'Gospel"]
"""
if asOneString :
if asOneString:
res = self._assure_string(self.category_array)
else :
else:
res = self._split_to_list(self.category_array)
return res
@ -522,9 +523,9 @@ class Song(object) :
category_array -- a string or list of strings
"""
if category_array == None :
if category_array is None:
self.category_array = None
else :
else:
self.category_array = self._list_to_string(category_array)
def get_show_title(self):
@ -577,12 +578,12 @@ class Song(object) :
self.slideList = []
tmpSlide = []
metContent = False
for l in self.lyrics :
if len(l) > 0 :
for l in self.lyrics:
if len(l) > 0:
metContent = True
tmpSlide.append(l)
else :
if metContent :
else:
if metContent:
metContent = False
self.slideList.append(tmpSlide)
tmpSlide = []
@ -598,22 +599,22 @@ class Song(object) :
def get_preview_slide(self, slideNumber):
"""Return the preview text for specified slide number
slideNumber -- 0: all slides, 1..n : specific slide
slideNumber -- 0: all slides, 1..n: specific slide
a list of strings are returned
"""
num = len(self.slideList)
if num < 1 :
if num < 1:
raise SongSlideError(u'No slides in this song')
elif slideNumber > num :
elif slideNumber > num:
raise SongSlideError(u'Slide number too high')
if slideNumber > 0 :
if slideNumber > 0:
# return this slide
res = self.slideList[slideNumber-1]
# find theme in this slide
else :
else:
res = []
for i in range(num):
if i > 0 :
if i > 0:
res.append(u'')
res.extend()
# remove formattingincluding themes
@ -633,26 +634,26 @@ class Song(object) :
lyric-part as a list of strings]
"""
num = len(self.slideList)
if num < 1 :
if num < 1:
raise SongSlideError(u'No slides in this song')
elif slideNumber > num :
elif slideNumber > num:
raise SongSlideError(u'Slide number too high')
res = []
if self.show_title :
if self.show_title:
title = self.get_title()
else :
else:
title = ""
if self.show_author_list :
if self.show_author_list:
author = self.get_author_list(True)
else :
else:
author = ""
if self.show_copyright :
if self.show_copyright:
cpright = self.get_copyright()
else :
else:
cpright = ""
if self.show_song_cclino :
if self.show_song_cclino:
ccli = self.get_song_cclino()
else :
else:
ccli = ""
theme = self.get_theme()
# examine the slide for a theme