diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index c873fed7a..a661552c3 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -109,7 +109,7 @@ class Renderer: """ 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) verses = [] words = words.replace("\r\n", "\n") @@ -121,8 +121,8 @@ class Renderer: text.append(line) split_text = self._split_set_of_lines(text, False) - #print "split text ", split_text - #print "text ", text + print "split text ", split_text + print "text ", text return split_text # def render_screen(self, screennum): diff --git a/openlp/plugins/custom/lib/__init__.py b/openlp/plugins/custom/lib/__init__.py index 0cd9a4d66..dde02b5f6 100644 --- a/openlp/plugins/custom/lib/__init__.py +++ b/openlp/plugins/custom/lib/__init__.py @@ -3,7 +3,7 @@ """ OpenLP - Open Source Lyrics Projection 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 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 customtab import CustomTab from mediaitem import CustomMediaItem - -__all__ = ['CustomManager', 'CustomTab', 'CustomMediaItem', 'CustomServiceItem','TextListData'] - diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index 64294135f..0d2311462 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -228,11 +228,11 @@ class CustomMediaItem(MediaManagerItem): self.parent.service_manager.addServiceItem(service_item) def generateSlideData(self, service_item): - indexes = self.CustomListView.selectedIndexes() raw_slides =[] raw_footer = [] slide = None theme = None + indexes = self.CustomListView.selectedIndexes() for index in indexes: id = self.CustomListData.getId(index) customSlide = self.parent.custommanager.get_custom(id) diff --git a/openlp/plugins/custom/lib/textlistdata.py b/openlp/plugins/custom/lib/textlistdata.py index 6774b230c..547e978f8 100644 --- a/openlp/plugins/custom/lib/textlistdata.py +++ b/openlp/plugins/custom/lib/textlistdata.py @@ -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 from PyQt4 import QtCore, QtGui @@ -7,16 +26,16 @@ class TextListData(QtCore.QAbstractListModel): An abstract list of strings """ global log - log=logging.getLogger(u'TextListData') + 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 + self.items = [] # will be a list of (database id , title) tuples def resetStore(self): #reset list so can be reloaded - self.items=[] + self.items = [] def rowCount(self, parent): return len(self.items) @@ -36,7 +55,7 @@ class TextListData(QtCore.QAbstractListModel): self.insertRow(len(self.items), id, title) 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! return QtCore.QVariant() if role == QtCore.Qt.DisplayRole: diff --git a/openlp/plugins/songs/lib/__init__.py b/openlp/plugins/songs/lib/__init__.py index 699daee1b..0bc7d70f2 100644 --- a/openlp/plugins/songs/lib/__init__.py +++ b/openlp/plugins/songs/lib/__init__.py @@ -3,7 +3,7 @@ """ OpenLP - Open Source Lyrics Projection 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 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 Place, Suite 330, Boston, MA 02111-1307 USA """ - +from textlistdata import TextListData from manager import SongManager from songstab import SongsTab from mediaitem import SongMediaItem -#from xml import SongOpenXml - -#__all__ = ['SongManager', 'SongsTab', 'SongMediaItem'] diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 02c2a1817..8b8a0dd3c 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -3,7 +3,7 @@ """ OpenLP - Open Source Lyrics Projection 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 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 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.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): """ @@ -98,19 +122,29 @@ class SongMediaItem(MediaManagerItem): self.SearchLayout.addWidget(self.SearchTextButton, 3, 2, 1, 1) # Add the song widget to the page layout self.PageLayout.addWidget(self.SongWidget) - 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 = SongList() 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.SongListData = TextListData() + self.SongListView.setModel(self.SongListData) + self.SongListView.setDragEnabled(True) + +# 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.PageLayout.addWidget(self.SongListView) + self.SongListView.setDragEnabled(True) + # Signals and slots QtCore.QObject.connect(self.SearchTextButton, QtCore.SIGNAL('pressed()'), self.onSearchTextButtonClick) @@ -118,8 +152,8 @@ class SongMediaItem(MediaManagerItem): QtCore.SIGNAL('pressed()'), self.onClearTextButtonClick) QtCore.QObject.connect(self.SearchTextEdit, QtCore.SIGNAL('textChanged(const QString&)'), self.onSearchTextEditChanged) - QtCore.QObject.connect(self.SongListView, - QtCore.SIGNAL('itemPressed(QTableWidgetItem * item)'), self.onSongSelected) +# QtCore.QObject.connect(self.SongListView, +# QtCore.SIGNAL('itemPressed(QTableWidgetItem * item)'), self.onSongSelected) #define and add the context menu self.SongListView.setContextMenuPolicy(QtCore.Qt.ActionsContextMenu) self.SongListView.addAction(self.contextMenuAction(self.SongListView, @@ -148,26 +182,18 @@ class SongMediaItem(MediaManagerItem): self.SearchTypeComboBox.addItem(translate('SongMediaItem', u'Authors')) def displayResults(self, searchresults): - log.debug("_search results") - self.SongListView.clear() # clear the results - self.SongListView.horizontalHeader().setVisible(False) - self.SongListView.verticalHeader().setVisible(False) - self.SongListView.setRowCount(0) + log.debug("display results") + self.SongListData.resetStore() #log.debug("Records returned from search %s", len(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'' for author in song.authors: if author_list != u'': author_list = author_list + u', ' author_list = author_list + author.display_name - song_detail = QtGui.QTableWidgetItem( - u'%s (%s)' % (str(song.title), str(author_list))) - self.SongListView.setItem(row_count, 1, song_detail) - self.SongListView.setRowHeight(row_count, 20) + song_detail = str(u'%s (%s)' % (str(song.title), str(author_list))) + + self.SongListData.addRow(song.id,song_detail) def onClearTextButtonClick(self): """ @@ -197,9 +223,6 @@ class SongMediaItem(MediaManagerItem): #searchresults = self.songmanager.get_song_from_author(searchtext) self.displayResults(search_results) - def onSongSelected(self, item): - print item - def onSongNewClick(self): self.edit_song_form.exec_() @@ -210,13 +233,46 @@ class SongMediaItem(MediaManagerItem): self.edit_song_form.exec_() 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): - 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): - 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): - pass + service_item = ServiceItem(self.parent) + service_item.addIcon( ":/media/media_song.png") + self.generateSlideData(service_item) + self.parent.service_manager.addServiceItem(service_item) diff --git a/openlp/plugins/songs/lib/textlistdata.py b/openlp/plugins/songs/lib/textlistdata.py new file mode 100644 index 000000000..547e978f8 --- /dev/null +++ b/openlp/plugins/songs/lib/textlistdata.py @@ -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) diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index 6387094b7..adfd59297 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -49,8 +49,8 @@ class SongsPlugin(Plugin): def get_media_manager_item(self): # Create the MediaManagerItem object - self.MediaManagerItem = SongMediaItem(self, self.icon, 'Songs') - return self.MediaManagerItem + self.media_item = SongMediaItem(self, self.icon, 'Songs') + return self.media_item def add_import_menu_item(self, import_menu): self.ImportSongMenu = QtGui.QMenu(import_menu) @@ -127,3 +127,12 @@ class SongsPlugin(Plugin): if event.event_type == EventType.ThemeListChanged: log.debug(u'New Theme request received') #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()