Start fixing the songs plugin

This commit is contained in:
Tim Bentley 2009-06-03 17:14:56 +01:00
parent 5fbc870c64
commit a473a4dffc
8 changed files with 125 additions and 49 deletions

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

@ -2,7 +2,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, Carsten Tinggaard Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley, Carsten Tinggaard
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
@ -17,10 +17,6 @@ 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 PyQt4 import QtGui, QtCore from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import pyqtSignature
from openlp.core.resources import *
from openlp.plugins.songs.lib.classes import *
from openlp.plugins.songs.forms.authorsdialog import Ui_AuthorsDialog from openlp.plugins.songs.forms.authorsdialog import Ui_AuthorsDialog
@ -38,17 +34,27 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
self.AuthorListView.setColumnCount(2) self.AuthorListView.setColumnCount(2)
self.AuthorListView.setColumnHidden(0, True) self.AuthorListView.setColumnHidden(0, True)
self.AuthorListView.setColumnWidth(1, 300) self.AuthorListView.setColumnWidth(1, 300)
#self.AuthorListView.setHorizontalHeaderLabels(QtCore.QStringList([" ","Author"]))
self.AuthorListView.horizontalHeader().setVisible(False) self.AuthorListView.horizontalHeader().setVisible(False)
self.AuthorListView.verticalHeader().setVisible(False) self.AuthorListView.verticalHeader().setVisible(False)
self.currentrow = 0 self.currentRow = 0
self.author = None self.author = None
QtCore.QObject.connect(self.DeleteButton,
QtCore.SIGNAL('pressed()'), self.onDeleteButtonClick)
QtCore.QObject.connect(self.ClearButton,
QtCore.SIGNAL('pressed()'), self.onClearButtonClick)
QtCore.QObject.connect(self.AddUpdateButton,
QtCore.SIGNAL('pressed()'), self.onAddUpdateButtonClick)
QtCore.QObject.connect(self.DisplayEdit,
QtCore.SIGNAL('pressed()'), self.onDisplayEditLostFocus)
QtCore.QObject.connect(self.AuthorListView,
QtCore.SIGNAL('pressed()'), self.onAuthorListViewItemClicked)
def load_form(self): def load_form(self):
""" """
Refresh the screen and rest fields Refresh the screen and rest fields
""" """
self.on_ClearButton_clicked() # 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.clear() # clear the results
#self.AuthorListView.setHorizontalHeaderLabels(QtCore.QStringList([" ","Author"])) #self.AuthorListView.setHorizontalHeaderLabels(QtCore.QStringList([" ","Author"]))
@ -65,27 +71,24 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
self.AuthorListView.setItem(row_count, 1, display_name) self.AuthorListView.setItem(row_count, 1, display_name)
self.AuthorListView.setRowHeight(row_count, 20) self.AuthorListView.setRowHeight(row_count, 20)
row_count = self.AuthorListView.rowCount() 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 self.AuthorListView.selectRow(self.currentRow) # set selected row to previous selected row
self._validate_form() self._validate_form()
@pyqtSignature("") def onDeleteButtonClick(self):
def on_DeleteButton_clicked(self):
""" """
Delete the author is the Author is not attached to any songs Delete the author is the Author is not attached to any songs
""" """
self.songmanager.delete_author(self.author.id) self.songmanager.delete_author(self.author.id)
self.on_ClearButton_clicked() self.onClearButtonClick()
self.load_form() self.load_form()
@pyqtSignature("") def onDisplayEditLostFocus(self):
def on_DisplayEdit_lostFocus(self):
self._validate_form() self._validate_form()
@pyqtSignature("") def onAddUpdateButtonClick(self):
def on_AddUpdateButton_clicked(self):
""" """
Sent New or update details to the database Sent New or update details to the database
""" """
@ -95,13 +98,11 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
self.author.first_name = unicode(self.FirstNameEdit.displayText()) self.author.first_name = unicode(self.FirstNameEdit.displayText())
self.author.last_name = unicode(self.LastNameEdit.displayText()) self.author.last_name = unicode(self.LastNameEdit.displayText())
self.songmanager.save_author(self.author) self.songmanager.save_author(self.author)
self.on_ClearButton_clicked() self.onClearButtonClick()
self.load_form() self.load_form()
self._validate_form() self._validate_form()
def onClearButtonClick(self):
@pyqtSignature("")
def on_ClearButton_clicked(self):
""" """
Tidy up screen if clear button pressed Tidy up screen if clear button pressed
""" """
@ -113,14 +114,13 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
self.author = None self.author = None
self._validate_form() self._validate_form()
@pyqtSignature("QTableWidgetItem*") def onAuthorListViewItemClicked(self, item):
def on_AuthorListView_itemClicked(self, item):
""" """
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() self.currentRow = self.AuthorListView.currentRow()
id = int(self.AuthorListView.item(self.currentrow, 0).text()) id = int(self.AuthorListView.item(self.currentRow, 0).text())
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)

View File

@ -108,10 +108,10 @@ class Ui_EditSongDialog(object):
self.ThemeSelectionComboItem = QtGui.QComboBox(self.ThemeGroupBox) self.ThemeSelectionComboItem = QtGui.QComboBox(self.ThemeGroupBox)
self.ThemeSelectionComboItem.setObjectName("ThemeSelectionComboItem") self.ThemeSelectionComboItem.setObjectName("ThemeSelectionComboItem")
self.ThemeLayout.addWidget(self.ThemeSelectionComboItem) self.ThemeLayout.addWidget(self.ThemeSelectionComboItem)
self.ThemeAddItem = QtGui.QPushButton(self.ThemeGroupBox) # self.ThemeAddItem = QtGui.QPushButton(self.ThemeGroupBox)
self.ThemeAddItem.setMaximumSize(QtCore.QSize(110, 16777215)) # self.ThemeAddItem.setMaximumSize(QtCore.QSize(110, 16777215))
self.ThemeAddItem.setObjectName("ThemeAddItem") # self.ThemeAddItem.setObjectName("ThemeAddItem")
self.ThemeLayout.addWidget(self.ThemeAddItem) # self.ThemeLayout.addWidget(self.ThemeAddItem)
self.DetailsLayout.addWidget(self.ThemeGroupBox) self.DetailsLayout.addWidget(self.ThemeGroupBox)
self.TopLayout.addWidget(self.TextWidget) self.TopLayout.addWidget(self.TextWidget)
self.AdditionalWidget = QtGui.QWidget(self.TopWidget) self.AdditionalWidget = QtGui.QWidget(self.TopWidget)
@ -305,8 +305,7 @@ class Ui_EditSongDialog(object):
EditSongDialog.setTabOrder(self.AlternativeEdit, self.VerseOrderEdit) EditSongDialog.setTabOrder(self.AlternativeEdit, self.VerseOrderEdit)
EditSongDialog.setTabOrder(self.VerseOrderEdit, self.CommentsEdit) EditSongDialog.setTabOrder(self.VerseOrderEdit, self.CommentsEdit)
EditSongDialog.setTabOrder(self.CommentsEdit, self.ThemeSelectionComboItem) EditSongDialog.setTabOrder(self.CommentsEdit, self.ThemeSelectionComboItem)
EditSongDialog.setTabOrder(self.ThemeSelectionComboItem, self.ThemeAddItem) EditSongDialog.setTabOrder(self.ThemeSelectionComboItem, self.AuthorAddtoSongItem)
EditSongDialog.setTabOrder(self.ThemeAddItem, self.AuthorAddtoSongItem)
EditSongDialog.setTabOrder(self.AuthorAddtoSongItem, self.AuthorsListView) EditSongDialog.setTabOrder(self.AuthorAddtoSongItem, self.AuthorsListView)
EditSongDialog.setTabOrder(self.AuthorsListView, self.AuthorRemoveItem) EditSongDialog.setTabOrder(self.AuthorsListView, self.AuthorRemoveItem)
EditSongDialog.setTabOrder(self.AuthorRemoveItem, self.SongbookCombo) EditSongDialog.setTabOrder(self.AuthorRemoveItem, self.SongbookCombo)
@ -330,7 +329,6 @@ class Ui_EditSongDialog(object):
self.VerseOrderLabel.setText(QtGui.QApplication.translate("EditSongDialog", "Verse Order:", None, QtGui.QApplication.UnicodeUTF8)) self.VerseOrderLabel.setText(QtGui.QApplication.translate("EditSongDialog", "Verse Order:", None, QtGui.QApplication.UnicodeUTF8))
self.CommentsLabel.setText(QtGui.QApplication.translate("EditSongDialog", "Comments:", None, QtGui.QApplication.UnicodeUTF8)) self.CommentsLabel.setText(QtGui.QApplication.translate("EditSongDialog", "Comments:", None, QtGui.QApplication.UnicodeUTF8))
self.ThemeGroupBox.setTitle(QtGui.QApplication.translate("EditSongDialog", "Theme", None, QtGui.QApplication.UnicodeUTF8)) self.ThemeGroupBox.setTitle(QtGui.QApplication.translate("EditSongDialog", "Theme", None, QtGui.QApplication.UnicodeUTF8))
self.ThemeAddItem.setText(QtGui.QApplication.translate("EditSongDialog", "Add a Theme", None, QtGui.QApplication.UnicodeUTF8))
self.AuthorsGroupBox.setTitle(QtGui.QApplication.translate("EditSongDialog", "Authors", None, QtGui.QApplication.UnicodeUTF8)) self.AuthorsGroupBox.setTitle(QtGui.QApplication.translate("EditSongDialog", "Authors", None, QtGui.QApplication.UnicodeUTF8))
self.AuthorAddtoSongItem.setText(QtGui.QApplication.translate("EditSongDialog", "Add to Song", None, QtGui.QApplication.UnicodeUTF8)) self.AuthorAddtoSongItem.setText(QtGui.QApplication.translate("EditSongDialog", "Add to Song", None, QtGui.QApplication.UnicodeUTF8))
self.AuthorRemoveItem.setText(QtGui.QApplication.translate("EditSongDialog", "Remove", None, QtGui.QApplication.UnicodeUTF8)) self.AuthorRemoveItem.setText(QtGui.QApplication.translate("EditSongDialog", "Remove", None, QtGui.QApplication.UnicodeUTF8))

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

View File

@ -2,7 +2,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, Carsten Tinggaard Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley, Carsten Tinggaard
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
@ -17,8 +17,6 @@ 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 openlp.core.resources import *
from PyQt4 import QtGui, QtCore from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import QDialog from PyQt4.QtGui import QDialog
from PyQt4.QtCore import pyqtSignature from PyQt4.QtCore import pyqtSignature
@ -35,9 +33,9 @@ class SongBookForm(QDialog, Ui_SongBookDialog):
QDialog.__init__(self, parent) QDialog.__init__(self, parent)
self.setupUi(self) self.setupUi(self)
self.songmanager = songmanager self.songmanager = songmanager
def load_form(self): def load_form(self):
A = 1 A = 1
@pyqtSignature("QTableWidgetItem*") @pyqtSignature("QTableWidgetItem*")
def on_BookSongListView_itemClicked(self, item): def on_BookSongListView_itemClicked(self, item):
@ -45,14 +43,14 @@ class SongBookForm(QDialog, Ui_SongBookDialog):
Slot documentation goes here. Slot documentation goes here.
""" """
print "bslv ic " + str(item) print "bslv ic " + str(item)
@pyqtSignature("") @pyqtSignature("")
def on_DeleteButton_clicked(self): def on_DeleteButton_clicked(self):
""" """
Slot documentation goes here. Slot documentation goes here.
""" """
print "db c " print "db c "
@pyqtSignature("") @pyqtSignature("")
def on_AddUpdateButton_clicked(self): def on_AddUpdateButton_clicked(self):
""" """

View File

@ -0,0 +1,80 @@
# -*- 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

@ -2,7 +2,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, Carsten Tinggaard Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley, Carsten Tinggaard
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
@ -16,7 +16,6 @@ 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 openlp.core.resources import *
from PyQt4 import QtGui, QtCore from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import QDialog from PyQt4.QtGui import QDialog

View File

@ -227,10 +227,11 @@ class SongMediaItem(MediaManagerItem):
self.edit_song_form.exec_() self.edit_song_form.exec_()
def onSongEditClick(self): def onSongEditClick(self):
current_row = self.SongListView.currentRow() indexes = self.SongListView.selectedIndexes()
id = int(self.SongListView.item(current_row, 0).text()) for index in indexes:
self.edit_song_form.loadSong(id) id = self.SongListData.getId(index)
self.edit_song_form.exec_() self.edit_song_form.loadSong(id)
self.edit_song_form.exec_()
def onSongDeleteClick(self): def onSongDeleteClick(self):
indexes = self.SongListView.selectedIndexes() indexes = self.SongListView.selectedIndexes()