From 29530d31ca5b665a282753281a4bba477ed186cf Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 3 Jun 2009 18:32:53 +0100 Subject: [PATCH] More changes to Songs plugin to get ManageAuthors working. --- openlp/plugins/songs/forms/__init__.py | 2 +- openlp/plugins/songs/forms/authorsdialog.py | 20 ++++-- openlp/plugins/songs/forms/authorsform.py | 44 ++++-------- openlp/plugins/songs/forms/textlistdata.py | 80 --------------------- openlp/plugins/songs/lib/manager.py | 9 ++- 5 files changed, 36 insertions(+), 119 deletions(-) delete mode 100644 openlp/plugins/songs/forms/textlistdata.py diff --git a/openlp/plugins/songs/forms/__init__.py b/openlp/plugins/songs/forms/__init__.py index 5cced6170..26b623778 100644 --- a/openlp/plugins/songs/forms/__init__.py +++ b/openlp/plugins/songs/forms/__init__.py @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -from textlistdata import TextListData + from authorsform import AuthorsForm from topicsform import TopicsForm from songbookform import SongBookForm diff --git a/openlp/plugins/songs/forms/authorsdialog.py b/openlp/plugins/songs/forms/authorsdialog.py index 99b9714f2..784af5fc5 100644 --- a/openlp/plugins/songs/forms/authorsdialog.py +++ b/openlp/plugins/songs/forms/authorsdialog.py @@ -8,6 +8,7 @@ # WARNING! All changes made in this file will be lost! from PyQt4 import QtCore, QtGui +from openlp.plugins.songs.lib import TextListData class Ui_AuthorsDialog(object): def setupUi(self, AuthorsDialog): @@ -17,14 +18,21 @@ class Ui_AuthorsDialog(object): self.DialogLayout.setSpacing(8) self.DialogLayout.setMargin(8) self.DialogLayout.setObjectName("DialogLayout") - self.AuthorListView = QtGui.QTableWidget(AuthorsDialog) - self.AuthorListView.setDragEnabled(True) + + +# self.AuthorListView = QtGui.QTableWidget(AuthorsDialog) +# self.AuthorListView.setDragEnabled(True) +# self.AuthorListView.setAlternatingRowColors(True) +# self.AuthorListView.setColumnCount(0) +# self.AuthorListView.setObjectName("AuthorListView") +# self.AuthorListView.setColumnCount(0) +# self.AuthorListView.setRowCount(0) + self.AuthorListView = QtGui.QListView() self.AuthorListView.setAlternatingRowColors(True) - self.AuthorListView.setColumnCount(0) - self.AuthorListView.setObjectName("AuthorListView") - self.AuthorListView.setColumnCount(0) - self.AuthorListView.setRowCount(0) + self.AuthorListData = TextListData() + self.AuthorListView.setModel(self.AuthorListData) self.DialogLayout.addWidget(self.AuthorListView) + self.AuthorDetails = QtGui.QGroupBox(AuthorsDialog) self.AuthorDetails.setMinimumSize(QtCore.QSize(0, 0)) self.AuthorDetails.setObjectName("AuthorDetails") diff --git a/openlp/plugins/songs/forms/authorsform.py b/openlp/plugins/songs/forms/authorsform.py index 0e3efb53a..ed056af59 100644 --- a/openlp/plugins/songs/forms/authorsform.py +++ b/openlp/plugins/songs/forms/authorsform.py @@ -19,6 +19,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA from PyQt4 import QtGui, QtCore from openlp.plugins.songs.forms.authorsdialog import Ui_AuthorsDialog +from openlp.plugins.songs.lib import TextListData class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog): """ @@ -31,11 +32,6 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog): QtGui.QDialog.__init__(self, parent) self.setupUi(self) self.songmanager = songmanager - self.AuthorListView.setColumnCount(2) - self.AuthorListView.setColumnHidden(0, True) - self.AuthorListView.setColumnWidth(1, 300) - self.AuthorListView.horizontalHeader().setVisible(False) - self.AuthorListView.verticalHeader().setVisible(False) self.currentRow = 0 self.author = None @@ -48,33 +44,24 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog): QtCore.QObject.connect(self.DisplayEdit, QtCore.SIGNAL('pressed()'), self.onDisplayEditLostFocus) QtCore.QObject.connect(self.AuthorListView, - QtCore.SIGNAL('pressed()'), self.onAuthorListViewItemClicked) + QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onAuthorListViewItemClicked) def load_form(self): """ Refresh the screen and rest fields """ + self.AuthorListData.resetStore() self.onClearButtonClick() # tidy up screen authors = self.songmanager.get_authors() - self.AuthorListView.clear() # clear the results - #self.AuthorListView.setHorizontalHeaderLabels(QtCore.QStringList([" ","Author"])) - self.AuthorListView.horizontalHeader().setVisible(False) - self.AuthorListView.verticalHeader().setVisible(False) - self.AuthorListView.setRowCount(0) for author in authors: - row_count = self.AuthorListView.rowCount() - self.AuthorListView.setRowCount(row_count + 1) - author_id = QtGui.QTableWidgetItem(str(author.id)) - self.AuthorListView.setItem(row_count, 0, author_id) - display_name = QtGui.QTableWidgetItem(author.display_name) - display_name.setFlags(QtCore.Qt.ItemIsSelectable) - self.AuthorListView.setItem(row_count, 1, display_name) - self.AuthorListView.setRowHeight(row_count, 20) - row_count = self.AuthorListView.rowCount() + self.AuthorListData.addRow(author.id,author.display_name) + row_count = self.AuthorListData.rowCount(None) if self.currentRow > row_count: # in case we have delete the last row of the table self.currentRow = row_count - self.AuthorListView.selectRow(self.currentRow) # set selected row to previous selected row + row = self.AuthorListData.createIndex(self.currentRow, 0) + if row.isValid(): + self.AuthorListView.selectionModel().setCurrentIndex(row, QtGui.QItemSelectionModel.SelectCurrent) self._validate_form() def onDeleteButtonClick(self): @@ -106,27 +93,26 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog): """ Tidy up screen if clear button pressed """ - self.DisplayEdit.setText("") - self.FirstNameEdit.setText("") - self.LastNameEdit.setText("") - self.MessageLabel.setText("") + self.DisplayEdit.setText(u'') + self.FirstNameEdit.setText(u'') + self.LastNameEdit.setText(u'') + self.MessageLabel.setText(u'') self.DeleteButton.setEnabled(False) self.author = None self._validate_form() - def onAuthorListViewItemClicked(self, item): + def onAuthorListViewItemClicked(self, index): """ An Author has been selected display it If the author is attached to a Song prevent delete """ - self.currentRow = self.AuthorListView.currentRow() - id = int(self.AuthorListView.item(self.currentRow, 0).text()) + print index + id = int(self.AuthorListData.getId(index)) self.author = self.songmanager.get_author(id) self.DisplayEdit.setText(self.author.display_name) self.FirstNameEdit.setText(self.author.first_name) self.LastNameEdit.setText(self.author.last_name) - #songs = self.songmanager.get_song_authors_for_author(id) if len(self.author.songs) > 0: self.MessageLabel.setText("Author in use 'Delete' is disabled") self.DeleteButton.setEnabled(False) diff --git a/openlp/plugins/songs/forms/textlistdata.py b/openlp/plugins/songs/forms/textlistdata.py deleted file mode 100644 index 547e978f8..000000000 --- a/openlp/plugins/songs/forms/textlistdata.py +++ /dev/null @@ -1,80 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 -""" -OpenLP - Open Source Lyrics Projection -Copyright (c) 2008 Raoul Snyman -Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation; version 2 of the License. - -This program is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A -PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along with -this program; if not, write to the Free Software Foundation, Inc., 59 Temple -Place, Suite 330, Boston, MA 02111-1307 USA -""" -import logging - -from PyQt4 import QtCore, QtGui - -class TextListData(QtCore.QAbstractListModel): - """ - An abstract list of strings - """ - global log - log = logging.getLogger(u'TextListData') - log.info(u'started') - - def __init__(self): - QtCore.QAbstractListModel.__init__(self) - self.items = [] # will be a list of (database id , title) tuples - - def resetStore(self): - #reset list so can be reloaded - self.items = [] - - def rowCount(self, parent): - return len(self.items) - - def insertRow(self, row, id, title): - self.beginInsertRows(QtCore.QModelIndex(),row,row) - log.debug("insert row %d:%s for id %d" % (row,title, id)) - self.items.insert(row, (id, title)) - self.endInsertRows() - - def removeRow(self, row): - self.beginRemoveRows(QtCore.QModelIndex(), row,row) - self.items.pop(row) - self.endRemoveRows() - - def addRow(self, id, title): - 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 QtCore.QVariant() - if role == QtCore.Qt.DisplayRole: - retval = self.items[row][1] - else: - retval = QtCore.QVariant() - if type(retval) is not type(QtCore.QVariant): - return QtCore.QVariant(retval) - else: - return retval - - def getIdList(self): - filelist = [item[0] for item in self.items]; - return filelist - - def getId(self, index): - row = index.row() - return self.items[row][0] - - def deleteRow(self, index): - row = index.row() - self.removeRow(row) diff --git a/openlp/plugins/songs/lib/manager.py b/openlp/plugins/songs/lib/manager.py index 2dcc600c9..f0da16cf4 100644 --- a/openlp/plugins/songs/lib/manager.py +++ b/openlp/plugins/songs/lib/manager.py @@ -3,7 +3,7 @@ """ OpenLP - Open Source Lyrics Projection Copyright (c) 2008 Raoul Snyman -Portions copyright (c) 2008 Martin Thompson, Tim Bentley +Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -34,7 +34,7 @@ class SongManager(): """ global log - log=logging.getLogger('SongManager') + log = logging.getLogger('SongManager') log.info('Song manager loaded') def __init__(self, config): @@ -134,11 +134,14 @@ class SongManager(): def delete_author(self, authorid): """ - Delete the author and refresh the author cache + Delete the author """ + author = self.get_author(authorid) try: self.session.delete(author) self.session.commit() return True except: + log.error("Errow thrown %s", sys.exc_info()[1]) + print "Errow thrown ", sys.exc_info()[1] return False