diff --git a/openlp/core/lib/songxmlhandler.py b/openlp/core/lib/songxmlhandler.py index e47908d7e..14ed4ea0b 100644 --- a/openlp/core/lib/songxmlhandler.py +++ b/openlp/core/lib/songxmlhandler.py @@ -29,6 +29,7 @@ from xml.etree.ElementTree import ElementTree, XML, dump """ +import logging from xml.dom.minidom import Document from xml.etree.ElementTree import ElementTree, XML, dump @@ -70,11 +71,20 @@ class SongXMLBuilder(): def extract_xml(self): # Print our newly created XML - return self.song_xml.toxml() + return self.song_xml.toxml(u'utf-8') class SongXMLParser(): + global log + log = logging.getLogger(u'SongXMLParser') + log.info(u'SongXMLParser Loaded') + def __init__(self, xml): - self.song_xml = ElementTree(element=XML(xml)) + #print xml + try: + self.song_xml = ElementTree(element=XML(xml)) + except: + #print "invalid xml ", xml + log.debug(u'invalid xml %s', xml) def get_verses(self): #return a list of verse's and attributes diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 889a0397b..d6fa68cba 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -21,14 +21,11 @@ import logging import os from PyQt4 import QtCore, QtGui - from openlp.core.lib import OpenLPToolbar, translate class SlideData(QtCore.QAbstractListModel): """ - Tree of items for an order of Theme. - Includes methods for reading and writing the contents to an OOS file - Root contains a list of ThemeItems + List of frames to be displayed on the list and the main display. """ global log log = logging.getLogger(u'SlideData') @@ -98,6 +95,24 @@ class SlideData(QtCore.QAbstractListModel): filelist = [item[3] for item in self.items]; return filelist +class SlideList(QtGui.QListView): + + def __init__(self,parent=None,name=None): + QtGui.QListView.__init__(self,parent.Controller) + self.parent = parent + + def keyPressEvent(self, event): + if type(event) == QtGui.QKeyEvent: + #here accept the event and do something + if event.key() == QtCore.Qt.Key_PageUp: + self.parent.onSlideSelectedPrevious() + event.accept() + elif event.key() == QtCore.Qt.Key_PageDown: + self.parent.onSlideSelectedNext() + event.accept() + event.ignore() + else: + event.ignore() class SlideController(QtGui.QWidget): """ @@ -132,7 +147,7 @@ class SlideController(QtGui.QWidget): self.ControllerLayout.setSpacing(0) self.ControllerLayout.setMargin(0) # Controller list view - self.PreviewListView = QtGui.QListView(self.Controller) + self.PreviewListView = SlideList(self) self.PreviewListView.setUniformItemSizes(True) self.PreviewListView.setIconSize(QtCore.QSize(250, 190)) self.PreviewListData = SlideData() @@ -210,6 +225,11 @@ class SlideController(QtGui.QWidget): QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSlideSelected) QtCore.QObject.connect(self.PreviewListView, QtCore.SIGNAL(u'activated(QModelIndex)'), self.onSlideSelected) + QtCore.QObject.connect(self.PreviewListView, + QtCore.SIGNAL(u'entered(QModelIndex)'), self.onTest) + + def onTest(self , item): + print "found", item def onSlideSelectedFirst(self): """ diff --git a/openlp/plugins/songs/lib/manager.py b/openlp/plugins/songs/lib/manager.py index c21721fd1..c4c7a1fa6 100644 --- a/openlp/plugins/songs/lib/manager.py +++ b/openlp/plugins/songs/lib/manager.py @@ -60,8 +60,8 @@ class SongManager(): metadata.create_all() log.debug(u'Song Initialised') - def process_dialog(self, dialogobject): - self.dialogobject = dialogobject +# def process_dialog(self, dialogobject): +# self.dialogobject = dialogobject def get_songs(self): """ @@ -81,6 +81,12 @@ class SongManager(): """ return self.session.query(Song).filter(Song.search_lyrics.like(u'%' + keywords + u'%')).order_by(Song.search_lyrics.asc()).all() + def get_song_from_author(self, keywords): + """ + Searches the song authors for keywords. + """ + return self.session.query(Author).filter(Author.display_name.like(u'%' + keywords + u'%')).order_by(Author.display_name.asc()).all() + def get_song(self, id=None): """ Returns the details of a song diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 08704501a..5d9455481 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -160,8 +160,25 @@ class SongMediaItem(MediaManagerItem): self.SearchTypeComboBox.addItem(translate(u'SongMediaItem', u'Lyrics')) self.SearchTypeComboBox.addItem(translate(u'SongMediaItem', u'Authors')) - def displayResults(self, searchresults): - log.debug(u'display results') + def onSearchTextButtonClick(self): + search_keywords = unicode(self.SearchTextEdit.displayText()) + search_results = [] + search_type = self.SearchTypeComboBox.currentIndex() + if search_type == 0: + log.debug(u'Titles Search') + search_results = self.parent.songmanager.search_song_title(search_keywords) + self.displayResultsSong(search_results) + elif search_type == 1: + log.debug(u'Lyrics Search') + search_results = self.parent.songmanager.search_song_lyrics(search_keywords) + self.displayResultsSong(search_results) + elif search_type == 2: + log.debug(u'Authors Search') + search_results = self.parent.songmanager.get_song_from_author(search_keywords) + self.displayResultsAuthor(search_results) + + def displayResultsSong(self, searchresults): + log.debug(u'display results Song') self.SongListWidget.clear() #log.debug(u'Records returned from search %s", len(searchresults)) for song in searchresults: @@ -175,6 +192,16 @@ class SongMediaItem(MediaManagerItem): song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id)) self.SongListWidget.addItem(song_name) + def displayResultsAuthor(self, searchresults): + log.debug(u'display results Author') + self.SongListWidget.clear() + for author in searchresults: + for song in author.songs: + song_detail = unicode(u'%s (%s)' % (unicode(author.display_name), unicode(song.title))) + song_name = QtGui.QListWidgetItem(song_detail) + song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song.id)) + self.SongListWidget.addItem(song_name) + def onClearTextButtonClick(self): """ Clear the search text. @@ -188,21 +215,6 @@ class SongMediaItem(MediaManagerItem): if len(text) > search_length: self.onSearchTextButtonClick() - def onSearchTextButtonClick(self): - search_keywords = unicode(self.SearchTextEdit.displayText()) - search_results = [] - search_type = self.SearchTypeComboBox.currentIndex() - if search_type == 0: - log.debug(u'Titles Search') - search_results = self.parent.songmanager.search_song_title(search_keywords) - elif search_type == 1: - log.debug(u'Lyrics Search') - search_results = self.parent.songmanager.search_song_lyrics(search_keywords) - elif search_type == 2: - log.debug(u'Authors Search') - #searchresults = self.songmanager.get_song_from_author(searchtext) - self.displayResults(search_results) - def onSongNewClick(self): self.edit_song_form.newSong() self.edit_song_form.exec_() diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index bc099b928..eb3d2588f 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -103,7 +103,7 @@ class SongsPlugin(Plugin): QtCore.QObject.connect(self.ExportOpenSongItem, QtCore.SIGNAL(u'triggered()'), self.onExportOpenSongItemClicked) def initialise(self): - self.media_item.displayResults(self.songmanager.get_songs()) + self.media_item.displayResultsSong(self.songmanager.get_songs()) def onImportOpenlp1ItemClick(self): self.openlp_import_form.show() @@ -136,4 +136,4 @@ class SongsPlugin(Plugin): self.media_item.onSongLiveClick() if event.event_type == EventType.LoadSongList : log.debug(u'Load Load Song List Item received') - self.media_item.displayResults(self.songmanager.get_songs()) \ No newline at end of file + self.media_item.displayResults(self.songmanager.get_songs())