openlp/openlp/core/ui/serviceitemeditform.py

125 lines
5.3 KiB
Python
Raw Normal View History

2010-03-03 17:48:37 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2010-12-26 11:04:47 +00:00
# Copyright (c) 2008-2011 Raoul Snyman #
# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael #
2010-07-24 22:10:47 +00:00
# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian #
# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
# Carsten Tinggaard, Frode Woldsund #
2010-03-03 17:48:37 +00:00
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
from PyQt4 import QtCore, QtGui
2010-03-17 21:08:18 +00:00
from serviceitemeditdialog import Ui_ServiceItemEditDialog
2010-03-03 17:48:37 +00:00
2010-03-17 21:08:18 +00:00
class ServiceItemEditForm(QtGui.QDialog, Ui_ServiceItemEditDialog):
2010-03-03 17:48:37 +00:00
"""
This is the form that is used to edit the verses of the song.
"""
def __init__(self, parent=None):
"""
Constructor
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
2010-03-18 21:50:20 +00:00
self.itemList = []
# enable drop
2010-06-08 15:56:47 +00:00
QtCore.QObject.connect(self.upButton, QtCore.SIGNAL(u'clicked()'),
self.onItemUp)
QtCore.QObject.connect(self.downButton, QtCore.SIGNAL(u'clicked()'),
self.onItemDown)
QtCore.QObject.connect(self.deleteButton, QtCore.SIGNAL(u'clicked()'),
self.onItemDelete)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'accepted()'),
self.accept)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'rejected()'),
self.reject)
2010-03-18 21:50:20 +00:00
def setServiceItem(self, item):
self.item = item
self.itemList = []
if self.item.is_image():
self.data = True
for frame in self.item._raw_frames:
self.itemList.append(frame)
self.loadData()
def getServiceItem(self):
if self.data:
self.item._raw_frames = []
if self.item.is_image():
for item in self.itemList:
2010-12-17 19:15:31 +00:00
self.item.add_from_image(item[u'path'], item[u'title'])
2010-03-18 21:50:20 +00:00
self.item.render()
return self.item
def loadData(self):
self.listWidget.clear()
for frame in self.itemList:
item_name = QtGui.QListWidgetItem(frame[u'title'])
self.listWidget.addItem(item_name)
2010-06-25 16:50:35 +00:00
if self.listWidget.count() == 1:
2010-06-25 18:18:52 +00:00
self.downButton.setEnabled(False)
self.upButton.setEnabled(False)
2010-06-25 16:50:35 +00:00
self.deleteButton.setEnabled(False)
else:
2010-06-25 18:18:52 +00:00
self.downButton.setEnabled(True)
self.upButton.setEnabled(True)
2010-06-25 16:50:35 +00:00
self.deleteButton.setEnabled(True)
2010-03-18 21:50:20 +00:00
def onItemDelete(self):
"""
2010-03-19 07:23:48 +00:00
Delete the selected row
2010-03-18 21:50:20 +00:00
"""
items = self.listWidget.selectedItems()
for item in items:
2010-06-26 16:08:38 +00:00
row = self.listWidget.row(item)
2010-03-19 07:23:48 +00:00
self.itemList.remove(self.itemList[row])
self.loadData()
2010-06-26 16:08:38 +00:00
if row == self.listWidget.count():
self.listWidget.setCurrentRow(row - 1)
else:
self.listWidget.setCurrentRow(row)
2010-03-18 21:50:20 +00:00
def onItemUp(self):
"""
2010-03-19 07:23:48 +00:00
Move the selected row up in the list
2010-03-18 21:50:20 +00:00
"""
items = self.listWidget.selectedItems()
for item in items:
2010-06-26 16:13:52 +00:00
row = self.listWidget.row(item)
2010-03-18 21:50:20 +00:00
if row > 0:
temp = self.itemList[row]
self.itemList.remove(self.itemList[row])
self.itemList.insert(row - 1, temp)
self.loadData()
2010-06-18 07:42:38 +00:00
self.listWidget.setCurrentRow(row - 1)
2010-03-18 21:50:20 +00:00
def onItemDown(self):
"""
2010-03-19 07:23:48 +00:00
Move the selected row down in the list
2010-03-18 21:50:20 +00:00
"""
items = self.listWidget.selectedItems()
for item in items:
2010-06-26 16:13:52 +00:00
row = self.listWidget.row(item)
2010-03-18 21:50:20 +00:00
if row < len(self.itemList) and row is not -1:
temp = self.itemList[row]
self.itemList.remove(self.itemList[row])
self.itemList.insert(row + 1, temp)
self.loadData()
2010-12-26 11:04:47 +00:00
self.listWidget.setCurrentRow(row + 1)