Complete Song Plugin Tidy Up

All lists now use same MVC mechanisms
Code in the same style.
This commit is contained in:
Tim Bentley 2009-06-14 16:12:40 +01:00
parent 69a846c7c9
commit 50d41d562e
8 changed files with 184 additions and 265 deletions

View File

@ -18,104 +18,104 @@ 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 QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.plugins.songs.lib import TextListData from openlp.core.lib import translate
class Ui_AuthorsDialog(object): class Ui_AuthorsDialog(object):
def setupUi(self, AuthorsDialog): def setupUi(self, AuthorsDialog):
AuthorsDialog.setObjectName("AuthorsDialog") AuthorsDialog.setObjectName(u'AuthorsDialog')
AuthorsDialog.resize(410, 505) AuthorsDialog.resize(410, 505)
self.DialogLayout = QtGui.QVBoxLayout(AuthorsDialog) self.DialogLayout = QtGui.QVBoxLayout(AuthorsDialog)
self.DialogLayout.setSpacing(8) self.DialogLayout.setSpacing(8)
self.DialogLayout.setMargin(8) self.DialogLayout.setMargin(8)
self.DialogLayout.setObjectName("DialogLayout") self.DialogLayout.setObjectName(u'DialogLayout')
self.AuthorListView = QtGui.QListView() self.AuthorListWidget = QtGui.QListWidget()
self.AuthorListView.setAlternatingRowColors(True) self.AuthorListWidget.setAlternatingRowColors(True)
self.DialogLayout.addWidget(self.AuthorListView) self.DialogLayout.addWidget(self.AuthorListWidget)
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(u'AuthorDetails')
self.AuthorLayout = QtGui.QVBoxLayout(self.AuthorDetails) self.AuthorLayout = QtGui.QVBoxLayout(self.AuthorDetails)
self.AuthorLayout.setSpacing(8) self.AuthorLayout.setSpacing(8)
self.AuthorLayout.setMargin(8) self.AuthorLayout.setMargin(8)
self.AuthorLayout.setObjectName("AuthorLayout") self.AuthorLayout.setObjectName(u'AuthorLayout')
self.DetailsWidget = QtGui.QWidget(self.AuthorDetails) self.DetailsWidget = QtGui.QWidget(self.AuthorDetails)
self.DetailsWidget.setObjectName("DetailsWidget") self.DetailsWidget.setObjectName(u'DetailsWidget')
self.DetailsLayout = QtGui.QFormLayout(self.DetailsWidget) self.DetailsLayout = QtGui.QFormLayout(self.DetailsWidget)
self.DetailsLayout.setMargin(0) self.DetailsLayout.setMargin(0)
self.DetailsLayout.setSpacing(8) self.DetailsLayout.setSpacing(8)
self.DetailsLayout.setObjectName("DetailsLayout") self.DetailsLayout.setObjectName(u'DetailsLayout')
self.DisplayLabel = QtGui.QLabel(self.DetailsWidget) self.DisplayLabel = QtGui.QLabel(self.DetailsWidget)
self.DisplayLabel.setObjectName("DisplayLabel") self.DisplayLabel.setObjectName(u'DisplayLabel')
self.DetailsLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.DisplayLabel) self.DetailsLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.DisplayLabel)
self.DisplayEdit = QtGui.QLineEdit(self.DetailsWidget) self.DisplayEdit = QtGui.QLineEdit(self.DetailsWidget)
self.DisplayEdit.setObjectName("DisplayEdit") self.DisplayEdit.setObjectName(u'DisplayEdit')
self.DetailsLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.DisplayEdit) self.DetailsLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.DisplayEdit)
self.FirstNameLabel = QtGui.QLabel(self.DetailsWidget) self.FirstNameLabel = QtGui.QLabel(self.DetailsWidget)
self.FirstNameLabel.setObjectName("FirstNameLabel") self.FirstNameLabel.setObjectName(u'FirstNameLabel')
self.DetailsLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.FirstNameLabel) self.DetailsLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.FirstNameLabel)
self.FirstNameEdit = QtGui.QLineEdit(self.DetailsWidget) self.FirstNameEdit = QtGui.QLineEdit(self.DetailsWidget)
self.FirstNameEdit.setObjectName("FirstNameEdit") self.FirstNameEdit.setObjectName(u'FirstNameEdit')
self.DetailsLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.FirstNameEdit) self.DetailsLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.FirstNameEdit)
self.LastNameLabel = QtGui.QLabel(self.DetailsWidget) self.LastNameLabel = QtGui.QLabel(self.DetailsWidget)
self.LastNameLabel.setObjectName("LastNameLabel") self.LastNameLabel.setObjectName(u'LastNameLabel')
self.DetailsLayout.setWidget(2, QtGui.QFormLayout.LabelRole, self.LastNameLabel) self.DetailsLayout.setWidget(2, QtGui.QFormLayout.LabelRole, self.LastNameLabel)
self.LastNameEdit = QtGui.QLineEdit(self.DetailsWidget) self.LastNameEdit = QtGui.QLineEdit(self.DetailsWidget)
self.LastNameEdit.setObjectName("LastNameEdit") self.LastNameEdit.setObjectName(u'LastNameEdit')
self.DetailsLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.LastNameEdit) self.DetailsLayout.setWidget(2, QtGui.QFormLayout.FieldRole, self.LastNameEdit)
self.AuthorLayout.addWidget(self.DetailsWidget) self.AuthorLayout.addWidget(self.DetailsWidget)
self.MessageLabel = QtGui.QLabel(self.AuthorDetails) self.MessageLabel = QtGui.QLabel(self.AuthorDetails)
self.MessageLabel.setObjectName("MessageLabel") self.MessageLabel.setObjectName(u'MessageLabel')
self.AuthorLayout.addWidget(self.MessageLabel) self.AuthorLayout.addWidget(self.MessageLabel)
self.ButtonWidget = QtGui.QWidget(self.AuthorDetails) self.ButtonWidget = QtGui.QWidget(self.AuthorDetails)
self.ButtonWidget.setMinimumSize(QtCore.QSize(0, 0)) self.ButtonWidget.setMinimumSize(QtCore.QSize(0, 0))
self.ButtonWidget.setObjectName("ButtonWidget") self.ButtonWidget.setObjectName(u'ButtonWidget')
self.ButtonLayout = QtGui.QHBoxLayout(self.ButtonWidget) self.ButtonLayout = QtGui.QHBoxLayout(self.ButtonWidget)
self.ButtonLayout.setSpacing(8) self.ButtonLayout.setSpacing(8)
self.ButtonLayout.setMargin(0) self.ButtonLayout.setMargin(0)
self.ButtonLayout.setObjectName("ButtonLayout") self.ButtonLayout.setObjectName(u'ButtonLayout')
spacerItem = QtGui.QSpacerItem(198, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) spacerItem = QtGui.QSpacerItem(198, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.ButtonLayout.addItem(spacerItem) self.ButtonLayout.addItem(spacerItem)
self.ClearButton = QtGui.QPushButton(self.ButtonWidget) self.ClearButton = QtGui.QPushButton(self.ButtonWidget)
icon = QtGui.QIcon() icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/services/service_new.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon.addPixmap(QtGui.QPixmap(u':/services/service_new.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.ClearButton.setIcon(icon) self.ClearButton.setIcon(icon)
self.ClearButton.setObjectName("ClearButton") self.ClearButton.setObjectName(u'ClearButton')
self.ButtonLayout.addWidget(self.ClearButton) self.ButtonLayout.addWidget(self.ClearButton)
self.AddUpdateButton = QtGui.QPushButton(self.ButtonWidget) self.AddUpdateButton = QtGui.QPushButton(self.ButtonWidget)
icon1 = QtGui.QIcon() icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(":/services/service_save.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon1.addPixmap(QtGui.QPixmap(u':/services/service_save.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.AddUpdateButton.setIcon(icon1) self.AddUpdateButton.setIcon(icon1)
self.AddUpdateButton.setObjectName("AddUpdateButton") self.AddUpdateButton.setObjectName(u'AddUpdateButton')
self.ButtonLayout.addWidget(self.AddUpdateButton) self.ButtonLayout.addWidget(self.AddUpdateButton)
self.DeleteButton = QtGui.QPushButton(self.ButtonWidget) self.DeleteButton = QtGui.QPushButton(self.ButtonWidget)
icon2 = QtGui.QIcon() icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap(":/services/service_delete.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon2.addPixmap(QtGui.QPixmap(u':/services/service_delete.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.DeleteButton.setIcon(icon2) self.DeleteButton.setIcon(icon2)
self.DeleteButton.setObjectName("DeleteButton") self.DeleteButton.setObjectName(u'DeleteButton')
self.ButtonLayout.addWidget(self.DeleteButton) self.ButtonLayout.addWidget(self.DeleteButton)
self.AuthorLayout.addWidget(self.ButtonWidget) self.AuthorLayout.addWidget(self.ButtonWidget)
self.DialogLayout.addWidget(self.AuthorDetails) self.DialogLayout.addWidget(self.AuthorDetails)
self.buttonBox = QtGui.QDialogButtonBox(AuthorsDialog) self.buttonBox = QtGui.QDialogButtonBox(AuthorsDialog)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal) self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok) self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok)
self.buttonBox.setObjectName("buttonBox") self.buttonBox.setObjectName(u'buttonBox')
self.DialogLayout.addWidget(self.buttonBox) self.DialogLayout.addWidget(self.buttonBox)
self.retranslateUi(AuthorsDialog) self.retranslateUi(AuthorsDialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("accepted()"), AuthorsDialog.accept) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'accepted()'), AuthorsDialog.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL("rejected()"), AuthorsDialog.reject) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'rejected()'), AuthorsDialog.reject)
QtCore.QMetaObject.connectSlotsByName(AuthorsDialog) QtCore.QMetaObject.connectSlotsByName(AuthorsDialog)
def retranslateUi(self, AuthorsDialog): def retranslateUi(self, AuthorsDialog):
AuthorsDialog.setWindowTitle(QtGui.QApplication.translate("AuthorsDialog", "Author Maintenance", None, QtGui.QApplication.UnicodeUTF8)) AuthorsDialog.setWindowTitle(translate(u'AuthorsDialog', u'Author Maintenance'))
self.AuthorDetails.setTitle(QtGui.QApplication.translate("AuthorsDialog", "Author Details", None, QtGui.QApplication.UnicodeUTF8)) self.AuthorDetails.setTitle(translate(u'AuthorsDialog', u'Author Details'))
self.DisplayLabel.setText(QtGui.QApplication.translate("AuthorsDialog", "Display Name:", None, QtGui.QApplication.UnicodeUTF8)) self.DisplayLabel.setText(translate(u'AuthorsDialog', u'Display Name:'))
self.FirstNameLabel.setText(QtGui.QApplication.translate("AuthorsDialog", "First Name:", None, QtGui.QApplication.UnicodeUTF8)) self.FirstNameLabel.setText(translate(u'AuthorsDialog', u'First Name:'))
self.LastNameLabel.setText(QtGui.QApplication.translate("AuthorsDialog", "Last Name:", None, QtGui.QApplication.UnicodeUTF8)) self.LastNameLabel.setText(translate(u'AuthorsDialog', u'Last Name:'))
self.ClearButton.setToolTip(QtGui.QApplication.translate("AuthorsDialog", "Clear Selection", None, QtGui.QApplication.UnicodeUTF8)) self.ClearButton.setToolTip(translate(u'AuthorsDialog', u'Clear Selection'))
self.ClearButton.setText(QtGui.QApplication.translate("AuthorsDialog", "Clear", None, QtGui.QApplication.UnicodeUTF8)) self.ClearButton.setText(translate(u'AuthorsDialog', u'Clear'))
self.AddUpdateButton.setToolTip(QtGui.QApplication.translate("AuthorsDialog", "Add Update Author", None, QtGui.QApplication.UnicodeUTF8)) self.AddUpdateButton.setToolTip(translate(u'AuthorsDialog', u'Add Update Author'))
self.AddUpdateButton.setText(QtGui.QApplication.translate("AuthorsDialog", "Save", None, QtGui.QApplication.UnicodeUTF8)) self.AddUpdateButton.setText(translate(u'AuthorsDialog', u'Save'))
self.DeleteButton.setToolTip(QtGui.QApplication.translate("AuthorsDialog", "Delete Author", None, QtGui.QApplication.UnicodeUTF8)) self.DeleteButton.setToolTip(translate(u'AuthorsDialog', u'Delete Author'))
self.DeleteButton.setText(QtGui.QApplication.translate("AuthorsDialog", "Delete", None, QtGui.QApplication.UnicodeUTF8)) self.DeleteButton.setText(translate(u'AuthorsDialog', u'Delete'))
self.buttonBox.setToolTip(QtGui.QApplication.translate("AuthorsDialog", "Exit Screen", None, QtGui.QApplication.UnicodeUTF8)) self.buttonBox.setToolTip(translate(u'AuthorsDialog', u'Exit Screen'))

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.core.lib import translate from openlp.core.lib import translate
from openlp.plugins.songs.forms.authorsdialog import Ui_AuthorsDialog from openlp.plugins.songs.forms.authorsdialog import Ui_AuthorsDialog
from openlp.plugins.songs.lib.classes import Author
class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog): class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
""" """
@ -42,27 +43,24 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
QtCore.SIGNAL(u'pressed()'), self.onAddUpdateButtonClick) QtCore.SIGNAL(u'pressed()'), self.onAddUpdateButtonClick)
QtCore.QObject.connect(self.DisplayEdit, QtCore.QObject.connect(self.DisplayEdit,
QtCore.SIGNAL(u'lostFocus()'), self.onDisplayEditLostFocus) QtCore.SIGNAL(u'lostFocus()'), self.onDisplayEditLostFocus)
QtCore.QObject.connect(self.AuthorListView, QtCore.QObject.connect(self.AuthorListWidget,
QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onAuthorListViewItemClicked) QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onAuthorListWidgetItemClicked)
def load_form(self): def load_form(self):
""" """
Refresh the screen and rest fields Refresh the screen and rest fields
""" """
self.AuthorListData.resetStore() self.AuthorListWidget.clear()
self.onClearButtonClick() # tidy up screen self.onClearButtonClick() # tidy up screen
authors = self.songmanager.get_authors() authors = self.songmanager.get_authors()
for author in authors: for author in authors:
self.AuthorListData.addRow(author.id,author.display_name) author_name = QtGui.QListWidgetItem(author.display_name)
#rowCount is number of rows BUT test should be Zero based author_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(author.id))
row_count = self.AuthorListData.rowCount(None) - 1 self.AuthorListWidget.addItem(author_name)
if self.currentRow > row_count: if self.currentRow >= self.AuthorListWidget.count() :
# in case we have delete the last row of the table self.AuthorListWidget.setCurrentRow(self.AuthorListWidget.count() - 1)
self.currentRow = row_count else:
row = self.AuthorListData.createIndex(self.currentRow, 0) self.AuthorListWidget.setCurrentRow(self.currentRow)
if row.isValid():
self.AuthorListView.selectionModel().setCurrentIndex(row,
QtGui.QItemSelectionModel.SelectCurrent)
self._validate_form() self._validate_form()
def onDeleteButtonClick(self): def onDeleteButtonClick(self):
@ -100,15 +98,15 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
self.author = None self.author = None
self._validate_form() self._validate_form()
def onAuthorListViewItemClicked(self, index): def onAuthorListWidgetItemClicked(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 = index.row() self.currentRow = self.AuthorListWidget.currentRow()
id = int(self.AuthorListData.getId(index)) item = self.AuthorListWidget.currentItem()
self.author = self.songmanager.get_author(id) item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.author = self.songmanager.get_author(item_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)

View File

@ -1,60 +1,66 @@
# -*- coding: utf-8 -*- # -*- 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,
# Form implementation generated from reading ui file 'songbookdialog.ui' 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
# Created: Sun Jan 4 08:43:12 2009 Foundation; version 2 of the License.
# by: PyQt4 UI code generator 4.4.3
#
# WARNING! All changes made in this file will be lost!
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
"""
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.plugins.songs.lib import TextListData from openlp.core.lib import translate
class Ui_SongBookDialog(object): class Ui_SongBookDialog(object):
def setupUi(self, SongBookDialog): def setupUi(self, SongBookDialog):
SongBookDialog.setObjectName("SongBookDialog") SongBookDialog.setObjectName(u'SongBookDialog')
SongBookDialog.resize(387, 531) SongBookDialog.resize(387, 531)
self.DialogLayout = QtGui.QVBoxLayout(SongBookDialog) self.DialogLayout = QtGui.QVBoxLayout(SongBookDialog)
self.DialogLayout.setSpacing(8) self.DialogLayout.setSpacing(8)
self.DialogLayout.setMargin(8) self.DialogLayout.setMargin(8)
self.DialogLayout.setObjectName("DialogLayout") self.DialogLayout.setObjectName(u'DialogLayout')
self.BookSongListWidget = QtGui.QListWidget()
self.BookSongListView = QtGui.QListView() self.BookSongListWidget.setAlternatingRowColors(True)
self.BookSongListView.setAlternatingRowColors(True) self.DialogLayout.addWidget(self.BookSongListWidget)
self.BookSongListData = TextListData() self.DialogLayout.addWidget(self.BookSongListWidget)
self.BookSongListView.setModel(self.BookSongListData)
self.DialogLayout.addWidget(self.BookSongListView)
self.DialogLayout.addWidget(self.BookSongListView)
self.SongBookGroup = QtGui.QGroupBox(SongBookDialog) self.SongBookGroup = QtGui.QGroupBox(SongBookDialog)
self.SongBookGroup.setMinimumSize(QtCore.QSize(0, 200)) self.SongBookGroup.setMinimumSize(QtCore.QSize(0, 200))
self.SongBookGroup.setObjectName("SongBookGroup") self.SongBookGroup.setObjectName(u'SongBookGroup')
self.SongBookLayout = QtGui.QVBoxLayout(self.SongBookGroup) self.SongBookLayout = QtGui.QVBoxLayout(self.SongBookGroup)
self.SongBookLayout.setSpacing(8) self.SongBookLayout.setSpacing(8)
self.SongBookLayout.setMargin(8) self.SongBookLayout.setMargin(8)
self.SongBookLayout.setObjectName("SongBookLayout") self.SongBookLayout.setObjectName(u'SongBookLayout')
self.DetailsWidget = QtGui.QWidget(self.SongBookGroup) self.DetailsWidget = QtGui.QWidget(self.SongBookGroup)
self.DetailsWidget.setMinimumSize(QtCore.QSize(0, 0)) self.DetailsWidget.setMinimumSize(QtCore.QSize(0, 0))
self.DetailsWidget.setObjectName("DetailsWidget") self.DetailsWidget.setObjectName(u'DetailsWidget')
self.DetailsLayout = QtGui.QFormLayout(self.DetailsWidget) self.DetailsLayout = QtGui.QFormLayout(self.DetailsWidget)
self.DetailsLayout.setMargin(0) self.DetailsLayout.setMargin(0)
self.DetailsLayout.setSpacing(8) self.DetailsLayout.setSpacing(8)
self.DetailsLayout.setObjectName("DetailsLayout") self.DetailsLayout.setObjectName(u'DetailsLayout')
self.NameLabel = QtGui.QLabel(self.DetailsWidget) self.NameLabel = QtGui.QLabel(self.DetailsWidget)
self.NameLabel.setObjectName("NameLabel") self.NameLabel.setObjectName(u'NameLabel')
self.DetailsLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.NameLabel) self.DetailsLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.NameLabel)
self.NameEdit = QtGui.QLineEdit(self.DetailsWidget) self.NameEdit = QtGui.QLineEdit(self.DetailsWidget)
self.NameEdit.setObjectName("NameEdit") self.NameEdit.setObjectName(u'NameEdit')
self.DetailsLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.NameEdit) self.DetailsLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.NameEdit)
self.PublisherLabel = QtGui.QLabel(self.DetailsWidget) self.PublisherLabel = QtGui.QLabel(self.DetailsWidget)
self.PublisherLabel.setObjectName("PublisherLabel") self.PublisherLabel.setObjectName(u'PublisherLabel')
self.DetailsLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.PublisherLabel) self.DetailsLayout.setWidget(1, QtGui.QFormLayout.LabelRole, self.PublisherLabel)
self.PublisherEdit = QtGui.QLineEdit(self.DetailsWidget) self.PublisherEdit = QtGui.QLineEdit(self.DetailsWidget)
self.PublisherEdit.setObjectName("PublisherEdit") self.PublisherEdit.setObjectName(u'PublisherEdit')
self.DetailsLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.PublisherEdit) self.DetailsLayout.setWidget(1, QtGui.QFormLayout.FieldRole, self.PublisherEdit)
self.SongBookLayout.addWidget(self.DetailsWidget) self.SongBookLayout.addWidget(self.DetailsWidget)
self.MessageLabel = QtGui.QLabel(self.SongBookGroup) self.MessageLabel = QtGui.QLabel(self.SongBookGroup)
self.MessageLabel.setObjectName("MessageLabel") self.MessageLabel.setObjectName(u'MessageLabel')
self.SongBookLayout.addWidget(self.MessageLabel) self.SongBookLayout.addWidget(self.MessageLabel)
self.ButtonWidget = QtGui.QWidget(self.SongBookGroup) self.ButtonWidget = QtGui.QWidget(self.SongBookGroup)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
@ -63,52 +69,51 @@ class Ui_SongBookDialog(object):
sizePolicy.setHeightForWidth(self.ButtonWidget.sizePolicy().hasHeightForWidth()) sizePolicy.setHeightForWidth(self.ButtonWidget.sizePolicy().hasHeightForWidth())
self.ButtonWidget.setSizePolicy(sizePolicy) self.ButtonWidget.setSizePolicy(sizePolicy)
self.ButtonWidget.setMinimumSize(QtCore.QSize(0, 0)) self.ButtonWidget.setMinimumSize(QtCore.QSize(0, 0))
self.ButtonWidget.setObjectName("ButtonWidget") self.ButtonWidget.setObjectName(u'ButtonWidget')
self.ButtonLayout = QtGui.QHBoxLayout(self.ButtonWidget) self.ButtonLayout = QtGui.QHBoxLayout(self.ButtonWidget)
self.ButtonLayout.setSpacing(8) self.ButtonLayout.setSpacing(8)
self.ButtonLayout.setMargin(0) self.ButtonLayout.setMargin(0)
self.ButtonLayout.setObjectName("ButtonLayout") self.ButtonLayout.setObjectName(u'ButtonLayout')
spacerItem = QtGui.QSpacerItem(61, 24, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) spacerItem = QtGui.QSpacerItem(61, 24, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.ButtonLayout.addItem(spacerItem) self.ButtonLayout.addItem(spacerItem)
self.ClearButton = QtGui.QPushButton(self.ButtonWidget) self.ClearButton = QtGui.QPushButton(self.ButtonWidget)
icon = QtGui.QIcon() icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/services/service_new.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon.addPixmap(QtGui.QPixmap(u':/services/service_new.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.ClearButton.setIcon(icon) self.ClearButton.setIcon(icon)
self.ClearButton.setObjectName("ClearButton") self.ClearButton.setObjectName(u'ClearButton')
self.ButtonLayout.addWidget(self.ClearButton) self.ButtonLayout.addWidget(self.ClearButton)
self.AddUpdateButton = QtGui.QPushButton(self.ButtonWidget) self.AddUpdateButton = QtGui.QPushButton(self.ButtonWidget)
icon1 = QtGui.QIcon() icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(":/services/service_save.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon1.addPixmap(QtGui.QPixmap(u':/services/service_save.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.AddUpdateButton.setIcon(icon1) self.AddUpdateButton.setIcon(icon1)
self.AddUpdateButton.setObjectName("AddUpdateButton") self.AddUpdateButton.setObjectName(u'AddUpdateButton')
self.ButtonLayout.addWidget(self.AddUpdateButton) self.ButtonLayout.addWidget(self.AddUpdateButton)
self.DeleteButton = QtGui.QPushButton(self.ButtonWidget) self.DeleteButton = QtGui.QPushButton(self.ButtonWidget)
icon2 = QtGui.QIcon() icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap(":/services/service_delete.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon2.addPixmap(QtGui.QPixmap(u':/services/service_delete.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.DeleteButton.setIcon(icon2) self.DeleteButton.setIcon(icon2)
self.DeleteButton.setObjectName("DeleteButton") self.DeleteButton.setObjectName(u'DeleteButton')
self.ButtonLayout.addWidget(self.DeleteButton) self.ButtonLayout.addWidget(self.DeleteButton)
self.SongBookLayout.addWidget(self.ButtonWidget) self.SongBookLayout.addWidget(self.ButtonWidget)
self.DialogLayout.addWidget(self.SongBookGroup) self.DialogLayout.addWidget(self.SongBookGroup)
self.ButtonBox = QtGui.QDialogButtonBox(SongBookDialog) self.ButtonBox = QtGui.QDialogButtonBox(SongBookDialog)
self.ButtonBox.setOrientation(QtCore.Qt.Horizontal) self.ButtonBox.setOrientation(QtCore.Qt.Horizontal)
self.ButtonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok) self.ButtonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok)
self.ButtonBox.setObjectName("ButtonBox") self.ButtonBox.setObjectName(u'ButtonBox')
self.DialogLayout.addWidget(self.ButtonBox) self.DialogLayout.addWidget(self.ButtonBox)
self.retranslateUi(SongBookDialog) self.retranslateUi(SongBookDialog)
QtCore.QObject.connect(self.ButtonBox, QtCore.SIGNAL("accepted()"), SongBookDialog.accept) QtCore.QObject.connect(self.ButtonBox, QtCore.SIGNAL(u'accepted()'), SongBookDialog.accept)
QtCore.QObject.connect(self.ButtonBox, QtCore.SIGNAL("rejected()"), SongBookDialog.reject) QtCore.QObject.connect(self.ButtonBox, QtCore.SIGNAL(u'rejected()'), SongBookDialog.reject)
QtCore.QMetaObject.connectSlotsByName(SongBookDialog) QtCore.QMetaObject.connectSlotsByName(SongBookDialog)
def retranslateUi(self, SongBookDialog): def retranslateUi(self, SongBookDialog):
SongBookDialog.setWindowTitle(QtGui.QApplication.translate("SongBookDialog", "Book Song Maintenance", None, QtGui.QApplication.UnicodeUTF8)) SongBookDialog.setWindowTitle(translate(u'SongBookDialog', u'Book Song Maintenance'))
self.SongBookGroup.setTitle(QtGui.QApplication.translate("SongBookDialog", "Song Book", None, QtGui.QApplication.UnicodeUTF8)) self.SongBookGroup.setTitle(translate(u'SongBookDialog', u'Song Book'))
self.NameLabel.setText(QtGui.QApplication.translate("SongBookDialog", "Name:", None, QtGui.QApplication.UnicodeUTF8)) self.NameLabel.setText(translate(u'SongBookDialog', u'Name:'))
self.PublisherLabel.setText(QtGui.QApplication.translate("SongBookDialog", "Publisher:", None, QtGui.QApplication.UnicodeUTF8)) self.PublisherLabel.setText(translate(u'SongBookDialog', u'Publisher:'))
self.ClearButton.setToolTip(QtGui.QApplication.translate("SongBookDialog", "Clear Selection", None, QtGui.QApplication.UnicodeUTF8)) self.ClearButton.setToolTip(translate(u'SongBookDialog', u'Clear Selection'))
self.ClearButton.setText(QtGui.QApplication.translate("SongBookDialog", "New", None, QtGui.QApplication.UnicodeUTF8)) self.ClearButton.setText(translate(u'SongBookDialog', u'Clear'))
self.AddUpdateButton.setToolTip(QtGui.QApplication.translate("SongBookDialog", "Add Update Author", None, QtGui.QApplication.UnicodeUTF8)) self.AddUpdateButton.setToolTip(translate(u'SongBookDialog', u'Add Update Author'))
self.AddUpdateButton.setText(QtGui.QApplication.translate("SongBookDialog", "Save", None, QtGui.QApplication.UnicodeUTF8)) self.AddUpdateButton.setText(translate(u'SongBookDialog', u'Save'))
self.DeleteButton.setToolTip(QtGui.QApplication.translate("SongBookDialog", "Delete Author", None, QtGui.QApplication.UnicodeUTF8)) self.DeleteButton.setToolTip(translate(u'SongBookDialog', u'Delete Author'))
self.DeleteButton.setText(QtGui.QApplication.translate("SongBookDialog", "Delete", None, QtGui.QApplication.UnicodeUTF8)) self.DeleteButton.setText(translate(u'SongBookDialog', u'Delete'))

View File

@ -44,28 +44,24 @@ class SongBookForm(QtGui.QDialog, Ui_SongBookDialog):
QtCore.SIGNAL(u'pressed()'), self.onAddUpdateButtonClick) QtCore.SIGNAL(u'pressed()'), self.onAddUpdateButtonClick)
QtCore.QObject.connect(self.NameEdit, QtCore.QObject.connect(self.NameEdit,
QtCore.SIGNAL(u'lostFocus()'), self.onBookNameEditLostFocus) QtCore.SIGNAL(u'lostFocus()'), self.onBookNameEditLostFocus)
QtCore.QObject.connect(self.BookSongListView, QtCore.QObject.connect(self.BookSongListWidget,
QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onBooksListViewItemClicked) QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onBooksListViewItemClicked)
def load_form(self): def load_form(self):
""" """
Refresh the screen and rest fields Refresh the screen and rest fields
""" """
self.BookSongListData.resetStore() self.BookSongListWidget.clear()
self.onClearButtonClick() # tidy up screen self.onClearButtonClick() # tidy up screen
Books = self.songmanager.get_books() books = self.songmanager.get_books()
for Book in Books: for book in books:
self.BookSongListData.addRow(Book.id,Book.name) book_name = QtGui.QListWidgetItem(book.name)
#rowCount is number of rows BUT test should be Zero based book_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(book.id))
row_count = self.BookSongListData.rowCount(None) - 1 self.BookSongListWidget.addItem(book_name)
if self.currentRow > row_count: if self.currentRow >= self.BookSongListWidget.count() :
# in case we have delete the last row of the table self.BookSongListWidget.setCurrentRow(self.BookSongListWidget.count() - 1)
self.currentRow = row_count else:
row = self.BookSongListData.createIndex(self.currentRow, 0) self.BookSongListWidget.setCurrentRow(self.currentRow)
if row.isValid():
self.BookSongListView.selectionModel().setCurrentIndex(row,
QtGui.QItemSelectionModel.SelectCurrent)
self._validate_form()
def onDeleteButtonClick(self): def onDeleteButtonClick(self):
""" """
@ -106,10 +102,10 @@ class SongBookForm(QtGui.QDialog, Ui_SongBookDialog):
An Book has been selected display it An Book has been selected display it
If the Book is attached to a Song prevent delete If the Book is attached to a Song prevent delete
""" """
self.currentRow = index.row() self.currentRow = self.BookSongListWidget.currentRow()
id = int(self.BookSongListData.getId(index)) item = self.BookSongListWidget.currentItem()
self.Book = self.songmanager.get_book(id) item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.Book = self.songmanager.get_book(item_id)
self.NameEdit.setText(self.Book.name) self.NameEdit.setText(self.Book.name)
self.PublisherEdit.setText(self.Book.publisher) self.PublisherEdit.setText(self.Book.publisher)
if len(self.Book.songs) > 0: if len(self.Book.songs) > 0:

View File

@ -1,82 +1,88 @@
# -*- coding: utf-8 -*- # -*- 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,
# Form implementation generated from reading ui file 'topicsdialog.ui' 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
# Created: Sun Jan 4 08:42:59 2009 Foundation; version 2 of the License.
# by: PyQt4 UI code generator 4.4.3
#
# WARNING! All changes made in this file will be lost!
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
"""
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.plugins.songs.lib import TextListData from openlp.core.lib import translate
class Ui_TopicsDialog(object): class Ui_TopicsDialog(object):
def setupUi(self, TopicsDialog): def setupUi(self, TopicsDialog):
TopicsDialog.setObjectName("TopicsDialog") TopicsDialog.setObjectName(u'TopicsDialog')
TopicsDialog.resize(387, 463) TopicsDialog.resize(387, 463)
self.gridLayout_2 = QtGui.QGridLayout(TopicsDialog) self.gridLayout_2 = QtGui.QGridLayout(TopicsDialog)
self.gridLayout_2.setObjectName("gridLayout_2") self.gridLayout_2.setObjectName(u'gridLayout_2')
self.TopicGroupBox = QtGui.QGroupBox(TopicsDialog) self.TopicGroupBox = QtGui.QGroupBox(TopicsDialog)
self.TopicGroupBox.setObjectName("TopicGroupBox") self.TopicGroupBox.setObjectName(u'TopicGroupBox')
self.gridLayout = QtGui.QGridLayout(self.TopicGroupBox) self.gridLayout = QtGui.QGridLayout(self.TopicGroupBox)
self.gridLayout.setObjectName("gridLayout") self.gridLayout.setObjectName(u'gridLayout')
self.TopicNameLabel = QtGui.QLabel(self.TopicGroupBox) self.TopicNameLabel = QtGui.QLabel(self.TopicGroupBox)
self.TopicNameLabel.setObjectName("TopicNameLabel") self.TopicNameLabel.setObjectName(u'TopicNameLabel')
self.gridLayout.addWidget(self.TopicNameLabel, 0, 0, 1, 1) self.gridLayout.addWidget(self.TopicNameLabel, 0, 0, 1, 1)
self.TopicNameEdit = QtGui.QLineEdit(self.TopicGroupBox) self.TopicNameEdit = QtGui.QLineEdit(self.TopicGroupBox)
self.TopicNameEdit.setObjectName("TopicNameEdit") self.TopicNameEdit.setObjectName(u'TopicNameEdit')
self.gridLayout.addWidget(self.TopicNameEdit, 0, 1, 1, 4) self.gridLayout.addWidget(self.TopicNameEdit, 0, 1, 1, 4)
spacerItem = QtGui.QSpacerItem(198, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) spacerItem = QtGui.QSpacerItem(198, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.gridLayout.addItem(spacerItem, 1, 0, 1, 2) self.gridLayout.addItem(spacerItem, 1, 0, 1, 2)
self.DeleteButton = QtGui.QPushButton(self.TopicGroupBox) self.DeleteButton = QtGui.QPushButton(self.TopicGroupBox)
icon = QtGui.QIcon() icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/services/service_delete.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon.addPixmap(QtGui.QPixmap(u':/services/service_delete.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.DeleteButton.setIcon(icon) self.DeleteButton.setIcon(icon)
self.DeleteButton.setObjectName("DeleteButton") self.DeleteButton.setObjectName(u'DeleteButton')
self.gridLayout.addWidget(self.DeleteButton, 1, 3, 1, 1) self.gridLayout.addWidget(self.DeleteButton, 1, 3, 1, 1)
self.AddUpdateButton = QtGui.QPushButton(self.TopicGroupBox) self.AddUpdateButton = QtGui.QPushButton(self.TopicGroupBox)
icon1 = QtGui.QIcon() icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(":/services/service_save.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon1.addPixmap(QtGui.QPixmap(u':/services/service_save.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.AddUpdateButton.setIcon(icon1) self.AddUpdateButton.setIcon(icon1)
self.AddUpdateButton.setObjectName("AddUpdateButton") self.AddUpdateButton.setObjectName(u'AddUpdateButton')
self.gridLayout.addWidget(self.AddUpdateButton, 1, 4, 1, 1) self.gridLayout.addWidget(self.AddUpdateButton, 1, 4, 1, 1)
self.ClearButton = QtGui.QPushButton(self.TopicGroupBox) self.ClearButton = QtGui.QPushButton(self.TopicGroupBox)
icon2 = QtGui.QIcon() icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap(":/services/service_new.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon2.addPixmap(QtGui.QPixmap(u':/services/service_new.png'), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.ClearButton.setIcon(icon2) self.ClearButton.setIcon(icon2)
self.ClearButton.setObjectName("ClearButton") self.ClearButton.setObjectName(u'ClearButton')
self.gridLayout.addWidget(self.ClearButton, 1, 2, 1, 1) self.gridLayout.addWidget(self.ClearButton, 1, 2, 1, 1)
self.gridLayout_2.addWidget(self.TopicGroupBox, 1, 0, 1, 1) self.gridLayout_2.addWidget(self.TopicGroupBox, 1, 0, 1, 1)
self.MessageLabel = QtGui.QLabel(TopicsDialog) self.MessageLabel = QtGui.QLabel(TopicsDialog)
self.MessageLabel.setObjectName("MessageLabel") self.MessageLabel.setObjectName(u'MessageLabel')
self.gridLayout_2.addWidget(self.MessageLabel, 3, 0, 1, 1) self.gridLayout_2.addWidget(self.MessageLabel, 3, 0, 1, 1)
self.TopicsListWidget = QtGui.QListWidget()
self.TopicsListView = QtGui.QListView() self.TopicsListWidget.setAlternatingRowColors(True)
self.TopicsListView.setAlternatingRowColors(True) self.gridLayout_2.addWidget(self.TopicsListWidget, 0, 0, 1, 1)
self.TopicsListData = TextListData()
self.TopicsListView.setModel(self.TopicsListData)
self.gridLayout_2.addWidget(self.TopicsListView, 0, 0, 1, 1)
self.ButtonBox = QtGui.QDialogButtonBox(TopicsDialog) self.ButtonBox = QtGui.QDialogButtonBox(TopicsDialog)
self.ButtonBox.setOrientation(QtCore.Qt.Horizontal) self.ButtonBox.setOrientation(QtCore.Qt.Horizontal)
self.ButtonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok) self.ButtonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok)
self.ButtonBox.setObjectName("ButtonBox") self.ButtonBox.setObjectName(u'ButtonBox')
self.gridLayout_2.addWidget(self.ButtonBox, 2, 0, 1, 1) self.gridLayout_2.addWidget(self.ButtonBox, 2, 0, 1, 1)
self.retranslateUi(TopicsDialog) self.retranslateUi(TopicsDialog)
QtCore.QObject.connect(self.ButtonBox, QtCore.SIGNAL("accepted()"), TopicsDialog.accept) QtCore.QObject.connect(self.ButtonBox, QtCore.SIGNAL(u'accepted()'), TopicsDialog.accept)
QtCore.QObject.connect(self.ButtonBox, QtCore.SIGNAL("rejected()"), TopicsDialog.reject) QtCore.QObject.connect(self.ButtonBox, QtCore.SIGNAL(u'rejected()'), TopicsDialog.reject)
QtCore.QMetaObject.connectSlotsByName(TopicsDialog) QtCore.QMetaObject.connectSlotsByName(TopicsDialog)
def retranslateUi(self, TopicsDialog): def retranslateUi(self, TopicsDialog):
TopicsDialog.setWindowTitle(QtGui.QApplication.translate("TopicsDialog", "Topic Maintenance", None, QtGui.QApplication.UnicodeUTF8)) TopicsDialog.setWindowTitle(translate(u'TopicsDialog', u'Topic Maintenance'))
self.TopicGroupBox.setTitle(QtGui.QApplication.translate("TopicsDialog", "Topic", None, QtGui.QApplication.UnicodeUTF8)) self.TopicGroupBox.setTitle(translate(u'TopicsDialog', u'Topic'))
self.TopicNameLabel.setText(QtGui.QApplication.translate("TopicsDialog", "Topic Name:", None, QtGui.QApplication.UnicodeUTF8)) self.TopicNameLabel.setText(translate(u'TopicsDialog', u'Topic Name:'))
self.DeleteButton.setToolTip(QtGui.QApplication.translate("TopicsDialog", "Delete Author", None, QtGui.QApplication.UnicodeUTF8)) self.DeleteButton.setToolTip(translate(u'TopicsDialog', u'Delete Author'))
self.DeleteButton.setText(QtGui.QApplication.translate("AuthorsDialog", "Delete", None, QtGui.QApplication.UnicodeUTF8)) self.DeleteButton.setText(translate(u'AuthorsDialog', u'Delete'))
self.AddUpdateButton.setToolTip(QtGui.QApplication.translate("TopicsDialog", "Add Update Author", None, QtGui.QApplication.UnicodeUTF8)) self.AddUpdateButton.setToolTip(translate(u'TopicsDialog', u'Add Update Author'))
self.AddUpdateButton.setText(QtGui.QApplication.translate("AuthorsDialog", "Save", None, QtGui.QApplication.UnicodeUTF8)) self.AddUpdateButton.setText(translate(u'AuthorsDialog', u'Save'))
self.ClearButton.setToolTip(QtGui.QApplication.translate("TopicsDialog", "Clear Selection", None, QtGui.QApplication.UnicodeUTF8)) self.ClearButton.setToolTip(translate(u'TopicsDialog', u'Clear Selection'))
self.ClearButton.setText(QtGui.QApplication.translate("TopicsDialog", "Clear", None, QtGui.QApplication.UnicodeUTF8)) self.ClearButton.setText(translate(u'TopicsDialog', u'Clear'))

View File

@ -18,7 +18,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA
""" """
from PyQt4 import QtGui, QtCore from PyQt4 import QtGui, QtCore
from openlp.core.lib import translate from openlp.core.lib import translate
from openlp.plugins.songs.lib import TextListData
from openlp.plugins.songs.forms.topicsdialog import Ui_TopicsDialog from openlp.plugins.songs.forms.topicsdialog import Ui_TopicsDialog
from openlp.plugins.songs.lib.classes import Topic from openlp.plugins.songs.lib.classes import Topic
@ -44,27 +43,24 @@ class TopicsForm(QtGui.QDialog, Ui_TopicsDialog):
QtCore.SIGNAL(u'pressed()'), self.onAddUpdateButtonClick) QtCore.SIGNAL(u'pressed()'), self.onAddUpdateButtonClick)
QtCore.QObject.connect(self.TopicNameEdit, QtCore.QObject.connect(self.TopicNameEdit,
QtCore.SIGNAL(u'lostFocus()'), self.onTopicNameEditLostFocus) QtCore.SIGNAL(u'lostFocus()'), self.onTopicNameEditLostFocus)
QtCore.QObject.connect(self.TopicsListView, QtCore.QObject.connect(self.TopicsListWidget,
QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onTopicsListViewItemClicked) QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onTopicsListWidgetItemClicked)
def load_form(self): def load_form(self):
""" """
Refresh the screen and rest fields Refresh the screen and rest fields
""" """
self.TopicsListData.resetStore() self.TopicsListWidget.clear()
self.onClearButtonClick() # tidy up screen self.onClearButtonClick() # tidy up screen
topics = self.songmanager.get_topics() topics = self.songmanager.get_topics()
for topic in topics: for topic in topics:
self.TopicsListData.addRow(topic.id,topic.name) topic_name = QtGui.QListWidgetItem(topic.name)
#rowCount is number of rows BUT test should be Zero based topic_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(topic.id))
row_count = self.TopicsListData.rowCount(None) - 1 self.TopicsListWidget.addItem(topic_name)
if self.currentRow > row_count: if self.currentRow >= self.TopicsListWidget.count() :
# in case we have delete the last row of the table self.TopicsListWidget.setCurrentRow(self.TopicsListWidget.count() - 1)
self.currentRow = row_count else:
row = self.TopicsListData.createIndex(self.currentRow, 0) self.TopicsListWidget.setCurrentRow(self.currentRow)
if row.isValid():
self.TopicsListView.selectionModel().setCurrentIndex(row,
QtGui.QItemSelectionModel.SelectCurrent)
self._validate_form() self._validate_form()
def onDeleteButtonClick(self): def onDeleteButtonClick(self):
@ -99,15 +95,15 @@ class TopicsForm(QtGui.QDialog, Ui_TopicsDialog):
self.topic = None self.topic = None
self._validate_form() self._validate_form()
def onTopicsListViewItemClicked(self, index): def onTopicsListWidgetItemClicked(self, index):
""" """
An Topic has been selected display it An Topic has been selected display it
If the Topic is attached to a Song prevent delete If the Topic is attached to a Song prevent delete
""" """
self.currentRow = index.row() self.currentRow = self.TopicsListWidget.currentRow()
id = int(self.TopicsListData.getId(index)) item = self.TopicsListWidget.currentItem()
self.topic = self.songmanager.get_topic(id) item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.topic = self.songmanager.get_topic(item_id)
self.TopicNameEdit.setText(self.topic.name) self.TopicNameEdit.setText(self.topic.name)
if len(self.topic.songs) > 0: if len(self.topic.songs) > 0:
self.MessageLabel.setText(translate(u'TopicForm', u'Topic in use "Delete" is disabled')) self.MessageLabel.setText(translate(u'TopicForm', u'Topic in use "Delete" is disabled'))

View File

@ -17,7 +17,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 textlistdata import TextListData
from manager import SongManager from manager import SongManager
from songstab import SongsTab from songstab import SongsTab
from mediaitem import SongMediaItem from mediaitem import SongMediaItem

View File

@ -1,81 +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)
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:
if row == self.rowCount(None):
row -= 1
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)