More changes to Songs plugin to get ManageAuthors working.

This commit is contained in:
Tim Bentley 2009-06-03 18:32:53 +01:00
parent a473a4dffc
commit 29530d31ca
5 changed files with 36 additions and 119 deletions

View File

@ -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 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA Place, Suite 330, Boston, MA 02111-1307 USA
""" """
from textlistdata import TextListData
from authorsform import AuthorsForm from authorsform import AuthorsForm
from topicsform import TopicsForm from topicsform import TopicsForm
from songbookform import SongBookForm from songbookform import SongBookForm

View File

@ -8,6 +8,7 @@
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.plugins.songs.lib import TextListData
class Ui_AuthorsDialog(object): class Ui_AuthorsDialog(object):
def setupUi(self, AuthorsDialog): def setupUi(self, AuthorsDialog):
@ -17,14 +18,21 @@ class Ui_AuthorsDialog(object):
self.DialogLayout.setSpacing(8) self.DialogLayout.setSpacing(8)
self.DialogLayout.setMargin(8) self.DialogLayout.setMargin(8)
self.DialogLayout.setObjectName("DialogLayout") 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.setAlternatingRowColors(True)
self.AuthorListView.setColumnCount(0) self.AuthorListData = TextListData()
self.AuthorListView.setObjectName("AuthorListView") self.AuthorListView.setModel(self.AuthorListData)
self.AuthorListView.setColumnCount(0)
self.AuthorListView.setRowCount(0)
self.DialogLayout.addWidget(self.AuthorListView) self.DialogLayout.addWidget(self.AuthorListView)
self.AuthorDetails = QtGui.QGroupBox(AuthorsDialog) self.AuthorDetails = QtGui.QGroupBox(AuthorsDialog)
self.AuthorDetails.setMinimumSize(QtCore.QSize(0, 0)) self.AuthorDetails.setMinimumSize(QtCore.QSize(0, 0))
self.AuthorDetails.setObjectName("AuthorDetails") self.AuthorDetails.setObjectName("AuthorDetails")

View File

@ -19,6 +19,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
from PyQt4 import QtGui, QtCore from PyQt4 import QtGui, QtCore
from openlp.plugins.songs.forms.authorsdialog import Ui_AuthorsDialog from openlp.plugins.songs.forms.authorsdialog import Ui_AuthorsDialog
from openlp.plugins.songs.lib import TextListData
class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog): class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
""" """
@ -31,11 +32,6 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
QtGui.QDialog.__init__(self, parent) QtGui.QDialog.__init__(self, parent)
self.setupUi(self) self.setupUi(self)
self.songmanager = songmanager 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.currentRow = 0
self.author = None self.author = None
@ -48,33 +44,24 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
QtCore.QObject.connect(self.DisplayEdit, QtCore.QObject.connect(self.DisplayEdit,
QtCore.SIGNAL('pressed()'), self.onDisplayEditLostFocus) QtCore.SIGNAL('pressed()'), self.onDisplayEditLostFocus)
QtCore.QObject.connect(self.AuthorListView, QtCore.QObject.connect(self.AuthorListView,
QtCore.SIGNAL('pressed()'), self.onAuthorListViewItemClicked) QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onAuthorListViewItemClicked)
def load_form(self): def load_form(self):
""" """
Refresh the screen and rest fields Refresh the screen and rest fields
""" """
self.AuthorListData.resetStore()
self.onClearButtonClick() # tidy up screen self.onClearButtonClick() # tidy up screen
authors = self.songmanager.get_authors() 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: for author in authors:
row_count = self.AuthorListView.rowCount() self.AuthorListData.addRow(author.id,author.display_name)
self.AuthorListView.setRowCount(row_count + 1) row_count = self.AuthorListData.rowCount(None)
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()
if self.currentRow > row_count: if self.currentRow > row_count:
# in case we have delete the last row of the table # in case we have delete the last row of the table
self.currentRow = row_count 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() self._validate_form()
def onDeleteButtonClick(self): def onDeleteButtonClick(self):
@ -106,27 +93,26 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
""" """
Tidy up screen if clear button pressed Tidy up screen if clear button pressed
""" """
self.DisplayEdit.setText("") self.DisplayEdit.setText(u'')
self.FirstNameEdit.setText("") self.FirstNameEdit.setText(u'')
self.LastNameEdit.setText("") self.LastNameEdit.setText(u'')
self.MessageLabel.setText("") self.MessageLabel.setText(u'')
self.DeleteButton.setEnabled(False) self.DeleteButton.setEnabled(False)
self.author = None self.author = None
self._validate_form() self._validate_form()
def onAuthorListViewItemClicked(self, item): def onAuthorListViewItemClicked(self, index):
""" """
An Author has been selected display it An Author has been selected display it
If the author is attached to a Song prevent delete If the author is attached to a Song prevent delete
""" """
self.currentRow = self.AuthorListView.currentRow() print index
id = int(self.AuthorListView.item(self.currentRow, 0).text()) id = int(self.AuthorListData.getId(index))
self.author = self.songmanager.get_author(id) self.author = self.songmanager.get_author(id)
self.DisplayEdit.setText(self.author.display_name) self.DisplayEdit.setText(self.author.display_name)
self.FirstNameEdit.setText(self.author.first_name) self.FirstNameEdit.setText(self.author.first_name)
self.LastNameEdit.setText(self.author.last_name) self.LastNameEdit.setText(self.author.last_name)
#songs = self.songmanager.get_song_authors_for_author(id)
if len(self.author.songs) > 0: if len(self.author.songs) > 0:
self.MessageLabel.setText("Author in use 'Delete' is disabled") self.MessageLabel.setText("Author in use 'Delete' is disabled")
self.DeleteButton.setEnabled(False) self.DeleteButton.setEnabled(False)

View File

@ -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)

View File

@ -3,7 +3,7 @@
""" """
OpenLP - Open Source Lyrics Projection OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman 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 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 the terms of the GNU General Public License as published by the Free Software
@ -34,7 +34,7 @@ class SongManager():
""" """
global log global log
log=logging.getLogger('SongManager') log = logging.getLogger('SongManager')
log.info('Song manager loaded') log.info('Song manager loaded')
def __init__(self, config): def __init__(self, config):
@ -134,11 +134,14 @@ class SongManager():
def delete_author(self, authorid): def delete_author(self, authorid):
""" """
Delete the author and refresh the author cache Delete the author
""" """
author = self.get_author(authorid)
try: try:
self.session.delete(author) self.session.delete(author)
self.session.commit() self.session.commit()
return True return True
except: except:
log.error("Errow thrown %s", sys.exc_info()[1])
print "Errow thrown ", sys.exc_info()[1]
return False return False