diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py index 972aaed3c..2f498538e 100644 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ b/openlp/plugins/bibles/forms/bibleimportform.py @@ -23,19 +23,16 @@ import sys import time import logging -from openlp.core.resources import * - from PyQt4 import QtCore, QtGui -from PyQt4.QtGui import QDialog from bibleimportdialog import Ui_BibleImportDialog -from openlp.core.lib import Receiver +from openlp.core.lib import Receiver, translate -class BibleImportForm(QDialog, Ui_BibleImportDialog): +class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog): global log log=logging.getLogger("BibleImportForm") - log.info("BibleImportForm loaded") + log.info("BibleImportForm loaded") """ Class documentation goes here. """ @@ -43,7 +40,7 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog): """ Constructor """ - QDialog.__init__(self, parent) + QtGui.QDialog.__init__(self, parent) self.setupUi(self) self.biblemanager = biblemanager self.config = config @@ -53,9 +50,9 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog): self.AddressEdit.setText(self.config.get_config("proxy_address", "")) self.UsernameEdit.setText(self.config.get_config("proxy_username", "")) self.PasswordEdit.setText(self.config.get_config("proxy_password","")) - + filepath = os.path.split(os.path.abspath(__file__))[0] - filepath = os.path.abspath(os.path.join(filepath, '..', 'resources','crosswalkbooks.csv')) + filepath = os.path.abspath(os.path.join(filepath, '..', 'resources','crosswalkbooks.csv')) fbibles=open(filepath, 'r') self.bible_versions = {} self.BibleComboBox.clear() @@ -64,125 +61,136 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog): p = line.split(",") self.bible_versions[p[0]] = p[1].replace('\n', '') self.BibleComboBox.addItem(str(p[0])) - + #Combo Boxes QtCore.QObject.connect(self.LocationComboBox, QtCore.SIGNAL("activated(int)"), self.onLocationComboBoxSelected) QtCore.QObject.connect(self.BibleComboBox, QtCore.SIGNAL("activated(int)"), self.onBibleComboBoxSelected) - #Buttons - QtCore.QObject.connect(self.ImportButton, QtCore.SIGNAL("pressed()"), self.onImportButtonClicked) + #Buttons + QtCore.QObject.connect(self.ImportButton, QtCore.SIGNAL("pressed()"), self.onImportButtonClicked) QtCore.QObject.connect(self.CancelButton, QtCore.SIGNAL("pressed()"), self.onCancelButtonClicked) QtCore.QObject.connect(self.VersesFileButton, QtCore.SIGNAL("pressed()"), self.onVersesFileButtonClicked) QtCore.QObject.connect(self.BooksFileButton, QtCore.SIGNAL("pressed()"), self.onBooksFileButtonClicked) - QtCore.QObject.connect(self.OsisFileButton, QtCore.SIGNAL("pressed()"), self.onOsisFileButtonClicked) - + QtCore.QObject.connect(self.OsisFileButton, QtCore.SIGNAL("pressed()"), self.onOsisFileButtonClicked) + #Lost Focus QtCore.QObject.connect(self.OSISLocationEdit, QtCore.SIGNAL("lostFocus()"), self.onOSISLocationEditLostFocus) QtCore.QObject.connect(self.BooksLocationEdit, QtCore.SIGNAL("lostFocus()"),self.onBooksLocationEditLostFocus) QtCore.QObject.connect(self.VerseLocationEdit, QtCore.SIGNAL("lostFocus()"), self.onVerseLocationEditLostFocus) QtCore.QObject.connect(self.AddressEdit, QtCore.SIGNAL("lostFocus()"), self.onProxyAddressEditLostFocus) QtCore.QObject.connect(self.UsernameEdit, QtCore.SIGNAL("lostFocus()"), self.onProxyUsernameEditLostFocus) - QtCore.QObject.connect(self.PasswordEdit, QtCore.SIGNAL("lostFocus()"), self.onProxyPasswordEditLostFocus) + QtCore.QObject.connect(self.PasswordEdit, QtCore.SIGNAL("lostFocus()"), self.onProxyPasswordEditLostFocus) def onVersesFileButtonClicked(self): filename = QtGui.QFileDialog.getOpenFileName(self, 'Open file',self.config.get_last_dir(1)) if filename != "": - self.VerseLocationEdit.setText(filename) + self.VerseLocationEdit.setText(filename) self.config.set_last_dir(filename, 1) - self.setCsv() - + self.setCsv() + def onBooksFileButtonClicked(self): filename = QtGui.QFileDialog.getOpenFileName(self, 'Open file',self.config.get_last_dir(2)) - if filename != "": - self.BooksLocationEdit.setText(filename) + if filename != "": + self.BooksLocationEdit.setText(filename) self.config.set_last_dir(filename, 2) - self.setCsv() - + self.setCsv() + def onOsisFileButtonClicked(self): filename = QtGui.QFileDialog.getOpenFileName(self, 'Open file',self.config.get_last_dir(3)) - if filename != "": + if filename != "": self.OSISLocationEdit.setText(filename) self.config.set_last_dir(filename, 3) self.setOsis() - + def onOSISLocationEditLostFocus(self): if len(self.OSISLocationEdit.displayText() ) > 0: self.setOsis() else: - if self.bible_type == "OSIS": # Was OSIS and is not any more stops lostFocus running mad - self.bible_type = None + # Was OSIS and is not any more stops lostFocus running mad + if self.bible_type == "OSIS": + self.bible_type = None self.freeAll() - + def onBooksLocationEditLostFocus(self): self.checkOsis() - + def onVerseLocationEditLostFocus(self): self.checkOsis() - + def onProxyAddressEditLostFocus(self): self.config.set_config("proxy_address", str(self.AddressEdit.displayText())) def onProxyUsernameEditLostFocus(self): self.config.set_config("proxy_username", str(self.UsernameEdit.displayText())) - + def onProxyPasswordEditLostFocus(self): self.config.set_config("proxy_password", str(self.PasswordEdit.displayText())) - + def onLocationComboBoxSelected(self): - self.checkHttp() - + self.checkHttp() + def onBibleComboBoxSelected(self): self.checkHttp() self.BibleNameEdit.setText(str(self.BibleComboBox.currentText())) - + def onCancelButtonClicked(self): # tell import to stop - Receiver().send_message("openlpstopimport") + Receiver().send_message("openlpstopimport") # tell bibleplugin to reload the bibles Receiver().send_message("openlpreloadbibles") - self.close() - + self.close() + def onImportButtonClicked(self): if self.biblemanager != None: if not self.bible_type == None and len(self.BibleNameEdit.displayText()) > 0: self.MessageLabel.setText("Import Started") - self.ProgressBar.setMinimum(0) + self.ProgressBar.setMinimum(0) self.setMax(65) self.ProgressBar.setValue(0) self.biblemanager.process_dialog(self) self.importBible() self.MessageLabel.setText("Import Complete") - self.ProgressBar.setValue(self.barmax) + self.ProgressBar.setValue(self.barmax) # tell bibleplugin to reload the bibles - Receiver().send_message("openlpreloadbibles") + Receiver().send_message("openlpreloadbibles") + message = u'Bible import completered' + reply = QtGui.QMessageBox.information(self, + translate(u'BibleMediaItem', u'Information'), + translate(u'BibleMediaItem', message)) def setMax(self, max): - log.debug("set Max %s", max) + log.debug("set Max %s", max) self.barmax = max - self.ProgressBar.setMaximum(max) + self.ProgressBar.setMaximum(max) def incrementProgressBar(self, text ): log.debug("IncrementBar %s", text) self.MessageLabel.setText("Import processing " + text) self.ProgressBar.setValue(self.ProgressBar.value()+1) - + def importBible(self): log.debug("Import Bible ") if self.bible_type == "OSIS": - self.biblemanager.register_osis_file_bible(str(self.BibleNameEdit.displayText()), self.OSISLocationEdit.displayText()) + loaded = self.biblemanager.register_osis_file_bible(str(self.BibleNameEdit.displayText()), + self.OSISLocationEdit.displayText()) elif self.bible_type == "CSV": - self.biblemanager.register_csv_file_bible(str(self.BibleNameEdit.displayText()), self.BooksLocationEdit.displayText(), self.VerseLocationEdit.displayText()) + loaded = self.biblemanager.register_csv_file_bible(str(self.BibleNameEdit.displayText()), + self.BooksLocationEdit.displayText(), self.VerseLocationEdit.displayText()) else: self.setMax(1) # set a value as it will not be needed bible = self.bible_versions[str(self.BibleComboBox.currentText())] - self.biblemanager.register_http_bible(str(self.BibleComboBox.currentText()), \ + loaded = self.biblemanager.register_http_bible(str(self.BibleComboBox.currentText()), \ str(self.LocationComboBox.currentText()), \ str(bible), \ str(self.AddressEdit.displayText()), \ str(self.UsernameEdit .displayText()), \ - str(self.PasswordEdit.displayText())) - self.biblemanager.save_meta_data(str(self.BibleNameEdit.displayText()), str(self.VersionNameEdit.displayText()), str(self.CopyrightEdit.displayText()), str(self.PermisionEdit.displayText())) + str(self.PasswordEdit.displayText())) + if loaded: + self.biblemanager.save_meta_data(str(self.BibleNameEdit.displayText()), + str(self.VersionNameEdit.displayText()), + str(self.CopyrightEdit.displayText()), + str(self.PermisionEdit.displayText())) self.bible_type = None self.freeAll() # free the screen state restrictions self.resetAll() # reset all the screen fields @@ -191,16 +199,18 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog): if len(self.BooksLocationEdit.displayText()) > 0 or len(self.VerseLocationEdit.displayText()) > 0: self.setCsv() else: - if self.bible_type == "CSV": # Was CSV and is not any more stops lostFocus running mad - self.bible_type = None + # Was CSV and is not any more stops lostFocus running mad + if self.bible_type == "CSV": + self.bible_type = None self.freeAll() - + def checkHttp(self): if self.BibleComboBox.currentIndex() != 0 : # First slot is blank so no bible self.setHttp() else: - if self.bible_type == "HTTP": # Was HTTP and is not any more stops lostFocus running mad - self.bible_type = None + # Was HTTP and is not any more stops lostFocus running mad + if self.bible_type == "HTTP": + self.bible_type = None self.freeAll() def blockCsv(self): @@ -208,48 +218,48 @@ class BibleImportForm(QDialog, Ui_BibleImportDialog): self.VerseLocationEdit.setReadOnly(True) self.BooksFileButton.setEnabled(False) self.VersesFileButton.setEnabled(False) - + def setCsv(self): - self.bible_type = "CSV" + self.bible_type = "CSV" self.BooksLocationEdit.setReadOnly(False) - self.VerseLocationEdit.setReadOnly(False) + self.VerseLocationEdit.setReadOnly(False) self.BooksFileButton.setEnabled(True) self.VersesFileButton.setEnabled(True) self.blockOsis() - self.blockHttp() - + self.blockHttp() + def setOsis(self): - self.bible_type = "OSIS" + self.bible_type = "OSIS" self.OSISLocationEdit.setReadOnly(False) - self.OsisFileButton.setEnabled(True) + self.OsisFileButton.setEnabled(True) self.blockCsv() - self.blockHttp() - + self.blockHttp() + def blockOsis(self): self.OSISLocationEdit.setReadOnly(True) self.OsisFileButton.setEnabled(False) - + def setHttp(self): - self.bible_type = "HTTP" + self.bible_type = "HTTP" self.LocationComboBox.setEnabled(True) - self.BibleComboBox.setEnabled(True) + self.BibleComboBox.setEnabled(True) self.blockCsv() - self.blockOsis() - + self.blockOsis() + def blockHttp(self): - self.LocationComboBox.setEnabled(False) - self.BibleComboBox.setEnabled(False) - + self.LocationComboBox.setEnabled(False) + self.BibleComboBox.setEnabled(False) + def freeAll(self): - if self.bible_type == None: # only reset if no bible type set. + if self.bible_type == None: # only reset if no bible type set. self.BooksLocationEdit.setReadOnly(False) - self.VerseLocationEdit.setReadOnly(False) + self.VerseLocationEdit.setReadOnly(False) self.BooksFileButton.setEnabled(True) self.VersesFileButton.setEnabled(True) self.OSISLocationEdit.setReadOnly(False) - self.OsisFileButton.setEnabled(True) + self.OsisFileButton.setEnabled(True) self.LocationComboBox.setEnabled(True) - self.BibleComboBox.setEnabled(True) + self.BibleComboBox.setEnabled(True) def resetAll(self): self.BooksLocationEdit.setText("") diff --git a/openlp/plugins/bibles/lib/bibleDBimpl.py b/openlp/plugins/bibles/lib/bibleDBimpl.py index f2b1b05a7..15de38201 100644 --- a/openlp/plugins/bibles/lib/bibleDBimpl.py +++ b/openlp/plugins/bibles/lib/bibleDBimpl.py @@ -101,6 +101,7 @@ class BibleDBImpl(BibleCommon): return book def save_meta(self, key, value): + log.debug( "save_meta %s/%s", key, value) metadata.bind.echo = False session = self.session() bmeta= BibleMeta() diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index c881c9202..210d0460b 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -128,7 +128,10 @@ class BibleManager(): nbible.save_meta("proxyid", proxyid) # store the proxy userid if proxypass != None and proxypass != "": nbible.save_meta("proxypass", proxypass) # store the proxy password - + return True + else: + log.debug( "register_http_file_bible %s not created already exists", biblename) + return False def register_csv_file_bible(self, biblename, booksfile, versefile): """ @@ -143,6 +146,10 @@ class BibleManager(): self.bible_db_cache[biblename] = nbible # cache the database for use later bcsv = BibleCSVImpl(nbible) # create the loader and pass in the database bcsv.load_data(booksfile, versefile, self.dialogobject) + return True + else: + log.debug( "register_csv_file_bible %s not created already exists", biblename) + return False def register_osis_file_bible(self, biblename, osisfile): """ @@ -157,6 +164,10 @@ class BibleManager(): self.bible_db_cache[biblename] = nbible # cache the database for use later bcsv = BibleOSISImpl(self.biblePath, nbible) # create the loader and pass in the database bcsv.load_data(osisfile, self.dialogobject) + return True + else: + log.debug( "register_OSIS_file_bible %s , %s not created already exists", biblename, osisfile) + return False def get_bibles(self, mode="full"): log.debug("get_bibles") diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 634d6d7a3..db54b1896 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -283,7 +283,7 @@ class BibleMediaItem(MediaManagerItem): self.initialiseBible(bible) # use the first bible as the trigger def onAdvancedVersionComboBox(self): - self.initialiseBible(str(self.AdvancedVersionComboBox.currentText())) # restet the bible info + self.initialiseBible(str(self.AdvancedVersionComboBox.currentText())) # reset the bible info def onAdvancedBookComboBox(self): self.initialiseBible(str(self.AdvancedVersionComboBox.currentText())) # reset the bible info @@ -291,7 +291,7 @@ class BibleMediaItem(MediaManagerItem): def onBibleNewClick(self): self.bibleimportform = BibleImportForm(self.parent.config, self.parent.biblemanager, self) self.bibleimportform.exec_() - pass + self.reloadBibles() def onAdvancedFromVerse(self): frm = self.AdvancedFromVerse.currentText() @@ -417,22 +417,14 @@ class BibleMediaItem(MediaManagerItem): def initialiseBible(self, bible): log.debug(u"initialiseBible %s", bible) - current_book = str(self.AdvancedBookComboBox.currentText()) - chapter_count = self.parent.biblemanager.get_book_chapter_count(bible, - current_book)[0] - log.debug(u'Book change bible %s book %s ChapterCount %s', bible, - current_book, chapter_count) - if chapter_count == None: - # Only change the search details if the book is missing from the new bible - books = self.parent.biblemanager.get_bible_books(str( - self.AdvancedVersionComboBox.currentText())) - self.AdvancedBookComboBox.clear() - first = True - for book in books: - self.AdvancedBookComboBox.addItem(book.name) - if first: - first = False - self.initialiseChapterVerse(bible, book.name) + books = self.parent.biblemanager.get_bible_books(str(bible)) + self.AdvancedBookComboBox.clear() + first = True + for book in books: + self.AdvancedBookComboBox.addItem(book.name) + if first: + first = False + self.initialiseChapterVerse(bible, book.name) def initialiseChapterVerse(self, bible, book): log.debug(u"initialiseChapterVerse %s , %s", bible, book) diff --git a/openlp/plugins/songs/forms/authorsform.py b/openlp/plugins/songs/forms/authorsform.py index aaaeb087b..2f8eafcee 100644 --- a/openlp/plugins/songs/forms/authorsform.py +++ b/openlp/plugins/songs/forms/authorsform.py @@ -55,7 +55,8 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog): authors = self.songmanager.get_authors() for author in authors: self.AuthorListData.addRow(author.id,author.display_name) - row_count = self.AuthorListData.rowCount(None) + #rowCount is number of rows BUT test should be Zero based + row_count = self.AuthorListData.rowCount(None) - 1 if self.currentRow > row_count: # in case we have delete the last row of the table self.currentRow = row_count diff --git a/openlp/plugins/songs/forms/songbookform.py b/openlp/plugins/songs/forms/songbookform.py index 4a7235526..57b08a855 100644 --- a/openlp/plugins/songs/forms/songbookform.py +++ b/openlp/plugins/songs/forms/songbookform.py @@ -55,7 +55,8 @@ class SongBookForm(QtGui.QDialog, Ui_SongBookDialog): Books = self.songmanager.get_books() for Book in Books: self.BookSongListData.addRow(Book.id,Book.name) - row_count = self.BookSongListData.rowCount(None) + #rowCount is number of rows BUT test should be Zero based + row_count = self.BookSongListData.rowCount(None) - 1 if self.currentRow > row_count: # in case we have delete the last row of the table self.currentRow = row_count diff --git a/openlp/plugins/songs/forms/topicsform.py b/openlp/plugins/songs/forms/topicsform.py index fca381f6b..4540ff7cc 100644 --- a/openlp/plugins/songs/forms/topicsform.py +++ b/openlp/plugins/songs/forms/topicsform.py @@ -35,7 +35,7 @@ class TopicsForm(QtGui.QDialog, Ui_TopicsDialog): self.setupUi(self) self.songmanager = songmanager self.currentRow = 0 - self.songbook = None + self.topic = None QtCore.QObject.connect(self.DeleteButton, QtCore.SIGNAL('pressed()'), self.onDeleteButtonClick) @@ -52,13 +52,13 @@ class TopicsForm(QtGui.QDialog, Ui_TopicsDialog): """ Refresh the screen and rest fields """ - print "topics load form start" self.TopicsListData.resetStore() self.onClearButtonClick() # tidy up screen - Topics = self.songmanager.get_topics() - for Topic in Topics: - self.TopicsListData.addRow(Topic.id,Topic.name) - row_count = self.TopicsListData.rowCount(None) + topics = self.songmanager.get_topics() + for topic in topics: + self.TopicsListData.addRow(topic.id,topic.name) + #rowCount is number of rows BUT test should be Zero based + row_count = self.TopicsListData.rowCount(None) - 1 if self.currentRow > row_count: # in case we have delete the last row of the table self.currentRow = row_count @@ -67,14 +67,12 @@ class TopicsForm(QtGui.QDialog, Ui_TopicsDialog): self.TopicsListView.selectionModel().setCurrentIndex(row, QtGui.QItemSelectionModel.SelectCurrent) self._validate_form() - print "topics load form end" def onDeleteButtonClick(self): """ Delete the Topic is the Topic is not attached to any songs """ - self.songmanager.delete_topic(self.Topic.id) - self.onClearButtonClick() + self.songmanager.delete_topic(self.topic.id) self.load_form() def onTopicNameEditLostFocus(self): @@ -84,10 +82,10 @@ class TopicsForm(QtGui.QDialog, Ui_TopicsDialog): """ Sent New or update details to the database """ - if self.Topic == None: - self.Topic = Topic() - self.Topic.name = unicode(self.TopicNameEdit.displayText()) - self.songmanager.save_topic(self.Topic) + if self.topic == None: + self.topic = Topic() + self.topic.name = unicode(self.TopicNameEdit.displayText()) + self.songmanager.save_topic(self.topic) self.onClearButtonClick() self.load_form() @@ -99,7 +97,7 @@ class TopicsForm(QtGui.QDialog, Ui_TopicsDialog): self.MessageLabel.setText(u'') self.DeleteButton.setEnabled(False) self.AddUpdateButton.setEnabled(True) - self.Topic = None + self.topic = None self._validate_form() def onTopicsListViewItemClicked(self, index): @@ -109,10 +107,10 @@ class TopicsForm(QtGui.QDialog, Ui_TopicsDialog): """ self.currentRow = index.row() id = int(self.TopicsListData.getId(index)) - self.Topic = self.songmanager.get_topic(id) + self.topic = self.songmanager.get_topic(id) - self.TopicNameEdit.setText(self.Topic.name) - if len(self.Topic.songs) > 0: + self.TopicNameEdit.setText(self.topic.name) + if len(self.topic.songs) > 0: self.MessageLabel.setText("Topic in use 'Delete' is disabled") self.DeleteButton.setEnabled(False) else: