Truth tests and some style fixes

This commit is contained in:
Jon Tibble 2010-03-09 19:43:11 +00:00
parent 51d95b661c
commit e40f1b41ef
12 changed files with 33 additions and 33 deletions

View File

@ -314,7 +314,7 @@ class MediaManagerItem(QtGui.QWidget):
self, self.OnNewPrompt, self, self.OnNewPrompt,
self.parent.config.get_last_dir(), self.OnNewFileMasks) self.parent.config.get_last_dir(), self.OnNewFileMasks)
log.info(u'New files(s)%s', unicode(files)) log.info(u'New files(s)%s', unicode(files))
if len(files) > 0: if files:
self.loadList(files) self.loadList(files)
dir, filename = os.path.split(unicode(files[0])) dir, filename = os.path.split(unicode(files[0]))
self.parent.config.set_last_dir(dir) self.parent.config.set_last_dir(dir)

View File

@ -174,7 +174,7 @@ class Renderer(object):
#Must be a blank line so keep it. #Must be a blank line so keep it.
if len(line) == 0: if len(line) == 0:
line = u' ' line = u' '
while len(line) > 0: while line:
pos = char_per_line pos = char_per_line
split_text = line[:pos] split_text = line[:pos]
#line needs splitting #line needs splitting
@ -199,7 +199,7 @@ class Renderer(object):
split_lines.append(split_text) split_lines.append(split_text)
line = line[pos:].lstrip() line = line[pos:].lstrip()
#if we have more text add up to 10 spaces on the front. #if we have more text add up to 10 spaces on the front.
if len(line) > 0 and self._theme.font_main_indentation > 0: if line and self._theme.font_main_indentation > 0:
line = u'%s%s' % \ line = u'%s%s' % \
(u' '[:int(self._theme.font_main_indentation)], line) (u' '[:int(self._theme.font_main_indentation)], line)
#Text fits in a line now #Text fits in a line now
@ -210,7 +210,7 @@ class Renderer(object):
len(page) == page_length: len(page) == page_length:
split_pages.append(page) split_pages.append(page)
page = [] page = []
if len(page) > 0 and page != u' ': if page and page != u' ':
split_pages.append(page) split_pages.append(page)
return split_pages return split_pages

View File

@ -171,7 +171,8 @@ class ThemeXML(object):
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', def add_font(self, name, color, proportion, override, fonttype=u'main',
weight=u'Normal', italics=u'False', indentation=0, xpos=0, ypos=0, width=0, height=0): weight=u'Normal', italics=u'False', indentation=0, xpos=0, ypos=0,
width=0, height=0):
""" """
Add a Font. Add a Font.
@ -363,14 +364,14 @@ class ThemeXML(object):
master = u'' master = u''
for element in iter: for element in iter:
element.text = unicode(element.text).decode('unicode-escape') element.text = unicode(element.text).decode('unicode-escape')
if len(element.getchildren()) > 0: if element.getchildren():
master = element.tag + u'_' master = element.tag + u'_'
else: else:
#background transparent tags have no children so special case #background transparent tags have no children so special case
if element.tag == u'background': if element.tag == u'background':
for e in element.attrib.iteritems(): for e in element.attrib.iteritems():
setattr(self, element.tag + u'_' + e[0], e[1]) setattr(self, element.tag + u'_' + e[0], e[1])
if len(element.attrib) > 0: if element.attrib:
for e in element.attrib.iteritems(): for e in element.attrib.iteritems():
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'_'
@ -402,4 +403,4 @@ class ThemeXML(object):
for key in dir(self): for key in dir(self):
if key[0:1] != u'_': if key[0:1] != u'_':
theme_strings.append(u'%30s: %s' % (key, getattr(self, key))) theme_strings.append(u'%30s: %s' % (key, getattr(self, key)))
return u'\n'.join(theme_strings) return u'\n'.join(theme_strings)

View File

@ -428,7 +428,7 @@ class ServiceManager(QtGui.QWidget):
for itemcount, item in enumerate(self.serviceItems): for itemcount, item in enumerate(self.serviceItems):
serviceitem = item[u'service_item'] serviceitem = item[u'service_item']
treewidgetitem = QtGui.QTreeWidgetItem(self.ServiceManagerList) treewidgetitem = QtGui.QTreeWidgetItem(self.ServiceManagerList)
if len(serviceitem.notes) > 0: if serviceitem.notes:
icon = QtGui.QImage(serviceitem.icon) icon = QtGui.QImage(serviceitem.icon)
icon = icon.scaled(80, 80, QtCore.Qt.KeepAspectRatio, icon = icon.scaled(80, 80, QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation) QtCore.Qt.SmoothTransformation)
@ -601,7 +601,7 @@ class ServiceManager(QtGui.QWidget):
def regenerateServiceItems(self): def regenerateServiceItems(self):
#force reset of renderer as theme data has changed #force reset of renderer as theme data has changed
self.parent.RenderManager.themedata = None self.parent.RenderManager.themedata = None
if len(self.serviceItems) > 0: if self.serviceItems:
tempServiceItems = self.serviceItems tempServiceItems = self.serviceItems
self.ServiceManagerList.clear() self.ServiceManagerList.clear()
self.serviceItems = [] self.serviceItems = []
@ -663,7 +663,7 @@ class ServiceManager(QtGui.QWidget):
if str_to_bool(PluginConfig(u'General'). if str_to_bool(PluginConfig(u'General').
get_config(u'auto preview', u'False')): get_config(u'auto preview', u'False')):
item += 1 item += 1
if len(self.serviceItems) > 0 and item < len(self.serviceItems) and \ if self.serviceItems and item < len(self.serviceItems) and \
self.serviceItems[item][u'service_item'].autoPreviewAllowed: self.serviceItems[item][u'service_item'].autoPreviewAllowed:
self.parent.PreviewController.addServiceManagerItem( self.parent.PreviewController.addServiceManagerItem(
self.serviceItems[item][u'service_item'], 0) self.serviceItems[item][u'service_item'], 0)

View File

@ -246,7 +246,7 @@ class ThemeManager(QtGui.QWidget):
self, self.trUtf8('Select Theme Import File'), self, self.trUtf8('Select Theme Import File'),
self.config.get_last_dir(), u'Theme (*.*)') self.config.get_last_dir(), u'Theme (*.*)')
log.info(u'New Themes %s', unicode(files)) log.info(u'New Themes %s', unicode(files))
if len(files) > 0: if files:
for file in files: for file in files:
self.config.set_last_dir(unicode(file)) self.config.set_last_dir(unicode(file))
self.unzipTheme(file, self.path) self.unzipTheme(file, self.path)

View File

@ -82,7 +82,7 @@ class AlertEditForm(QtGui.QDialog, Ui_AlertEditDialog):
self.DeleteButton.setEnabled(False) self.DeleteButton.setEnabled(False)
def onItemSelected(self): def onItemSelected(self):
if len(self.AlertLineEdit.text()) > 0: if self.AlertLineEdit.text():
QtGui.QMessageBox.information(self, QtGui.QMessageBox.information(self,
self.trUtf8('Item selected to Edit'), self.trUtf8('Item selected to Edit'),
self.trUtf8('Please Save or Clear seletced item')) self.trUtf8('Please Save or Clear seletced item'))

View File

@ -77,7 +77,7 @@ class HTTPBooks(object):
books = HTTPBooks.run_sql(u'SELECT id, testament_id, name, ' books = HTTPBooks.run_sql(u'SELECT id, testament_id, name, '
u'abbreviation, chapters FROM books WHERE name = ? OR ' u'abbreviation, chapters FROM books WHERE name = ? OR '
u'abbreviation = ?', (name, name)) u'abbreviation = ?', (name, name))
if len(books) > 0: if books:
return { return {
u'id': books[0][0], u'id': books[0][0],
u'testament_id': books[0][1], u'testament_id': books[0][1],
@ -95,7 +95,7 @@ class HTTPBooks(object):
book = HTTPBooks.get_book(name) book = HTTPBooks.get_book(name)
chapters = HTTPBooks.run_sql(u'SELECT id, book_id, chapter, ' chapters = HTTPBooks.run_sql(u'SELECT id, book_id, chapter, '
u'verses FROM chapters WHERE book_id = ?', (book[u'id'],)) u'verses FROM chapters WHERE book_id = ?', (book[u'id'],))
if len(chapters) > 0: if chapters:
return { return {
u'id': chapters[0][0], u'id': chapters[0][0],
u'book_id': chapters[0][1], u'book_id': chapters[0][1],

View File

@ -254,7 +254,7 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
if self.VerseListView.count() == 0: if self.VerseListView.count() == 0:
self.VerseTextEdit.setFocus() self.VerseTextEdit.setFocus()
return False, self.trUtf8('You need to enter a slide') return False, self.trUtf8('You need to enter a slide')
if len(self.VerseTextEdit.toPlainText()) > 0: if self.VerseTextEdit.toPlainText():
self.VerseTextEdit.setFocus() self.VerseTextEdit.setFocus()
return False, self.trUtf8('You have unsaved data') return False, self.trUtf8('You have unsaved data')
return True, u'' return True, u''

View File

@ -151,7 +151,7 @@ class CustomMediaItem(MediaManagerItem):
service_item.edit_enabled = True service_item.edit_enabled = True
service_item.editId = item_id service_item.editId = item_id
theme = customSlide.theme_name theme = customSlide.theme_name
if len(theme) is not 0 : if theme:
service_item.theme = theme service_item.theme = theme
songXML = SongXMLParser(customSlide.text) songXML = SongXMLParser(customSlide.text)
verseList = songXML.get_verses() verseList = songXML.get_verses()
@ -160,9 +160,9 @@ class CustomMediaItem(MediaManagerItem):
service_item.title = title service_item.title = title
for slide in raw_slides: for slide in raw_slides:
service_item.add_from_text(slide[:30], slide) service_item.add_from_text(slide[:30], slide)
if str_to_bool(self.parent.config.get_config(u'display footer', True)) or \ if str_to_bool(self.parent.config.get_config(u'display footer', True)) \
len(credit) > 0: or credit:
raw_footer.append(title + u' '+ credit) raw_footer.append(title + u' ' + credit)
else: else:
raw_footer.append(u'') raw_footer.append(u'')
service_item.raw_footer = raw_footer service_item.raw_footer = raw_footer

View File

@ -103,7 +103,7 @@ class PresentationPlugin(Plugin):
self.registerControllers(controller) self.registerControllers(controller)
if controller.enabled: if controller.enabled:
controller.start_process() controller.start_process()
if len(self.controllers) > 0: if self.controllers:
return True return True
else: else:
return False return False

View File

@ -54,7 +54,7 @@ def main():
help="Message to be passed for the action") help="Message to be passed for the action")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if len(args) > 0: if args:
parser.print_help() parser.print_help()
parser.error("incorrect number of arguments") parser.error("incorrect number of arguments")
elif options.address is None: elif options.address is None:

View File

@ -153,12 +153,12 @@ class _OpenSong(XmlRootClass):
tmpVerse = [] tmpVerse = []
finalLyrics = [] finalLyrics = []
tag = "" tag = ""
for l in lyrics: for lyric in lyrics:
line = l.rstrip() line = lyric.rstrip()
if not line.startswith(u'.'): if not line.startswith(u'.'):
# drop all chords # drop all chords
tmpVerse.append(line) tmpVerse.append(line)
if len(line) > 0: if line:
if line.startswith(u'['): if line.startswith(u'['):
tag = line tag = line
else: else:
@ -298,9 +298,9 @@ class Song(object):
chars are: .,:;!?&%#/\@`$'|"^~*- chars are: .,:;!?&%#/\@`$'|"^~*-
""" """
punctuation = ".,:;!?&%#'\"/\\@`$|^~*-" punctuation = ".,:;!?&%#'\"/\\@`$|^~*-"
s = title string = title
for c in punctuation: for char in punctuation:
s = s.replace(c, '') string = string.replace(char, '')
return s return s
def set_title(self, title): def set_title(self, title):
@ -582,17 +582,16 @@ class Song(object):
self.slideList = [] self.slideList = []
tmpSlide = [] tmpSlide = []
metContent = False metContent = False
for l in self.lyrics: for lyric in self.lyrics:
if len(l) > 0: if lyric:
metContent = True metContent = True
tmpSlide.append(l) tmpSlide.append(lyric)
else: else:
if metContent: if metContent:
metContent = False metContent = False
self.slideList.append(tmpSlide) self.slideList.append(tmpSlide)
tmpSlide = [] tmpSlide = []
# if tmpSlide:
if len(tmpSlide) > 0:
self.slideList.append(tmpSlide) self.slideList.append(tmpSlide)
def get_number_of_slides(self): def get_number_of_slides(self):