More truth testing cleanup - plugins

This commit is contained in:
Jon Tibble 2009-11-03 19:01:53 +00:00
parent 84ce96f989
commit c2a0944e6b
19 changed files with 61 additions and 57 deletions

View File

@ -137,7 +137,7 @@ def main():
log.addHandler(logfile) log.addHandler(logfile)
# Parse command line options and deal with them. # Parse command line options and deal with them.
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if options.debug is not None: if options.debug:
log.setLevel(logging.DEBUG) log.setLevel(logging.DEBUG)
else: else:
log.setLevel(logging.INFO) log.setLevel(logging.INFO)

View File

@ -85,7 +85,7 @@ class BiblePlugin(Plugin):
self.ExportBibleItem.setVisible(False) self.ExportBibleItem.setVisible(False)
def onBibleNewClick(self): def onBibleNewClick(self):
if self.media_item is not None: if self.media_item:
self.media_item.onNewClick() self.media_item.onNewClick()
def about(self): def about(self):

View File

@ -199,7 +199,7 @@ class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog):
def onImportButtonClicked(self): def onImportButtonClicked(self):
message = self.trUtf8(u'Bible import completed') message = self.trUtf8(u'Bible import completed')
if self.biblemanager is not None: if self.biblemanager:
if not self.bible_type is None and \ if not self.bible_type is None and \
len(self.BibleNameEdit.displayText()) > 0: len(self.BibleNameEdit.displayText()) > 0:
self.MessageLabel.setText(self.trUtf8(u'Import Started')) self.MessageLabel.setText(self.trUtf8(u'Import Started'))
@ -208,7 +208,7 @@ class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog):
self.ProgressBar.setValue(0) self.ProgressBar.setValue(0)
self.biblemanager.process_dialog(self) self.biblemanager.process_dialog(self)
status, msg = self.importBible() status, msg = self.importBible()
if msg is not None: if msg:
message = msg message = msg
self.MessageLabel.setText(message) self.MessageLabel.setText(message)
self.ProgressBar.setValue(self.barmax) self.ProgressBar.setValue(self.barmax)

View File

@ -160,7 +160,7 @@ class BibleDBImpl(BibleCommon):
everse) everse)
#Look up book name or abbreviation #Look up book name or abbreviation
book = self.get_bible_book(bookname) book = self.get_bible_book(bookname)
if book is not None: if book:
bookname = book.name bookname = book.name
log.debug(u'bookname corrected to %s' % bookname) log.debug(u'bookname corrected to %s' % bookname)
verses = self.session.query(Verse).join(Book).filter( verses = self.session.query(Verse).join(Book).filter(

View File

@ -97,7 +97,7 @@ class BibleCommon(object):
The URL of a proxy server used to access the Internet. The URL of a proxy server used to access the Internet.
""" """
log.debug(u'get_web_text %s %s', proxyurl, urlstring) log.debug(u'get_web_text %s %s', proxyurl, urlstring)
if proxyurl is not None: if proxyurl:
proxy_support = urllib2.ProxyHandler({'http': self.proxyurl}) proxy_support = urllib2.ProxyHandler({'http': self.proxyurl})
http_support = urllib2.HTTPHandler() http_support = urllib2.HTTPHandler()
opener = urllib2.build_opener(proxy_support, http_support) opener = urllib2.build_opener(proxy_support, http_support)

View File

@ -97,7 +97,7 @@ class BibleManager(object):
# look to see if lazy load bible exists and get create getter. # look to see if lazy load bible exists and get create getter.
meta = self.bible_db_cache[bname].get_meta(u'proxy') meta = self.bible_db_cache[bname].get_meta(u'proxy')
proxy = None proxy = None
if meta is not None: if meta:
proxy = meta.value proxy = meta.value
# tell The Server where to get the verses from. # tell The Server where to get the verses from.
nhttp.set_proxy(proxy) nhttp.set_proxy(proxy)
@ -173,14 +173,14 @@ class BibleManager(object):
nbible.save_meta(u'WEB', biblesource) nbible.save_meta(u'WEB', biblesource)
# store the web id of the bible # store the web id of the bible
nbible.save_meta(u'bibleid', bibleid) nbible.save_meta(u'bibleid', bibleid)
if proxyurl is not None and proxyurl != u'': if proxyurl and proxyurl != u'':
# store the proxy URL # store the proxy URL
nbible.save_meta(u'proxy', proxyurl) nbible.save_meta(u'proxy', proxyurl)
nhttp.set_proxy(proxyurl) nhttp.set_proxy(proxyurl)
if proxyid is not None and proxyid != u'': if proxyid and proxyid != u'':
# store the proxy userid # store the proxy userid
nbible.save_meta(u'proxyid', proxyid) nbible.save_meta(u'proxyid', proxyid)
if proxypass is not None and proxypass != u'': if proxypass and proxypass != u'':
# store the proxy password # store the proxy password
nbible.save_meta(u'proxypass', proxypass) nbible.save_meta(u'proxypass', proxypass)
return True return True
@ -247,7 +247,7 @@ class BibleManager(object):
log.debug(u'get_bibles') log.debug(u'get_bibles')
bible_list = [] bible_list = []
for bible_name, bible_object in self.bible_db_cache.iteritems(): for bible_name, bible_object in self.bible_db_cache.iteritems():
if self.bible_http_cache[bible_name] is not None: if self.bible_http_cache[bible_name]:
bible_name = u'%s (%s)' % (bible_name, self.web) bible_name = u'%s (%s)' % (bible_name, self.web)
bible_list.append(bible_name) bible_list.append(bible_name)
return bible_list return bible_list
@ -338,13 +338,14 @@ class BibleManager(object):
# check to see if book/chapter exists fow HTTP bibles and load cache # check to see if book/chapter exists fow HTTP bibles and load cache
# if necessary # if necessary
web, bible = self.is_bible_web(bible) web, bible = self.is_bible_web(bible)
if self.bible_http_cache[bible] is not None: if self.bible_http_cache[bible]:
book = self.bible_db_cache[bible].get_bible_book(bookname) book = self.bible_db_cache[bible].get_bible_book(bookname)
if book is None: if book is None:
log.debug(u'get_verse_text : new book') log.debug(u'get_verse_text : new book')
for chapter in range(schapter, echapter + 1): for chapter in range(schapter, echapter + 1):
self.media.setQuickMessage( self.media.setQuickMessage(
unicode(self.media.trUtf8(u'Downloading %s: %s')) % (bookname, chapter)) unicode(self.media.trUtf8(u'Downloading %s: %s')) %
(bookname, chapter))
search_results = \ search_results = \
self.bible_http_cache[bible].get_bible_chapter( self.bible_http_cache[bible].get_bible_chapter(
bible, bookname, chapter) bible, bookname, chapter)

View File

@ -380,7 +380,7 @@ class BibleMediaItem(MediaManagerItem):
bible, text) bible, text)
else: else:
self.searchByReference(bible, text) self.searchByReference(bible, text)
if self.search_results is not None: if self.search_results:
self.displayResults(bible) self.displayResults(bible)
def generateSlideData(self, service_item): def generateSlideData(self, service_item):
@ -518,9 +518,9 @@ class BibleMediaItem(MediaManagerItem):
bible_verse.setData(QtCore.Qt.UserRole, bible_verse.setData(QtCore.Qt.UserRole,
QtCore.QVariant(bible_text)) QtCore.QVariant(bible_text))
self.ListView.addItem(bible_verse) self.ListView.addItem(bible_verse)
cr = self.ListView.setCurrentRow(count) row = self.ListView.setCurrentRow(count)
if cr is not None: if row:
cr.setSelected(True) row.setSelected(True)
def searchByReference(self, bible, search): def searchByReference(self, bible, search):
log.debug(u'searchByReference %s, %s', bible, search) log.debug(u'searchByReference %s, %s', bible, search)

View File

@ -90,14 +90,14 @@ class CustomMediaItem(MediaManagerItem):
def onRemoteEdit(self, item_id): def onRemoteEdit(self, item_id):
valid = self.parent.custommanager.get_custom(item_id) valid = self.parent.custommanager.get_custom(item_id)
if valid is not None: if valid:
self.fromServiceManager = item_id self.fromServiceManager = item_id
self.parent.edit_custom_form.loadCustom(item_id) self.parent.edit_custom_form.loadCustom(item_id)
self.parent.edit_custom_form.exec_() self.parent.edit_custom_form.exec_()
def onEditClick(self): def onEditClick(self):
item = self.ListView.currentItem() item = self.ListView.currentItem()
if item is not None: if item:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.parent.edit_custom_form.loadCustom(item_id) self.parent.edit_custom_form.loadCustom(item_id)
self.parent.edit_custom_form.exec_() self.parent.edit_custom_form.exec_()
@ -105,7 +105,7 @@ class CustomMediaItem(MediaManagerItem):
def onDeleteClick(self): def onDeleteClick(self):
item = self.ListView.currentItem() item = self.ListView.currentItem()
if item is not None: if item:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.parent.custommanager.delete_custom(item_id) self.parent.custommanager.delete_custom(item_id)
row = self.ListView.row(item) row = self.ListView.row(item)
@ -137,7 +137,7 @@ class CustomMediaItem(MediaManagerItem):
for verse in verseList: for verse in verseList:
raw_slides.append(verse[1]) raw_slides.append(verse[1])
raw_footer.append(title + u' '+ credit) raw_footer.append(title + u' '+ credit)
if theme is not None: if theme:
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)

View File

@ -96,7 +96,7 @@ class MediaMediaItem(MediaManagerItem):
def onDeleteClick(self): def onDeleteClick(self):
item = self.ListView.currentItem() item = self.ListView.currentItem()
if item is not None: if item:
row = self.ListView.row(item) row = self.ListView.row(item)
self.ListView.takeItem(row) self.ListView.takeItem(row)
self.parent.config.set_list( self.parent.config.set_list(

View File

@ -225,8 +225,8 @@ class ImpressController(PresentationController):
Triggerent by new object being added to SlideController orOpenLP Triggerent by new object being added to SlideController orOpenLP
being shut down being shut down
""" """
if self.document is not None: if self.document:
if self.presentation is not None: if self.presentation:
self.presentation.end() self.presentation.end()
self.presentation = None self.presentation = None
self.document.dispose() self.document.dispose()

View File

@ -121,7 +121,7 @@ class PresentationMediaItem(MediaManagerItem):
def onDeleteClick(self): def onDeleteClick(self):
item = self.ListView.currentItem() item = self.ListView.currentItem()
if item is not None: if item:
row = self.ListView.row(item) row = self.ListView.row(item)
self.ListView.takeItem(row) self.ListView.takeItem(row)
self.parent.config.set_list( self.parent.config.set_list(
@ -146,7 +146,7 @@ class PresentationMediaItem(MediaManagerItem):
cont.load_presentation(filename) cont.load_presentation(filename)
i = 1 i = 1
img = cont.get_slide_preview_file(i) img = cont.get_slide_preview_file(i)
while img is not None: while img:
service_item.add_from_command(path, name, img) service_item.add_from_command(path, name, img)
i = i + 1 i = i + 1
img = cont.get_slide_preview_file(i) img = cont.get_slide_preview_file(i)

View File

@ -86,7 +86,7 @@ class MessageListener(object):
def slide(self, message): def slide(self, message):
self.activate() self.activate()
if message is not None: if message:
self.controller.goto_slide(message[0]+1) self.controller.goto_slide(message[0]+1)
self.controller.poll_slidenumber() self.controller.poll_slidenumber()

View File

@ -78,7 +78,7 @@ class PptviewController(PresentationController):
""" """
Loads the PPTVIEWLIB library Loads the PPTVIEWLIB library
""" """
if self.process is not None: if self.process:
return return
log.debug(u'start PPTView') log.debug(u'start PPTView')
self.process = cdll.LoadLibrary(r'openlp\plugins\presentations\lib\pptviewlib\pptviewlib.dll') self.process = cdll.LoadLibrary(r'openlp\plugins\presentations\lib\pptviewlib\pptviewlib.dll')

View File

@ -69,7 +69,7 @@ def main():
elif options.address is None: elif options.address is None:
parser.print_help() parser.print_help()
parser.error("IP address missing") parser.error("IP address missing")
elif options.slidenext is not None: elif options.slidenext:
options.event = u'next_slide' options.event = u'next_slide'
options.message = u'' options.message = u''
text = format_message(options) text = format_message(options)

View File

@ -55,7 +55,7 @@ class RemotesPlugin(Plugin):
def finalise(self): def finalise(self):
log.debug(u'finalise') log.debug(u'finalise')
self.remove_toolbox_item() self.remove_toolbox_item()
if self.server is not None: if self.server:
self.server.close() self.server.close()
def get_settings_tab(self): def get_settings_tab(self):

View File

@ -183,7 +183,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
# Not Found # Not Found
id = 0 id = 0
self.SongbookCombo.setCurrentIndex(id) self.SongbookCombo.setCurrentIndex(id)
if self.song.theme_name is not None and len(self.song.theme_name) > 0: if self.song.theme_name:
id = self.ThemeSelectionComboItem.findText( id = self.ThemeSelectionComboItem.findText(
unicode(self.song.theme_name), QtCore.Qt.MatchExactly) unicode(self.song.theme_name), QtCore.Qt.MatchExactly)
if id == -1: if id == -1:
@ -193,20 +193,20 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.ThemeSelectionComboItem.setCurrentIndex(id) self.ThemeSelectionComboItem.setCurrentIndex(id)
if len(title) > 1: if len(title) > 1:
self.AlternativeEdit.setText(title[1]) self.AlternativeEdit.setText(title[1])
if self.song.copyright is not None: if self.song.copyright:
self.CopyrightEditItem.setText(self.song.copyright) self.CopyrightEditItem.setText(self.song.copyright)
else: else:
self.CopyrightEditItem.setText(u'') self.CopyrightEditItem.setText(u'')
self.VerseListWidget.clear() self.VerseListWidget.clear()
if self.song.verse_order is not None: if self.song.verse_order:
self.VerseOrderEdit.setText(self.song.verse_order) self.VerseOrderEdit.setText(self.song.verse_order)
else: else:
self.VerseOrderEdit.setText(u'') self.VerseOrderEdit.setText(u'')
if self.song.comments is not None: if self.song.comments:
self.CommentsEdit.setPlainText(self.song.comments) self.CommentsEdit.setPlainText(self.song.comments)
else: else:
self.CommentsEdit.setPlainText(u'') self.CommentsEdit.setPlainText(u'')
if self.song.ccli_number is not None: if self.song.ccli_number:
self.CCLNumberEdit.setText(self.song.ccli_number) self.CCLNumberEdit.setText(self.song.ccli_number)
else: else:
self.CCLNumberEdit.setText(u'') self.CCLNumberEdit.setText(u'')
@ -311,7 +311,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
def onVerseEditButtonClicked(self): def onVerseEditButtonClicked(self):
item = self.VerseListWidget.currentItem() item = self.VerseListWidget.currentItem()
if item is not None: if item:
tempText = item.text() tempText = item.text()
self.verse_form.setVerse(tempText) self.verse_form.setVerse(tempText)
self.verse_form.exec_() self.verse_form.exec_()

View File

@ -68,7 +68,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
def _getCurrentItemId(self, ListWidget): def _getCurrentItemId(self, ListWidget):
item = ListWidget.currentItem() item = ListWidget.currentItem()
if item is not None: if item:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
return item_id return item_id
else: else:
@ -79,9 +79,10 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
item_id = self._getCurrentItemId(list_widget) item_id = self._getCurrentItemId(list_widget)
if item_id != -1: if item_id != -1:
item = get_func(item_id) item = get_func(item_id)
if item is not None and len(item.songs) == 0: if item and len(item.songs) == 0:
if QtGui.QMessageBox.warning(self, dlg_title, del_text, if QtGui.QMessageBox.warning(self, dlg_title, del_text,
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | QtGui.QMessageBox.Yes) QtGui.QMessageBox.StandardButtons(
QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)
) == QtGui.QMessageBox.Yes: ) == QtGui.QMessageBox.Yes:
del_func(item.id) del_func(item.id)
reset_func() reset_func()
@ -96,7 +97,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
self.AuthorsListWidget.clear() self.AuthorsListWidget.clear()
authors = self.songmanager.get_authors() authors = self.songmanager.get_authors()
for author in authors: for author in authors:
if author.display_name is not None and author.display_name != u'': if author.display_name:
author_name = QtGui.QListWidgetItem(author.display_name) author_name = QtGui.QListWidgetItem(author.display_name)
else: else:
author_name = QtGui.QListWidgetItem( author_name = QtGui.QListWidgetItem(

View File

@ -53,11 +53,13 @@ class SongMediaItem(MediaManagerItem):
self.edit_song_form = EditSongForm(self.parent.songmanager, self) self.edit_song_form = EditSongForm(self.parent.songmanager, self)
self.song_maintenance_form = SongMaintenanceForm( self.song_maintenance_form = SongMaintenanceForm(
self.parent.songmanager, self) self.parent.songmanager, self)
#fromPreview holds the id of the item if the song editor needs to trigger a preview # fromPreview holds the id of the item if the song editor needs to
#without closing. It is set to -1 if this function is inactive # trigger a preview without closing. It is set to -1 if this
# function is inactive.
self.fromPreview = -1 self.fromPreview = -1
#fromServiceManager holds the id of the item if the song editor needs to trigger posting # fromServiceManager holds the id of the item if the song editor needs
#to the servicemanager without closing. It is set to -1 if this function is inactive # to trigger posting to the servicemanager without closing. It is set
# to -1 if this function is inactive.
self.fromServiceManager = -1 self.fromServiceManager = -1
def initPluginNameVisible(self): def initPluginNameVisible(self):
@ -244,14 +246,14 @@ class SongMediaItem(MediaManagerItem):
def onRemoteEdit(self, songid): def onRemoteEdit(self, songid):
valid = self.parent.songmanager.get_song(songid) valid = self.parent.songmanager.get_song(songid)
if valid is not None: if valid:
self.fromServiceManager = songid self.fromServiceManager = songid
self.edit_song_form.loadSong(songid, False) self.edit_song_form.loadSong(songid, False)
self.edit_song_form.exec_() self.edit_song_form.exec_()
def onEditClick(self, preview=False): def onEditClick(self, preview=False):
item = self.ListView.currentItem() item = self.ListView.currentItem()
if item is not None: if item:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.fromPreview = -1 self.fromPreview = -1
if preview: if preview:
@ -264,7 +266,7 @@ class SongMediaItem(MediaManagerItem):
def onDeleteClick(self): def onDeleteClick(self):
item = self.ListView.currentItem() item = self.ListView.currentItem()
if item is not None: if item:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.parent.songmanager.delete_song(item_id) self.parent.songmanager.delete_song(item_id)
row = self.ListView.row(item) row = self.ListView.row(item)
@ -295,7 +297,7 @@ class SongMediaItem(MediaManagerItem):
songXML=SongXMLParser(song.lyrics) songXML=SongXMLParser(song.lyrics)
verseList = songXML.get_verses() verseList = songXML.get_verses()
for verse in verseList: for verse in verseList:
if verse[1] is not None: if verse[1]:
service_item.add_from_text(verse[1][:30], verse[1]) service_item.add_from_text(verse[1][:30], verse[1])
else: else:
verses = song.lyrics.split(u'\n\n') verses = song.lyrics.split(u'\n\n')

View File

@ -85,7 +85,7 @@ class _OpenSong(XmlRootClass):
def from_buffer(self, xmlContent): def from_buffer(self, xmlContent):
"""Initialize from buffer(string) with xml content""" """Initialize from buffer(string) with xml content"""
self._reset() self._reset()
if xmlContent is not None: if xmlContent:
self._setFromXml(xmlContent, 'song') self._setFromXml(xmlContent, 'song')
def get_author_list(self): def get_author_list(self):
@ -95,7 +95,7 @@ class _OpenSong(XmlRootClass):
return as a string return as a string
""" """
res = [] res = []
if self.author is not None: if self.author:
lst = self.author.split(u' and ') lst = self.author.split(u' and ')
for l in lst: for l in lst:
res.append(l.strip()) res.append(l.strip())
@ -108,9 +108,9 @@ class _OpenSong(XmlRootClass):
return as a string return as a string
""" """
res = [] res = []
if self.theme is not None: if self.theme:
res.append(self.theme) res.append(self.theme)
if self.alttheme is not None: if self.alttheme:
res.append(self.alttheme) res.append(self.alttheme)
s = u', u'.join(res) s = u', u'.join(res)
return s return s
@ -264,13 +264,13 @@ class Song(object):
"""Initialize from buffer(string) of xml lines in opensong format""" """Initialize from buffer(string) of xml lines in opensong format"""
self._reset() self._reset()
opensong = _OpenSong(xmlcontent) opensong = _OpenSong(xmlcontent)
if opensong.title is not None: if opensong.title:
self.set_title(opensong.title) self.set_title(opensong.title)
if opensong.copyright is not None: if opensong.copyright:
self.set_copyright(opensong.copyright) self.set_copyright(opensong.copyright)
if opensong.presentation is not None: if opensong.presentation:
self.set_verse_order(opensong.presentation) self.set_verse_order(opensong.presentation)
if opensong.ccli is not None: if opensong.ccli:
self.set_song_cclino(opensong.ccli) self.set_song_cclino(opensong.ccli)
self.set_author_list(opensong.get_author_list()) self.set_author_list(opensong.get_author_list())
self.set_category_array(opensong.get_category_array()) self.set_category_array(opensong.get_category_array())
@ -402,7 +402,7 @@ class Song(object):
def _split_to_list(self, aString): def _split_to_list(self, aString):
"""Split a string into a list - comma separated""" """Split a string into a list - comma separated"""
res = [] res = []
if aString is not None: if aString:
lst = aString.split(u',') lst = aString.split(u',')
for l in lst: for l in lst:
# remove whitespace # remove whitespace