From aabe4e82f3bba2ce9d30c39fe619e36e1980e785 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 7 Jun 2009 19:39:31 +0100 Subject: [PATCH] Fix problem with single number for set of chapters eg John 1:1-5. Add double click feature to add preview (missing from 1.x) Move formatting cleanups on open classes. --- openlp/plugins/bibles/lib/mediaitem.py | 33 ++++++++++++++--------- openlp/plugins/bibles/lib/textlistdata.py | 31 ++++++++++----------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index d287c447e..2a5721b92 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -225,9 +225,10 @@ class BibleMediaItem(MediaManagerItem): QtCore.SIGNAL(u'pressed()'), self.onAdvancedSearchButton) QtCore.QObject.connect(self.QuickSearchButton, QtCore.SIGNAL(u'pressed()'), self.onQuickSearchButton) + QtCore.QObject.connect(self.BibleListView, + QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.onRowSelected) # Context Menus self.BibleListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) - self.BibleListView.addAction(self.contextMenuAction( self.BibleListView, u':/system/system_preview.png', translate(u'BibleMediaItem',u'&Preview Verse'), self.onBiblePreviewClick)) @@ -238,6 +239,7 @@ class BibleMediaItem(MediaManagerItem): self.BibleListView, u':/system/system_add.png', translate(u'BibleMediaItem',u'&Add to Service'), self.onBibleAddClick)) + def retranslateUi(self): log.debug(u'retranslateUi') self.QuickVersionLabel.setText(translate(u'BibleMediaItem', u'Version:')) @@ -260,6 +262,9 @@ class BibleMediaItem(MediaManagerItem): self.ClearAdvancedSearchComboBox.addItem(translate(u'BibleMediaItem', u'Clear')) self.ClearAdvancedSearchComboBox.addItem(translate(u'BibleMediaItem', u'Keep')) + def onRowSelected(self, row): + self.onBiblePreviewClick() + def initialise(self): log.debug(u'initialise') self.loadBibles() @@ -370,8 +375,8 @@ class BibleMediaItem(MediaManagerItem): bible_text = u'' for item in items: text = self.BibleListData.getValue(item) - verse = text[:text.find(u'(u')] - bible = text[text.find(u'(u') + 1:text.find(u')')] + verse = text[:text.find(u'(')] + bible = text[text.find(u'(') + 1:text.find(u')')] self.searchByReference(bible, verse) book = self.search_results[0][0] chapter = str(self.search_results[0][1]) @@ -380,7 +385,7 @@ class BibleMediaItem(MediaManagerItem): if self.parent.bibles_tab.paragraph_style: #Paragraph text = text + u'\n\n' if self.parent.bibles_tab.display_style == 1: - loc = self.formatVerse(old_chapter, chapter, verse, u'(u', u')') + loc = self.formatVerse(old_chapter, chapter, verse, u'(', u')') elif self.parent.bibles_tab.display_style == 2: loc = self.formatVerse(old_chapter, chapter, verse, u'{', u'}') elif self.parent.bibles_tab.display_style == 3: @@ -457,14 +462,16 @@ class BibleMediaItem(MediaManagerItem): search = search.replace(u' ', ' ').strip() original = search message = None - # Remove book - for i in range (len(search)-1, 0, -1): # 0 index arrays + # Remove book beware 0 index arrays + for i in range (len(search)-1, 0, - 1): if search[i] == ' ': book = search[:i] - search = search[i:] # remove book from string + # remove book from string + search = search[i:] break - search = search.replace(u'v', ':') # allow V or v for verse instead of : - search = search.replace(u'V', ':') # allow V or v for verse instead of : + # allow V or v for verse instead of : + search = search.replace(u'v', ':') + search = search.replace(u'V', ':') search = search.strip() colon = search.find(u':') if colon == -1: @@ -498,13 +505,15 @@ class BibleMediaItem(MediaManagerItem): end_verse = start_verse else: sp1 = sp[1].split(u':') - #print sp1, len(sp1) + #print "2nd details", sp1, len(sp1) if len(sp1) == 1: - end_chapter = sp1[0] - end_verse = 1 + end_chapter = start_chapter + end_verse = sp1[0] else: end_chapter = sp1[0] end_verse = sp1[1] + #print 'search = ' + str(original) + #print 'results = ' + str(book) + ' @ '+ str(start_chapter)+' @ '+ str(end_chapter)+' @ '+ str(start_verse)+ ' @ '+ str(end_verse) if end_chapter == '': end_chapter = start_chapter.rstrip() if start_verse == '': diff --git a/openlp/plugins/bibles/lib/textlistdata.py b/openlp/plugins/bibles/lib/textlistdata.py index 16ef37db5..774a2c9a5 100644 --- a/openlp/plugins/bibles/lib/textlistdata.py +++ b/openlp/plugins/bibles/lib/textlistdata.py @@ -19,21 +19,21 @@ Place, Suite 330, Boston, MA 02111-1307 USA """ import logging -from PyQt4.QtCore import * -from PyQt4.QtGui import * +from PyQt4 import QtCore, QtGui -class TextListData(QAbstractListModel): +class TextListData(QtCore.QAbstractListModel): """ An abstract list of strings """ global log - log=logging.getLogger(u'TextListData') + log = logging.getLogger(u'TextListData') log.info(u'started') def __init__(self): - QAbstractListModel.__init__(self) - self.items = [] # will be a list of (database id , title) tuples + QtCore.QAbstractListModel.__init__(self) + # will be a list of (database id , title) tuples + self.items = [] def resetStore(self): #reset list so can be reloaded @@ -43,8 +43,8 @@ class TextListData(QAbstractListModel): return len(self.items) def insertRow(self, row, id, title): - self.beginInsertRows(QModelIndex(),row,row) - log.debug(u'insert row %d:%s for id %d'%(row,title, id)) + self.beginInsertRows(QtCore.QModelIndex(),row,row) + log.debug(u'insert row %d:%s for id %d' % (row,title, id)) self.items.insert(row, (id, title)) self.endInsertRows() @@ -57,15 +57,16 @@ class TextListData(QAbstractListModel): self.insertRow(len(self.items), id, title) def data(self, index, role): - row=index.row() - if row > len(self.items): # if the last row is selected and deleted, we then get called with an empty row! - return QVariant() - if role == Qt.DisplayRole: + row = index.row() + # if the last row is selected and deleted, we then get called with an empty row! + if row > len(self.items): + return QtCore.QVariant() + if role == QtCore.Qt.DisplayRole: retval = self.items[row][1] else: - retval = QVariant() - if type(retval) is not type(QVariant): - return QVariant(retval) + retval = QtCore.QVariant() + if type(retval) is not type(QtCore.QVariant): + return QtCore.QVariant(retval) else: return retval