2008-12-01 13:15:31 +00:00
|
|
|
# -*- 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 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
|
|
|
|
"""
|
2009-01-12 19:31:29 +00:00
|
|
|
from PyQt4 import Qt, QtCore, QtGui
|
2009-02-17 21:01:27 +00:00
|
|
|
from PyQt4.QtGui import QDialog
|
2008-12-24 07:28:25 +00:00
|
|
|
from PyQt4.QtCore import pyqtSignature
|
|
|
|
|
2009-01-01 10:03:09 +00:00
|
|
|
from authorsform import AuthorsForm
|
|
|
|
from topicsform import TopicsForm
|
|
|
|
from songbookform import SongBookForm
|
|
|
|
|
2008-12-24 07:28:25 +00:00
|
|
|
from editsongdialog import Ui_EditSongDialog
|
|
|
|
|
2009-02-17 21:01:27 +00:00
|
|
|
class EditSongForm(QDialog, Ui_EditSongDialog):
|
2008-12-24 07:28:25 +00:00
|
|
|
"""
|
|
|
|
Class documentation goes here.
|
|
|
|
"""
|
|
|
|
def __init__(self, songmanager, parent = None):
|
|
|
|
"""
|
|
|
|
Constructor
|
|
|
|
"""
|
2009-02-17 21:01:27 +00:00
|
|
|
QDialog.__init__(self, parent)
|
2008-12-24 07:28:25 +00:00
|
|
|
self.setupUi(self)
|
2009-02-19 22:25:58 +00:00
|
|
|
# Connecting signals and slots
|
|
|
|
QtCore.QObject.connect(self.AddAuthorsButton, QtCore.SIGNAL('clicked()'), self.onAddAuthorsButtonClicked)
|
|
|
|
QtCore.QObject.connect(self.AddTopicButton, QtCore.SIGNAL('clicked()'), self.onAddTopicButtonClicked)
|
|
|
|
QtCore.QObject.connect(self.CopyrightInsertItem, QtCore.SIGNAL('clicked()'), self.onCopyrightInsertItemTriggered)
|
|
|
|
# Create other objects and forms
|
2008-12-24 07:28:25 +00:00
|
|
|
self.songmanager = songmanager
|
2009-01-01 10:03:09 +00:00
|
|
|
self.authors_form = AuthorsForm(self.songmanager)
|
|
|
|
self.topics_form = TopicsForm(self.songmanager)
|
2009-01-17 13:58:16 +00:00
|
|
|
self.song_book_form = SongBookForm(self.songmanager)
|
2008-12-24 07:28:25 +00:00
|
|
|
self.initialise()
|
2009-01-10 08:33:31 +00:00
|
|
|
|
|
|
|
self.AuthorsListView.setColumnCount(2)
|
|
|
|
self.AuthorsListView.setColumnHidden(0, True)
|
|
|
|
self.AuthorsListView.setColumnWidth(1, 200)
|
|
|
|
self.AuthorsListView.setShowGrid(False)
|
2009-01-17 13:58:16 +00:00
|
|
|
self.AuthorsListView.setSortingEnabled(False)
|
2009-01-10 08:33:31 +00:00
|
|
|
self.AuthorsListView.setAlternatingRowColors(True)
|
2009-01-17 13:58:16 +00:00
|
|
|
self.savebutton = self.ButtonBox.button(QtGui.QDialogButtonBox.Save)
|
|
|
|
|
2008-12-24 07:28:25 +00:00
|
|
|
def initialise(self):
|
2008-12-24 14:07:27 +00:00
|
|
|
list = self.songmanager.get_authors()
|
|
|
|
self.AuthorsSelectionComboItem.clear()
|
2009-01-06 18:36:54 +00:00
|
|
|
for i in list:
|
2009-01-10 08:33:31 +00:00
|
|
|
self.AuthorsSelectionComboItem.addItem( i.display_name)
|
2008-12-24 14:07:27 +00:00
|
|
|
|
2009-02-19 22:25:58 +00:00
|
|
|
def loadSong(self, id):
|
|
|
|
self.song = self.songmanager.get_song(id)
|
2009-01-17 13:58:16 +00:00
|
|
|
self.TitleEditItem.setText(self.song.title)
|
2009-01-12 19:31:29 +00:00
|
|
|
self.LyricsTextEdit.setText(self.song.lyrics)
|
|
|
|
self.CopyrightEditItem.setText(self.song.copyright)
|
2009-01-10 08:33:31 +00:00
|
|
|
|
|
|
|
self.AuthorsListView.clear() # clear the results
|
2009-02-17 21:01:27 +00:00
|
|
|
self.AuthorsListView.setHorizontalHeaderLabels(QtCore.QStringList(['', u'Author']))
|
|
|
|
self.AuthorsListView.setVerticalHeaderLabels(QtCore.QStringList(['']))
|
|
|
|
self.AuthorsListView.horizontalHeader().setVisible(False)
|
|
|
|
self.AuthorsListView.verticalHeader().setVisible(False)
|
2009-01-10 08:33:31 +00:00
|
|
|
self.AuthorsListView.setRowCount(0)
|
2009-01-12 19:31:29 +00:00
|
|
|
for author in self.song.authors:
|
2009-02-19 22:25:58 +00:00
|
|
|
row_count = self.AuthorsListView.rowCount()
|
|
|
|
self.AuthorsListView.setRowCount(row_count + 1)
|
2009-02-17 21:01:27 +00:00
|
|
|
author_id = QtGui.QTableWidgetItem(str(author.id))
|
2009-02-19 22:25:58 +00:00
|
|
|
self.AuthorsListView.setItem(row_count, 0, author_id)
|
2009-02-17 21:01:27 +00:00
|
|
|
author_name = QtGui.QTableWidgetItem(str(author.display_name))
|
2009-02-19 22:25:58 +00:00
|
|
|
self.AuthorsListView.setItem(row_count, 1, author_name)
|
|
|
|
self.AuthorsListView.setRowHeight(row_count, 20)
|
2009-01-17 13:58:16 +00:00
|
|
|
self._validate_song()
|
2008-12-01 13:15:31 +00:00
|
|
|
|
2009-02-19 22:25:58 +00:00
|
|
|
def onAddAuthorsButtonClicked(self):
|
2009-01-01 10:03:09 +00:00
|
|
|
"""
|
|
|
|
Slot documentation goes here.
|
|
|
|
"""
|
|
|
|
self.authors_form.load_form()
|
2009-02-19 22:25:58 +00:00
|
|
|
self.authors_form.exec_()
|
2009-01-01 10:03:09 +00:00
|
|
|
|
2009-02-19 22:25:58 +00:00
|
|
|
def onAddTopicButtonClicked(self):
|
2009-01-01 10:03:09 +00:00
|
|
|
"""
|
|
|
|
Slot documentation goes here.
|
|
|
|
"""
|
|
|
|
self.topics_form.load_form()
|
2009-02-19 22:25:58 +00:00
|
|
|
self.topics_form.exec_()
|
2009-01-17 13:58:16 +00:00
|
|
|
|
2009-02-17 21:01:27 +00:00
|
|
|
@pyqtSignature("")
|
2009-01-01 10:03:09 +00:00
|
|
|
def on_AddSongBookButton_clicked(self):
|
|
|
|
"""
|
|
|
|
Slot documentation goes here.
|
|
|
|
"""
|
|
|
|
self.song_book_form.load_form()
|
2009-02-19 22:25:58 +00:00
|
|
|
self.song_book_form.exec_()
|
2009-01-17 13:58:16 +00:00
|
|
|
|
2009-01-12 19:31:29 +00:00
|
|
|
def _validate_song(self):
|
|
|
|
"""
|
|
|
|
Check the validity of the form. Only display the 'save' if the data can be saved.
|
2009-01-17 13:58:16 +00:00
|
|
|
"""
|
2009-01-12 19:31:29 +00:00
|
|
|
valid = True # Lets be nice and assume the data is correct.
|
|
|
|
if len(self.TitleEditItem.displayText()) == 0: #Song title missing
|
|
|
|
valid = False
|
2009-02-17 21:01:27 +00:00
|
|
|
#self._color_widget(self.TitleEditItem, True)
|
|
|
|
#else:
|
|
|
|
#self._color_widget(self.TitleEditItem, False)
|
2009-01-12 19:31:29 +00:00
|
|
|
if len(self.CopyrightEditItem.displayText()) == 0: #Song title missing
|
|
|
|
valid = False
|
2009-02-17 21:01:27 +00:00
|
|
|
#self._color_widget(self.CopyrightEditItem, True)
|
|
|
|
#else:
|
|
|
|
#self._color_widget(self.CopyrightEditItem, False)
|
2009-01-17 13:58:16 +00:00
|
|
|
|
2009-01-12 19:31:29 +00:00
|
|
|
if valid:
|
|
|
|
self.ButtonBox.addButton(self.savebutton, QtGui.QDialogButtonBox.AcceptRole) # hide the save button tile screen is valid
|
|
|
|
else:
|
|
|
|
self.ButtonBox.removeButton(self.savebutton) # hide the save button tile screen is valid
|
2009-01-17 13:58:16 +00:00
|
|
|
|
2009-01-12 19:31:29 +00:00
|
|
|
def _color_widget(self, slot, invalid):
|
|
|
|
r = Qt.QPalette(slot.palette())
|
|
|
|
if invalid == True:
|
|
|
|
r.setColor(Qt.QPalette.Base, Qt.QColor('darkRed'))
|
|
|
|
else:
|
2009-01-17 13:58:16 +00:00
|
|
|
r.setColor(Qt.QPalette.Base, Qt.QColor('white'))
|
2009-01-12 19:31:29 +00:00
|
|
|
slot.setPalette(r)
|
2009-01-17 13:58:16 +00:00
|
|
|
slot.setAutoFillBackground(True)
|
|
|
|
|
2009-01-12 19:31:29 +00:00
|
|
|
def on_TitleEditItem_lostFocus(self):
|
2009-02-17 21:01:27 +00:00
|
|
|
#self._validate_song()
|
|
|
|
pass
|
|
|
|
|
2009-02-19 22:25:58 +00:00
|
|
|
def onCopyrightInsertItemTriggered(self):
|
|
|
|
text = self.CopyrightEditItem.displayText()
|
|
|
|
pos = self.CopyrightEditItem.cursorPosition()
|
|
|
|
text = text[:pos] + u'©' + text[pos:]
|
|
|
|
self.CopyrightEditItem.setText(text)
|
|
|
|
self.CopyrightEditItem.setFocus()
|
|
|
|
self.CopyrightEditItem.setCursorPosition(pos + 1)
|