diff --git a/cnvdb.py b/cnvdb.py old mode 100644 new mode 100755 index f33b5dc03..4463ec887 --- a/cnvdb.py +++ b/cnvdb.py @@ -21,7 +21,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA import codecs import sys -def convert_file(self, inname, outname): +def convert_file(inname, outname): """ Convert a file from another encoding into UTF-8. @@ -35,7 +35,8 @@ def convert_file(self, inname, outname): writefile = codecs.open(outname, 'w', encoding='utf-8') for line in infile: #replace the quotes with quotes - line = line.replace(u'\'\'', u'\'') + #TODO fix double quotes + #line = line.replace(u'\'\'', u'@') writefile.write(line) infile.close() writefile.close() diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 7b306ec76..3bb1ad0ee 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -243,3 +243,9 @@ class Plugin(object): """ pass + def shutdown(self): + """ + Called by the plugin Manager to cleanup things + """ + pass + diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index e8eb308a5..2233d3cbc 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -174,3 +174,10 @@ class PluginManager(object): for plugin in self.plugins: plugin.initialise() + def cleanup_plugins(self): + """ + Loop through all the plugins and give them an opportunity to + clean themselves up + """ + for plugin in self.plugins: + plugin.cleanup() diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index afa4da931..183917549 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -18,7 +18,7 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -from PyQt4 import QtCore, QtGui, QtTest +from PyQt4 import QtCore, QtGui from time import sleep from openlp.core.lib import translate @@ -41,6 +41,7 @@ class MainDisplay(QtGui.QWidget): self.alertactive = False self.alerttext = u'' self.alertTab = None + self.timer_id = 0 def setup(self, screenNumber): """ @@ -69,11 +70,18 @@ class MainDisplay(QtGui.QWidget): self.frameView(self.blankFrame) def frameView(self, frame): + """ + Called from a slide controller to display a frame + if the alert is in progress the alert is added on top + ``frame`` + Image frame to be rendered + """ + self.frame = frame - if not self.displayBlank: - self.display.setPixmap(QtGui.QPixmap.fromImage(frame)) - elif self.alertactive: + if self.timer_id != 0 : self.displayAlert() + elif not self.displayBlank: + self.display.setPixmap(QtGui.QPixmap.fromImage(frame)) def blankDisplay(self): if not self.displayBlank: @@ -85,17 +93,17 @@ class MainDisplay(QtGui.QWidget): def alert(self, alertTab, text): """ - Called from the Alert Tab - alertTab = details from AlertTab - text = display text - screen = screen number to be displayed on. + Called from the Alert Tab to display an alert + ``alertTab`` + details from AlertTab + + ``text`` + display text """ self.alerttext = text self.alertTab = alertTab if len(text) > 0: - self.alertactive = True self.displayAlert() - self.alertactive = False def displayAlert(self): alertframe = QtGui.QPixmap.fromImage(self.frame) @@ -113,5 +121,12 @@ class MainDisplay(QtGui.QWidget): painter.drawText(x, y+metrics.height()-metrics.descent()-1, self.alerttext) painter.end() self.display.setPixmap(alertframe) - QtTest.QTest.qWait(self.alertTab.timeout*1000) - self.display.setPixmap(QtGui.QPixmap.fromImage(self.frame)) + # check to see if we have a timer running + if self.timer_id == 0: + self.timer_id = self.startTimer(int(self.alertTab.timeout) * 1000) + + def timerEvent(self, event): + if event.timerId() == self.timer_id: + self.display.setPixmap(QtGui.QPixmap.fromImage(self.frame)) + self.killTimer(self.timer_id) + self.timer_id = 0 diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 7ca6d3c97..5d227d254 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -139,16 +139,24 @@ class MainWindow(object): if ret == QtGui.QMessageBox.Save: self.ServiceManagerContents.onSaveService() self.mainDisplay.close() + self.cleanUp() event.accept() elif ret == QtGui.QMessageBox.Discard: self.mainDisplay.close() + self.cleanUp() event.accept() else: event.ignore() else: self.mainDisplay.close() + self.cleanUp() event.accept() + def cleanUp(self): + # Call the cleanup method to shutdown plugins. + log.info(u'cleanup plugins') + self.plugin_manager.initialise_plugins() + def OosChanged(self, reset = False, oosName = None): """ Hook to change the title if the OOS has been changed diff --git a/openlp/migration/migratesongs.py b/openlp/migration/migratesongs.py index 3620c6ab2..14634758b 100644 --- a/openlp/migration/migratesongs.py +++ b/openlp/migration/migratesongs.py @@ -137,8 +137,7 @@ class MigrateSongs(): self.db_url = u'sqlite:///' + self.data_path + u'/songs.sqlite' print self.db_url self.session = init_models(self.db_url) - if not songs_table.exists(): - metadata.create_all() + metadata.create_all(checkfirst=True) results = self.session.query(TSong).order_by(TSong.songid).all() for songs_temp in results: song = Song() @@ -151,18 +150,21 @@ class MigrateSongs(): aa = self.session.execute(u'select * from songauthors_temp where songid =' + unicode(songs_temp.songid) ) for row in aa: a = row['authorid'] - author = Author() authors_temp = self.session.query(TAuthor).get(a) - author.display_name = authors_temp.authorname - author.first_name = u'' - author.last_name = u'' + bb = self.session.execute(u'select * from authors where display_name = \"%s\"' % unicode(authors_temp.authorname) ).fetchone() + if bb is None: + author = Author() + author.display_name = authors_temp.authorname + else: + id = int(bb[0]) + author = self.session.query(Author).get(bb[0]) song.authors.append(author) - try: - self.session.add(song) - self.session.commit() - except: - self.session.rollback() - print u'Errow thrown = ', sys.exc_info()[1] + try: + self.session.add(song) + self.session.commit() + except: + self.session.rollback() + print u'Errow thrown = ', sys.exc_info()[1] def _v1_9_0_cleanup(self, database): self.display.sub_output(u'Update Internal Data ' + database) @@ -184,5 +186,4 @@ class MigrateSongs(): conn.execute(u'drop table songauthors_temp;') conn.commit() conn.execute(u'drop table settings;') - conn.commit() diff --git a/openlp/plugins/bibles/lib/bibleDBimpl.py b/openlp/plugins/bibles/lib/bibleDBimpl.py index cfe05254a..0c7fcaa8c 100644 --- a/openlp/plugins/bibles/lib/bibleDBimpl.py +++ b/openlp/plugins/bibles/lib/bibleDBimpl.py @@ -58,7 +58,6 @@ class BibleDBImpl(BibleCommon): def add_verse(self, bookid, chap, vse, text): #log.debug(u'add_verse %s,%s,%s", bookid, chap, vse) - #metadata.bind.echo = False verse = Verse() verse.book_id = bookid verse.chapter = chap @@ -69,8 +68,6 @@ class BibleDBImpl(BibleCommon): def create_chapter(self, bookid, chap, textlist): log.debug(u'create_chapter %s,%s', bookid, chap) - #log.debug(u'Text %s ", textlist) - #metadata.bind.echo = False #text list has book and chapter as first to elements of the array for verse_number, verse_text in textlist.iteritems(): verse = Verse() @@ -83,7 +80,6 @@ class BibleDBImpl(BibleCommon): def create_book(self, bookname, bookabbrev, testament=1): log.debug(u'create_book %s,%s', bookname, bookabbrev) - #metadata.bind.echo = False book = Book() book.testament_id = testament book.name = bookname @@ -94,7 +90,6 @@ class BibleDBImpl(BibleCommon): def save_meta(self, key, value): log.debug(u'save_meta %s/%s', key, value) - #metadata.bind.echo = False bmeta = BibleMeta() bmeta.key = key bmeta.value = value @@ -116,7 +111,6 @@ class BibleDBImpl(BibleCommon): def _load_testament(self, testament): log.debug(u'load_testaments %s', testament) - #metadata.bind.echo = False test = ONTestament() test.name = testament self.session.add(test) @@ -128,17 +122,11 @@ class BibleDBImpl(BibleCommon): def get_max_bible_book_verses(self, bookname, chapter): log.debug(u'get_max_bible_book_verses %s, %s', bookname, chapter) - #metadata.bind.echo = False - #s = text (u'select max(verse.verse) from verse,book where chapter = :c and book_id = book.id and book.name = :b ') - #return self.db.execute(s, c=chapter, b=bookname).fetchone() verse = self.session.query(Verse).join(Book).filter(Book.name==bookname).filter(Verse.chapter==chapter).order_by(Verse.verse.desc()).first() return verse.verse def get_max_bible_book_chapter(self, bookname): log.debug(u'get_max_bible_book_chapter %s', bookname) - #metadata.bind.echo = False - #s = text (u'select max(verse.chapter) from verse,book where book_id = book.id and book.name = :b') - #return self.db.execute(s, b=bookname).fetchone() verse = self.session.query(Verse).join(Book).filter(Book.name==bookname).order_by(Verse.chapter.desc()).first() return verse.chapter @@ -151,34 +139,24 @@ class BibleDBImpl(BibleCommon): def get_bible_chapter(self, id, chapter): log.debug(u'get_bible_chapter %s, %s', id, chapter) - #metadata.bind.echo = False return self.session.query(Verse).filter_by(chapter=chapter).filter_by(book_id=id).first() def get_bible_text(self, bookname, chapter, sverse, everse): log.debug(u'get_bible_text %s, %s, %s, %s', bookname, chapter, sverse, everse) - #metadata.bind.echo = False - #bookname = bookname + u"%" - #s = text (u'select name,chapter,verse.verse, verse.text FROM verse , book where verse.book_id == book.id AND verse.chapter == :c AND (verse.verse between :v1 and :v2) and (book.name like :b)') - #return self.db.execute(s, c=chapter, v1=sverse , v2=everse, b=bookname).fetchall() verses = self.session.query(Verse).join(Book).filter(Book.name==bookname).filter(Verse.chapter==chapter).filter(Verse.verse>=sverse).filter(Verse.verse<=everse).order_by(Verse.verse).all() return verses def get_verses_from_text(self, versetext): log.debug(u'get_verses_from_text %s',versetext) - #metadata.bind.echo = False versetext = u'%%%s%%' % versetext - #s = text (u'select book.name, verse.chapter, verse.verse, verse.text FROM verse , book where verse.book_id == book.id and verse.text like :t') - #return self.db.execute(s, t=versetext).fetchall() verses = self.session.query(Verse).filter(Verse.text.like(versetext)).all() return verses def dump_bible(self): log.debug( u'.........Dumping Bible Database') log.debug( '...............................Books ') - #s = text (u'select * FROM book ') books = self.session.query(Book).all() log.debug(books) log.debug( u'...............................Verses ') - #s = text (u'select * FROM verse ') verses = self.session.query(Verse).all() log.debug(verses) diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index bc86ea8b2..e076811d7 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -29,8 +29,8 @@ from bibleCSVimpl import BibleCSVImpl from bibleDBimpl import BibleDBImpl from bibleHTTPimpl import BibleHTTPImpl -from openlp.plugins.bibles.lib.tables import * -from openlp.plugins.bibles.lib.classes import * +#from openlp.plugins.bibles.lib.tables import * +#from openlp.plugins.bibles.lib.classes import * class BibleMode(object): Full = 1 diff --git a/openlp/plugins/bibles/lib/models.py b/openlp/plugins/bibles/lib/models.py index ebe481cf7..d527ba72d 100644 --- a/openlp/plugins/bibles/lib/models.py +++ b/openlp/plugins/bibles/lib/models.py @@ -68,19 +68,14 @@ class Verse(BaseModel): """ pass - def init_models(db_url): engine = create_engine(db_url) metadata.bind = engine session = scoped_session(sessionmaker(autoflush=True, autocommit=False, bind=engine)) - # Don't think this is needed... - #metadata.bind.echo = False - #Define the tables and indexes return metadata, session - metadata = MetaData() meta_table = Table(u'metadata', metadata, Column(u'key', types.Unicode(255), primary_key=True, index=True), diff --git a/openlp/plugins/songs/forms/authorsform.py b/openlp/plugins/songs/forms/authorsform.py index d87e5bfe0..256ac2002 100644 --- a/openlp/plugins/songs/forms/authorsform.py +++ b/openlp/plugins/songs/forms/authorsform.py @@ -51,7 +51,8 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog): Refresh the screen and rest fields """ self.AuthorListWidget.clear() - self.onClearButtonClick() # tidy up screen + # tidy up screen + self.onClearButtonClick() authors = self.songmanager.get_authors() for author in authors: author_name = QtGui.QListWidgetItem(author.display_name) @@ -127,6 +128,9 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog): self.DisplayEdit.setFocus() def _validate_form(self): + """ + Validate the form and set if Add button if valid. + """ # We need at lease a display name if len(self.DisplayEdit.displayText()) == 0: self.AddUpdateButton.setEnabled(False) diff --git a/openlp/plugins/songs/forms/editsongdialog.py b/openlp/plugins/songs/forms/editsongdialog.py index 3e1ec3717..dec49e1a6 100644 --- a/openlp/plugins/songs/forms/editsongdialog.py +++ b/openlp/plugins/songs/forms/editsongdialog.py @@ -178,9 +178,9 @@ class Ui_EditSongDialog(object): self.AuthorRemoveItem = QtGui.QPushButton(self.AuthorRemoveWidget) self.AuthorRemoveItem.setObjectName(u'AuthorRemoveItem') self.AuthorRemoveLayout.addWidget(self.AuthorRemoveItem) - self.AddAuthorsButton = QtGui.QPushButton(self.AuthorRemoveWidget) - self.AddAuthorsButton.setObjectName(u'AddAuthorsButton') - self.AuthorRemoveLayout.addWidget(self.AddAuthorsButton) +# self.AddAuthorsButton = QtGui.QPushButton(self.AuthorRemoveWidget) +# self.AddAuthorsButton.setObjectName(u'AddAuthorsButton') +# self.AuthorRemoveLayout.addWidget(self.AddAuthorsButton) self.AuthorsLayout.addWidget(self.AuthorRemoveWidget) self.AdditionalLayout.addWidget(self.AuthorsGroupBox) self.SongBookGroup = QtGui.QGroupBox(self.AdditionalWidget) @@ -197,14 +197,14 @@ class Ui_EditSongDialog(object): self.SongbookCombo.setSizePolicy(sizePolicy) self.SongbookCombo.setObjectName(u'SongbookCombo') self.SongbookLayout.addWidget(self.SongbookCombo, 0, 0, 1, 1) - self.AddSongBookButton = QtGui.QPushButton(self.SongBookGroup) - sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) - sizePolicy.setHorizontalStretch(0) - sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.AddSongBookButton.sizePolicy().hasHeightForWidth()) - self.AddSongBookButton.setSizePolicy(sizePolicy) - self.AddSongBookButton.setObjectName(u'AddSongBookButton') - self.SongbookLayout.addWidget(self.AddSongBookButton, 0, 1, 1, 1) +# self.AddSongBookButton = QtGui.QPushButton(self.SongBookGroup) +# sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) +# sizePolicy.setHorizontalStretch(0) +# sizePolicy.setVerticalStretch(0) +# sizePolicy.setHeightForWidth(self.AddSongBookButton.sizePolicy().hasHeightForWidth()) +# self.AddSongBookButton.setSizePolicy(sizePolicy) +# self.AddSongBookButton.setObjectName(u'AddSongBookButton') +# self.SongbookLayout.addWidget(self.AddSongBookButton, 0, 1, 1, 1) self.AdditionalLayout.addWidget(self.SongBookGroup) self.TopicGroupBox = QtGui.QGroupBox(self.AdditionalWidget) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) @@ -255,9 +255,9 @@ class Ui_EditSongDialog(object): self.TopicRemoveItem = QtGui.QPushButton(self.TopicRemoveWidget) self.TopicRemoveItem.setObjectName(u'TopicRemoveItem') self.TopicRemoveLayout.addWidget(self.TopicRemoveItem) - self.AddTopicButton = QtGui.QPushButton(self.TopicRemoveWidget) - self.AddTopicButton.setObjectName(u'AddTopicButton') - self.TopicRemoveLayout.addWidget(self.AddTopicButton) +# self.AddTopicButton = QtGui.QPushButton(self.TopicRemoveWidget) +# self.AddTopicButton.setObjectName(u'AddTopicButton') +# self.TopicRemoveLayout.addWidget(self.AddTopicButton) self.TopicLayout.addWidget(self.TopicRemoveWidget) self.AdditionalLayout.addWidget(self.TopicGroupBox) self.CopyrightgroupBox = QtGui.QGroupBox(self.AdditionalWidget) @@ -313,8 +313,9 @@ class Ui_EditSongDialog(object): EditSongDialog.setTabOrder(self.AuthorAddtoSongItem, self.AuthorsListView) EditSongDialog.setTabOrder(self.AuthorsListView, self.AuthorRemoveItem) EditSongDialog.setTabOrder(self.AuthorRemoveItem, self.SongbookCombo) - EditSongDialog.setTabOrder(self.SongbookCombo, self.AddSongBookButton) - EditSongDialog.setTabOrder(self.AddSongBookButton, self.SongTopicCombo) + #EditSongDialog.setTabOrder(self.SongbookCombo, self.AddSongBookButton) + #EditSongDialog.setTabOrder(self.AddSongBookButton, self.SongTopicCombo) + EditSongDialog.setTabOrder(self.SongbookCombo, self.SongTopicCombo) EditSongDialog.setTabOrder(self.SongTopicCombo, self.TopicsListView) EditSongDialog.setTabOrder(self.TopicsListView, self.TopicRemoveItem) EditSongDialog.setTabOrder(self.TopicRemoveItem, self.CopyrightEditItem) @@ -336,13 +337,13 @@ class Ui_EditSongDialog(object): self.AuthorsGroupBox.setTitle(translate(u'EditSongDialog', u'Authors')) self.AuthorAddtoSongItem.setText(translate(u'EditSongDialog', u'Add to Song')) self.AuthorRemoveItem.setText(translate(u'EditSongDialog', u'Remove')) - self.AddAuthorsButton.setText(translate(u'EditSongDialog', u'Manage Authors')) + #self.AddAuthorsButton.setText(translate(u'EditSongDialog', u'Manage Authors')) self.SongBookGroup.setTitle(translate(u'EditSongDialog', u'Song Book')) - self.AddSongBookButton.setText(translate(u'EditSongDialog', u'Manage Song Books')) + #self.AddSongBookButton.setText(translate(u'EditSongDialog', u'Manage Song Books')) self.TopicGroupBox.setTitle(translate(u'EditSongDialog', u'Topic')) self.AddTopicsToSongButton.setText(translate(u'EditSongDialog', u'Add to Song')) self.TopicRemoveItem.setText(translate(u'EditSongDialog', u'Remove')) - self.AddTopicButton.setText(translate(u'EditSongDialog', u'Manage Topics')) + #self.AddTopicButton.setText(translate(u'EditSongDialog', u'Manage Topics')) self.CopyrightgroupBox.setTitle(translate(u'EditSongDialog', u'Copyright Infomaton')) self.CopyrightInsertItem.setText(translate(u'EditSongDialog', u'(c)')) self.CCLILabel.setText(translate(u'EditSongDialog', u'CCLI Number:')) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 0da4ab942..caa2a480e 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -40,24 +40,24 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): QtGui.QDialog.__init__(self, parent) self.setupUi(self) # Connecting signals and slots - QtCore.QObject.connect(self.AddAuthorsButton, - QtCore.SIGNAL(u'clicked()'), self.onAddAuthorsButtonClicked) +# QtCore.QObject.connect(self.AddAuthorsButton, +# QtCore.SIGNAL(u'clicked()'), self.onAddAuthorsButtonClicked) QtCore.QObject.connect(self.AuthorAddtoSongItem, QtCore.SIGNAL(u'clicked()'), self.onAuthorAddtoSongItemClicked) QtCore.QObject.connect(self.AuthorRemoveItem, QtCore.SIGNAL(u'clicked()'), self.onAuthorRemovefromSongItemClicked) QtCore.QObject.connect(self.AuthorsListView, QtCore.SIGNAL(u'itemClicked(QListWidgetItem*)'), self.onAuthorsListViewPressed) - QtCore.QObject.connect(self.AddTopicButton, - QtCore.SIGNAL(u'clicked()'), self.onAddTopicButtonClicked) +# QtCore.QObject.connect(self.AddTopicButton, +# QtCore.SIGNAL(u'clicked()'), self.onAddTopicButtonClicked) QtCore.QObject.connect(self.AddTopicsToSongButton, QtCore.SIGNAL(u'clicked()'), self.onTopicAddtoSongItemClicked) QtCore.QObject.connect(self.TopicRemoveItem, QtCore.SIGNAL(u'clicked()'), self.onTopicRemovefromSongItemClicked) QtCore.QObject.connect(self.TopicsListView, QtCore.SIGNAL(u'itemClicked(QListWidgetItem*)'), self.onTopicListViewPressed) - QtCore.QObject.connect(self.AddSongBookButton, - QtCore.SIGNAL(u'clicked()'), self.onAddSongBookButtonClicked) +# QtCore.QObject.connect(self.AddSongBookButton, +# QtCore.SIGNAL(u'clicked()'), self.onAddSongBookButtonClicked) QtCore.QObject.connect(self.CopyrightInsertItem, QtCore.SIGNAL(u'clicked()'), self.onCopyrightInsertItemTriggered) QtCore.QObject.connect(self.AddButton, @@ -75,9 +75,9 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): # Create other objects and forms self.songmanager = songmanager self.eventmanager = eventmanager - self.authors_form = AuthorsForm(self.songmanager) - self.topics_form = TopicsForm(self.songmanager) - self.song_book_form = SongBookForm(self.songmanager) +# self.authors_form = AuthorsForm(self.songmanager) +# self.topics_form = TopicsForm(self.songmanager) +# self.song_book_form = SongBookForm(self.songmanager) self.verse_form = EditVerseForm() self.initialise() self.AuthorsListView.setSortingEnabled(False) @@ -86,9 +86,6 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.TopicsListView.setAlternatingRowColors(True) def initialise(self): - self.loadAuthors() - self.loadTopics() - self.loadBooks() self.EditButton.setEnabled(False) self.DeleteButton.setEnabled(False) self.AuthorRemoveItem.setEnabled(False) @@ -140,26 +137,32 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.TopicsListView.clear() self.title_change = False self.TitleEditItem.setFocus(QtCore.Qt.OtherFocusReason) + self.loadAuthors() + self.loadTopics() + self.loadBooks() def loadSong(self, id): log.debug(u'Load Song') + self.loadAuthors() + self.loadTopics() + self.loadBooks() self.song = self.songmanager.get_song(id) self.TitleEditItem.setText(self.song.title) title = self.song.search_title.split(u'@') if self.song.song_book_id != 0: book_name = self.songmanager.get_book(self.song.song_book_id) - id = self.SongbookCombo.findText(unicode(book_name), QtCore.Qt.MatchExactly) + id = self.SongbookCombo.findText(unicode(book_name.name), QtCore.Qt.MatchExactly) if id == -1: # Not Found id = 0 - book_name.setCurrentIndex(id) + self.SongbookCombo.setCurrentIndex(id) if self.song.theme_name is not None and len(self.song.theme_name) > 0: - id = self.SongbookCombo.findText(unicode(self.song.theme_name), QtCore.Qt.MatchExactly) + id = self.ThemeSelectionComboItem.findText(unicode(self.song.theme_name), QtCore.Qt.MatchExactly) if id == -1: # Not Found id = 0 self.song.theme_name = None - self.SongbookCombo.setCurrentIndex(id) + self.ThemeSelectionComboItem.setCurrentIndex(id) if len(title) > 1: self.AlternativeEdit.setText(title[1]) if self.song.copyright is not None: @@ -207,15 +210,16 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): def onAuthorAddtoSongItemClicked(self): item = int(self.AuthorsSelectionComboItem.currentIndex()) - item_id = (self.AuthorsSelectionComboItem.itemData(item)).toInt()[0] - author = self.songmanager.get_author(item_id) - self.song.authors.append(author) - author_item = QtGui.QListWidgetItem(unicode(author.display_name)) - author_item.setData(QtCore.Qt.UserRole, QtCore.QVariant(author.id)) - self.AuthorsListView.addItem(author_item) + if item > -1: + item_id = (self.AuthorsSelectionComboItem.itemData(item)).toInt()[0] + author = self.songmanager.get_author(item_id) + self.song.authors.append(author) + author_item = QtGui.QListWidgetItem(unicode(author.display_name)) + author_item.setData(QtCore.Qt.UserRole, QtCore.QVariant(author.id)) + self.AuthorsListView.addItem(author_item) def onAuthorsListViewPressed(self): - if self.AuthorsListView.count() >1: + if self.AuthorsListView.count() > 1: self.AuthorRemoveItem.setEnabled(True) def onAuthorRemovefromSongItemClicked(self): @@ -229,12 +233,13 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): def onTopicAddtoSongItemClicked(self): item = int(self.SongTopicCombo.currentIndex()) - item_id = (self.SongTopicCombo.itemData(item)).toInt()[0] - topic = self.songmanager.get_topic(item_id) - self.song.topics.append(topic) - topic_item = QtGui.QListWidgetItem(unicode(topic.name)) - topic_item.setData(QtCore.Qt.UserRole, QtCore.QVariant(topic.id)) - self.TopicsListView.addItem(topic_item) + if item > -1: + item_id = (self.SongTopicCombo.itemData(item)).toInt()[0] + topic = self.songmanager.get_topic(item_id) + self.song.topics.append(topic) + topic_item = QtGui.QListWidgetItem(unicode(topic.name)) + topic_item.setData(QtCore.Qt.UserRole, QtCore.QVariant(topic.id)) + self.TopicsListView.addItem(topic_item) def onTopicListViewPressed(self): self.TopicRemoveItem.setEnabled(True) @@ -247,29 +252,30 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.song.topics.remove(topic) row = self.TopicsListView.row(item) self.TopicsListView.takeItem(row) - def onAddAuthorsButtonClicked(self): - """ - Slot documentation goes here. - """ - self.authors_form.load_form() - self.authors_form.exec_() - self.loadAuthors() - def onAddTopicButtonClicked(self): - """ - Slot documentation goes here. - """ - self.topics_form.load_form() - self.topics_form.exec_() - self.loadTopics() - - def onAddSongBookButtonClicked(self): - """ - Slot documentation goes here. - """ - self.song_book_form.load_form() - self.song_book_form.exec_() - self.loadBooks() +# def onAddAuthorsButtonClicked(self): +# """ +# Slot documentation goes here. +# """ +# self.authors_form.load_form() +# self.authors_form.exec_() +# self.loadAuthors() +# +# def onAddTopicButtonClicked(self): +# """ +# Slot documentation goes here. +# """ +# self.topics_form.load_form() +# self.topics_form.exec_() +# self.loadTopics() +# +# def onAddSongBookButtonClicked(self): +# """ +# Slot documentation goes here. +# """ +# self.song_book_form.load_form() +# self.song_book_form.exec_() +# self.loadBooks() def onSongBookComboChanged(self, item): if item == 0: @@ -301,7 +307,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.verse_form.setVerse(item.text()) self.verse_form.exec_() item.setText(self.verse_form.getVerse()) - self.VerseListWidget.update() + self.VerseListWidget.repaint() self.EditButton.setEnabled(False) self.DeleteButton.setEnabled(False) @@ -367,7 +373,6 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.song.ccli_number = unicode(self.CCLNumberEdit.displayText()) self.processLyrics() self.processTitle() - self.song.song_book_id = 0 self.songmanager.save_song(self.song) if self.title_change: self.eventmanager.post_event(Event(EventType.LoadSongList)) diff --git a/openlp/plugins/songs/lib/manager.py b/openlp/plugins/songs/lib/manager.py index bfe795f6e..8775a51b1 100644 --- a/openlp/plugins/songs/lib/manager.py +++ b/openlp/plugins/songs/lib/manager.py @@ -55,13 +55,9 @@ class SongManager(): self.config.get_config(u'db hostname') + u'/' + \ self.config.get_config(u'db database') self.session = init_models(self.db_url) - if not songs_table.exists(): - metadata.create_all() + metadata.create_all(checkfirst=True) log.debug(u'Song Initialised') -# def process_dialog(self, dialogobject): -# self.dialogobject = dialogobject - def get_songs(self): """ Returns the details of a song diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 5165237d5..b49bcac95 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -22,7 +22,7 @@ import logging from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, translate, ServiceItem, SongXMLParser , contextMenuAction, contextMenuSeparator -from openlp.plugins.songs.forms import EditSongForm +from openlp.plugins.songs.forms import EditSongForm, AuthorsForm, TopicsForm, SongBookForm class SongList(QtGui.QListWidget): @@ -59,6 +59,9 @@ class SongMediaItem(MediaManagerItem): self.ConfigSection = u'song' MediaManagerItem.__init__(self, parent, icon, title) self.edit_song_form = EditSongForm(self.parent.songmanager, self.parent.event_manager) + self.authors_form = AuthorsForm(self.parent.songmanager) + self.topics_form = TopicsForm(self.parent.songmanager) + self.song_book_form = SongBookForm(self.parent.songmanager) def setupUi(self): # Add a toolbar @@ -90,6 +93,19 @@ class SongMediaItem(MediaManagerItem): self.addToolbarButton(translate(u'SongMediaItem', u'Add Song To Service'), translate(u'SongMediaItem', u'Add the selected song(s) to the service'), ':/system/system_add.png', self.onSongAddClick, 'SongAddItem') + self.addToolbarSeparator() + ## Author Edit Button ## + self.addToolbarButton(translate(u'SongMediaItem', u'Edit Authors'), + translate(u'SongMediaItem', u'Maintain the list of Song Authors'), + ':/songs/song_author_edit.png', self.onEditAuthorClick, 'SongAuthorEditItem') + ## Author Edit Button ## + self.addToolbarButton(translate(u'SongMediaItem', u'Edit Books'), + translate(u'SongMediaItem', u'Maintain the list of Song Books'), + ':/songs/song_book_edit.png', self.onEditBookClick, 'SongAuthorEditItem') + ## Author Edit Button ## + self.addToolbarButton(translate(u'SongMediaItem', u'Edit Topics'), + translate(u'SongMediaItem', u'Maintain the list of Song Topics'), + ':/songs/song_topic_edit.png', self.onEditTopicClick, 'SongAuthorEditItem') ## Add the songlist widget ## # Create the tab widget self.SongWidget = QtGui.QWidget(self) @@ -222,6 +238,18 @@ class SongMediaItem(MediaManagerItem): self.edit_song_form.newSong() self.edit_song_form.exec_() + def onEditAuthorClick(self): + self.authors_form.load_form() + self.authors_form.exec_() + + def onEditTopicClick(self): + self.topics_form.load_form() + self.topics_form.exec_() + + def onEditBookClick(self): + self.song_book_form.load_form() + self.song_book_form.exec_() + def onSongEditClick(self): item = self.ListView.currentItem() if item is not None: diff --git a/resources/images/openlp-2.qrc b/resources/images/openlp-2.qrc index 0571a70d5..14f05e56e 100644 --- a/resources/images/openlp-2.qrc +++ b/resources/images/openlp-2.qrc @@ -4,6 +4,9 @@ song_edit.png song_export.png song_new.png + song_author_edit.png + song_topic_edit.png + song_book_edit.png slide_close.png diff --git a/resources/images/song_author_edit.png b/resources/images/song_author_edit.png new file mode 100644 index 000000000..b50ec42a5 Binary files /dev/null and b/resources/images/song_author_edit.png differ diff --git a/resources/images/song_book_edit.png b/resources/images/song_book_edit.png new file mode 100644 index 000000000..8fa59df19 Binary files /dev/null and b/resources/images/song_book_edit.png differ diff --git a/resources/images/song_topic_edit.png b/resources/images/song_topic_edit.png new file mode 100644 index 000000000..22b6eeb6f Binary files /dev/null and b/resources/images/song_topic_edit.png differ diff --git a/songcnv.sh b/songcnv.sh new file mode 100755 index 000000000..b7ef2a173 --- /dev/null +++ b/songcnv.sh @@ -0,0 +1,5 @@ +/usr/bin/sqlite ~/.local/share/openlp/songs/songs.olp .dump > ~/.local/share/openlp/songs/songs.dmp +./cnvdb.py ~/.local/share/openlp/songs/songs.dmp ~/.local/share/openlp/songs/songs.dmp2 +rm ~/.local/share/openlp/songs/songs.sqlite +sqlite3 ~/.local/share/openlp/songs/songs.sqlite < ~/.local/share/openlp/songs/songs.dmp2 +./openlpcnv.pyw