Song plugin add to service manager

custom and bible cleanups
This commit is contained in:
Tim Bentley 2009-06-03 16:38:14 +01:00
parent a2034dd132
commit 5fbc870c64
8 changed files with 211 additions and 53 deletions

View File

@ -109,7 +109,7 @@ class Renderer:
""" """
External API to sort out the text to pe placed on the frame External API to sort out the text to pe placed on the frame
""" """
#print "########## Format Slide ##################" print "########## Format Slide ##################"
log.debug(u'format_slide %s', words) log.debug(u'format_slide %s', words)
verses = [] verses = []
words = words.replace("\r\n", "\n") words = words.replace("\r\n", "\n")
@ -121,8 +121,8 @@ class Renderer:
text.append(line) text.append(line)
split_text = self._split_set_of_lines(text, False) split_text = self._split_set_of_lines(text, False)
#print "split text ", split_text print "split text ", split_text
#print "text ", text print "text ", text
return split_text return split_text
# def render_screen(self, screennum): # def render_screen(self, screennum):

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
@ -23,6 +23,3 @@ from customserviceitem import CustomServiceItem
from manager import CustomManager from manager import CustomManager
from customtab import CustomTab from customtab import CustomTab
from mediaitem import CustomMediaItem from mediaitem import CustomMediaItem
__all__ = ['CustomManager', 'CustomTab', 'CustomMediaItem', 'CustomServiceItem','TextListData']

View File

@ -228,11 +228,11 @@ class CustomMediaItem(MediaManagerItem):
self.parent.service_manager.addServiceItem(service_item) self.parent.service_manager.addServiceItem(service_item)
def generateSlideData(self, service_item): def generateSlideData(self, service_item):
indexes = self.CustomListView.selectedIndexes()
raw_slides =[] raw_slides =[]
raw_footer = [] raw_footer = []
slide = None slide = None
theme = None theme = None
indexes = self.CustomListView.selectedIndexes()
for index in indexes: for index in indexes:
id = self.CustomListData.getId(index) id = self.CustomListData.getId(index)
customSlide = self.parent.custommanager.get_custom(id) customSlide = self.parent.custommanager.get_custom(id)

View File

@ -1,3 +1,22 @@
# -*- 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 import logging
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
@ -7,16 +26,16 @@ class TextListData(QtCore.QAbstractListModel):
An abstract list of strings An abstract list of strings
""" """
global log global log
log=logging.getLogger(u'TextListData') log = logging.getLogger(u'TextListData')
log.info(u'started') log.info(u'started')
def __init__(self): def __init__(self):
QtCore.QAbstractListModel.__init__(self) QtCore.QAbstractListModel.__init__(self)
self.items=[] # will be a list of (database id , title) tuples self.items = [] # will be a list of (database id , title) tuples
def resetStore(self): def resetStore(self):
#reset list so can be reloaded #reset list so can be reloaded
self.items=[] self.items = []
def rowCount(self, parent): def rowCount(self, parent):
return len(self.items) return len(self.items)
@ -36,7 +55,7 @@ class TextListData(QtCore.QAbstractListModel):
self.insertRow(len(self.items), id, title) self.insertRow(len(self.items), id, title)
def data(self, index, role): def data(self, index, role):
row=index.row() row = index.row()
if row > len(self.items): # if the last row is selected and deleted, we then get called with an empty 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() return QtCore.QVariant()
if role == QtCore.Qt.DisplayRole: if role == QtCore.Qt.DisplayRole:

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,10 +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 manager import SongManager from manager import SongManager
from songstab import SongsTab from songstab import SongsTab
from mediaitem import SongMediaItem from mediaitem import SongMediaItem
#from xml import SongOpenXml
#__all__ = ['SongManager', 'SongsTab', 'SongMediaItem']

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
@ -21,9 +21,33 @@ import logging
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.lib import MediaManagerItem, translate from openlp.core.lib import MediaManagerItem, translate, ServiceItem
from openlp.plugins.songs.forms import EditSongForm from openlp.plugins.songs.forms import EditSongForm
from openlp.plugins.songs.lib import TextListData
class SongList(QtGui.QListView):
def __init__(self,parent=None,name=None):
QtGui.QListView.__init__(self,parent)
def mouseMoveEvent(self, event):
"""
Drag and drop event does not care what data is selected
as the recepient will use events to request the data move
just tell it what plugin to call
"""
if event.buttons() != QtCore.Qt.LeftButton:
return
drag = QtGui.QDrag(self)
mimeData = QtCore.QMimeData()
drag.setMimeData(mimeData)
mimeData.setText(u'Song')
dropAction = drag.start(QtCore.Qt.CopyAction)
if dropAction == QtCore.Qt.CopyAction:
self.close()
class SongMediaItem(MediaManagerItem): class SongMediaItem(MediaManagerItem):
""" """
@ -98,19 +122,29 @@ class SongMediaItem(MediaManagerItem):
self.SearchLayout.addWidget(self.SearchTextButton, 3, 2, 1, 1) self.SearchLayout.addWidget(self.SearchTextButton, 3, 2, 1, 1)
# Add the song widget to the page layout # Add the song widget to the page layout
self.PageLayout.addWidget(self.SongWidget) self.PageLayout.addWidget(self.SongWidget)
self.SongListView = QtGui.QTableWidget()
self.SongListView.setColumnCount(2) self.SongListView = SongList()
self.SongListView.setColumnHidden(0, True)
self.SongListView.setColumnWidth(1, 240)
self.SongListView.setShowGrid(False)
self.SongListView.setSortingEnabled(False)
self.SongListView.setAlternatingRowColors(True) self.SongListView.setAlternatingRowColors(True)
self.SongListView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) self.SongListData = TextListData()
self.SongListView.horizontalHeader().setVisible(False) self.SongListView.setModel(self.SongListData)
self.SongListView.verticalHeader().setVisible(False) self.SongListView.setDragEnabled(True)
self.SongListView.setGeometry(QtCore.QRect(10, 100, 256, 591))
# self.SongListView = QtGui.QTableWidget()
# self.SongListView.setColumnCount(2)
# self.SongListView.setColumnHidden(0, True)
# self.SongListView.setColumnWidth(1, 240)
# self.SongListView.setShowGrid(False)
# self.SongListView.setSortingEnabled(False)
# self.SongListView.setAlternatingRowColors(True)
# self.SongListView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
# self.SongListView.horizontalHeader().setVisible(False)
# self.SongListView.verticalHeader().setVisible(False)
# self.SongListView.setGeometry(QtCore.QRect(10, 100, 256, 591))
self.SongListView.setObjectName('SongListView') self.SongListView.setObjectName('SongListView')
self.PageLayout.addWidget(self.SongListView) self.PageLayout.addWidget(self.SongListView)
self.SongListView.setDragEnabled(True)
# Signals and slots # Signals and slots
QtCore.QObject.connect(self.SearchTextButton, QtCore.QObject.connect(self.SearchTextButton,
QtCore.SIGNAL('pressed()'), self.onSearchTextButtonClick) QtCore.SIGNAL('pressed()'), self.onSearchTextButtonClick)
@ -118,8 +152,8 @@ class SongMediaItem(MediaManagerItem):
QtCore.SIGNAL('pressed()'), self.onClearTextButtonClick) QtCore.SIGNAL('pressed()'), self.onClearTextButtonClick)
QtCore.QObject.connect(self.SearchTextEdit, QtCore.QObject.connect(self.SearchTextEdit,
QtCore.SIGNAL('textChanged(const QString&)'), self.onSearchTextEditChanged) QtCore.SIGNAL('textChanged(const QString&)'), self.onSearchTextEditChanged)
QtCore.QObject.connect(self.SongListView, # QtCore.QObject.connect(self.SongListView,
QtCore.SIGNAL('itemPressed(QTableWidgetItem * item)'), self.onSongSelected) # QtCore.SIGNAL('itemPressed(QTableWidgetItem * item)'), self.onSongSelected)
#define and add the context menu #define and add the context menu
self.SongListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) self.SongListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu)
self.SongListView.addAction(self.contextMenuAction(self.SongListView, self.SongListView.addAction(self.contextMenuAction(self.SongListView,
@ -148,26 +182,18 @@ class SongMediaItem(MediaManagerItem):
self.SearchTypeComboBox.addItem(translate('SongMediaItem', u'Authors')) self.SearchTypeComboBox.addItem(translate('SongMediaItem', u'Authors'))
def displayResults(self, searchresults): def displayResults(self, searchresults):
log.debug("_search results") log.debug("display results")
self.SongListView.clear() # clear the results self.SongListData.resetStore()
self.SongListView.horizontalHeader().setVisible(False)
self.SongListView.verticalHeader().setVisible(False)
self.SongListView.setRowCount(0)
#log.debug("Records returned from search %s", len(searchresults)) #log.debug("Records returned from search %s", len(searchresults))
for song in searchresults: for song in searchresults:
row_count = self.SongListView.rowCount()
self.SongListView.setRowCount(row_count + 1)
song_index = QtGui.QTableWidgetItem(str(song.id))
self.SongListView.setItem(row_count, 0, song_index)
author_list = u'' author_list = u''
for author in song.authors: for author in song.authors:
if author_list != u'': if author_list != u'':
author_list = author_list + u', ' author_list = author_list + u', '
author_list = author_list + author.display_name author_list = author_list + author.display_name
song_detail = QtGui.QTableWidgetItem( song_detail = str(u'%s (%s)' % (str(song.title), str(author_list)))
u'%s (%s)' % (str(song.title), str(author_list)))
self.SongListView.setItem(row_count, 1, song_detail) self.SongListData.addRow(song.id,song_detail)
self.SongListView.setRowHeight(row_count, 20)
def onClearTextButtonClick(self): def onClearTextButtonClick(self):
""" """
@ -197,9 +223,6 @@ class SongMediaItem(MediaManagerItem):
#searchresults = self.songmanager.get_song_from_author(searchtext) #searchresults = self.songmanager.get_song_from_author(searchtext)
self.displayResults(search_results) self.displayResults(search_results)
def onSongSelected(self, item):
print item
def onSongNewClick(self): def onSongNewClick(self):
self.edit_song_form.exec_() self.edit_song_form.exec_()
@ -210,13 +233,46 @@ class SongMediaItem(MediaManagerItem):
self.edit_song_form.exec_() self.edit_song_form.exec_()
def onSongDeleteClick(self): def onSongDeleteClick(self):
pass indexes = self.SongListView.selectedIndexes()
for index in indexes:
id = self.SongListData.getId(index)
self.parent.songmanager.delete_song(id)
self.SongListData.deleteRow(index)
def onSongPreviewClick(self): def onSongPreviewClick(self):
pass service_item = ServiceItem(self.parent)
service_item.addIcon( ":/media/media_song.png")
self.generateSlideData(service_item)
self.parent.preview_controller.addServiceItem(service_item)
def generateSlideData(self, service_item):
raw_slides =[]
raw_footer = []
indexes = self.SongListView.selectedIndexes()
for index in indexes:
id = self.SongListData.getId(index)
song = self.parent.songmanager.get_song(id)
if song.theme_name == None or len(song.theme_name) == 0:
service_item.theme = None
else:
service_item.theme = song.theme_name
verses = song.lyrics.split(u'\n\n')
for verse in verses:
raw_slides.append(verse)
service_item.raw_slides = raw_slides
service_item.title = song.title
raw_footer.append(str(u'%s \n%s \n' % (song.title, song.copyright )))
raw_footer.append(song.copyright)
service_item.raw_footer = raw_footer
def onSongLiveClick(self): def onSongLiveClick(self):
pass service_item = ServiceItem(self.parent)
service_item.addIcon( ":/media/media_song.png")
self.generateSlideData(service_item)
self.parent.live_controller.addServiceItem(service_item)
def onSongAddClick(self): def onSongAddClick(self):
pass service_item = ServiceItem(self.parent)
service_item.addIcon( ":/media/media_song.png")
self.generateSlideData(service_item)
self.parent.service_manager.addServiceItem(service_item)

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

@ -49,8 +49,8 @@ class SongsPlugin(Plugin):
def get_media_manager_item(self): def get_media_manager_item(self):
# Create the MediaManagerItem object # Create the MediaManagerItem object
self.MediaManagerItem = SongMediaItem(self, self.icon, 'Songs') self.media_item = SongMediaItem(self, self.icon, 'Songs')
return self.MediaManagerItem return self.media_item
def add_import_menu_item(self, import_menu): def add_import_menu_item(self, import_menu):
self.ImportSongMenu = QtGui.QMenu(import_menu) self.ImportSongMenu = QtGui.QMenu(import_menu)
@ -127,3 +127,12 @@ class SongsPlugin(Plugin):
if event.event_type == EventType.ThemeListChanged: if event.event_type == EventType.ThemeListChanged:
log.debug(u'New Theme request received') log.debug(u'New Theme request received')
#self.edit_custom_form.loadThemes(self.theme_manager.getThemes()) #self.edit_custom_form.loadThemes(self.theme_manager.getThemes())
if event.event_type == EventType.LoadServiceItem and event.payload == 'Song':
log.debug(u'Load Service Item received')
self.media_item.onSongAddClick()
if event.event_type == EventType.PreviewShow and event.payload == 'Song':
log.debug(u'Load Preview Item received ')
self.media_item.onSongPreviewClick()
if event.event_type == EventType.LiveShow and event.payload == 'Song':
log.debug(u'Load Live Show Item received')
self.media_item.onSongLiveClick()