From 3359726be2164e35cf78bbd34beb4538fbe6430f Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 20 May 2011 17:14:10 +0200 Subject: [PATCH 1/7] improved media item sorting --- openlp/plugins/custom/lib/mediaitem.py | 5 +++++ openlp/plugins/songs/lib/mediaitem.py | 11 +++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index 66b1c3675..72db3bfa4 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -25,6 +25,8 @@ ############################################################################### import logging +import locale +import operator from PyQt4 import QtCore, QtGui from sqlalchemy.sql import or_, func @@ -135,6 +137,9 @@ class CustomMediaItem(MediaManagerItem): def loadList(self, list): self.listView.clear() + # Sort the customs by its title considering language specific + # characters. + list.sort(cmp=locale.strcoll, key=operator.attrgetter('title')) for customSlide in list: custom_name = QtGui.QListWidgetItem(customSlide.title) custom_name.setData( diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 5f961b2f2..19a2924b3 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -26,6 +26,7 @@ import logging import locale +import operator from PyQt4 import QtCore, QtGui from sqlalchemy.sql import or_ @@ -229,7 +230,8 @@ class SongMediaItem(MediaManagerItem): def displayResultsSong(self, searchresults): log.debug(u'display results Song') self.listView.clear() - searchresults.sort(cmp=self.collateSongTitles) + # Sort the songs by its title considering language specific characters. + searchresults.sort(cmp=locale.strcoll, key=operator.attrgetter('title')) for song in searchresults: author_list = [author.display_name for author in song.authors] song_title = unicode(song.title) @@ -472,13 +474,6 @@ class SongMediaItem(MediaManagerItem): Receiver.send_message(u'service_item_update', u'%s:%s' % (editId, item._uuid)) - def collateSongTitles(self, song_1, song_2): - """ - Locale aware collation of song titles - """ - return locale.strcoll(unicode(song_1.title.lower()), - unicode(song_2.title.lower())) - def search(self, string): """ Search for some songs From 5a7aa2fb9fde71785dfbee7641f9c7a1ad6b2b70 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 20 May 2011 17:18:57 +0200 Subject: [PATCH 2/7] do not override list --- openlp/plugins/custom/lib/mediaitem.py | 10 +++++----- openlp/plugins/presentations/lib/mediaitem.py | 10 ++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index 72db3bfa4..f22771eff 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -135,15 +135,15 @@ class CustomMediaItem(MediaManagerItem): self.onPreviewClick() self.onRemoteEditClear() - def loadList(self, list): + def loadList(self, custom_slides): self.listView.clear() # Sort the customs by its title considering language specific # characters. - list.sort(cmp=locale.strcoll, key=operator.attrgetter('title')) - for customSlide in list: - custom_name = QtGui.QListWidgetItem(customSlide.title) + custom_slides.sort(cmp=locale.strcoll, key=operator.attrgetter('title')) + for custom_slide in custom_slides: + custom_name = QtGui.QListWidgetItem(custom_slide.title) custom_name.setData( - QtCore.Qt.UserRole, QtCore.QVariant(customSlide.id)) + QtCore.Qt.UserRole, QtCore.QVariant(custom_slide.id)) self.listView.addItem(custom_name) def onNewClick(self): diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 7660c9099..5cc6f1fe1 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -149,20 +149,18 @@ class PresentationMediaItem(MediaManagerItem): else: self.presentationWidget.hide() - def loadList(self, list, initialLoad=False): + def loadList(self, files, initialLoad=False): """ Add presentations into the media manager This is called both on initial load of the plugin to populate with existing files, and when the user adds new files via the media manager """ currlist = self.getFileList() - titles = [] - for file in currlist: - titles.append(os.path.split(file)[1]) + titles = [os.path.split(file)[1] for file in currlist] Receiver.send_message(u'cursor_busy') if not initialLoad: - self.parent.formparent.displayProgressBar(len(list)) - for file in list: + self.parent.formparent.displayProgressBar(len(files)) + for file in files: if not initialLoad: self.parent.formparent.incrementProgressBar() if currlist.count(file) > 0: From f753070f53bebc8f85d877ad666f4db0be9ca9c6 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 20 May 2011 19:06:38 +0200 Subject: [PATCH 3/7] fix for windows --- openlp/plugins/custom/lib/mediaitem.py | 3 ++- openlp/plugins/songs/lib/mediaitem.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index f22771eff..064a558ba 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -139,7 +139,8 @@ class CustomMediaItem(MediaManagerItem): self.listView.clear() # Sort the customs by its title considering language specific # characters. - custom_slides.sort(cmp=locale.strcoll, key=operator.attrgetter('title')) + custom_slides.sort( + cmp=locale.strcoll, key=operator.attrgetter('title').lower()) for custom_slide in custom_slides: custom_name = QtGui.QListWidgetItem(custom_slide.title) custom_name.setData( diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 19a2924b3..eb65fa775 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -231,7 +231,8 @@ class SongMediaItem(MediaManagerItem): log.debug(u'display results Song') self.listView.clear() # Sort the songs by its title considering language specific characters. - searchresults.sort(cmp=locale.strcoll, key=operator.attrgetter('title')) + searchresults.sort( + cmp=locale.strcoll, key=operator.attrgetter('title').lower()) for song in searchresults: author_list = [author.display_name for author in song.authors] song_title = unicode(song.title) From 594caf0a193a1e3e4ed80c856363b28681bda1c4 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 23 May 2011 12:34:42 +0200 Subject: [PATCH 4/7] fix for windows --- openlp/plugins/custom/lib/mediaitem.py | 2 +- openlp/plugins/songs/lib/mediaitem.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index 064a558ba..e56200ee7 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -140,7 +140,7 @@ class CustomMediaItem(MediaManagerItem): # Sort the customs by its title considering language specific # characters. custom_slides.sort( - cmp=locale.strcoll, key=operator.attrgetter('title').lower()) + cmp=locale.strcoll, key=lambda custom: custom.title.lower()) for custom_slide in custom_slides: custom_name = QtGui.QListWidgetItem(custom_slide.title) custom_name.setData( diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index eb65fa775..cbdb20462 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -232,7 +232,7 @@ class SongMediaItem(MediaManagerItem): self.listView.clear() # Sort the songs by its title considering language specific characters. searchresults.sort( - cmp=locale.strcoll, key=operator.attrgetter('title').lower()) + cmp=locale.strcoll, key=lambda song: song.title.lower()) for song in searchresults: author_list = [author.display_name for author in song.authors] song_title = unicode(song.title) From 73293c2985daeead5ac3e5ec61d3709d1fd019d8 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 23 May 2011 13:14:05 +0200 Subject: [PATCH 5/7] removed imports --- openlp/plugins/custom/lib/mediaitem.py | 1 - openlp/plugins/songs/lib/mediaitem.py | 1 - 2 files changed, 2 deletions(-) diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index e56200ee7..d19f462d7 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -26,7 +26,6 @@ import logging import locale -import operator from PyQt4 import QtCore, QtGui from sqlalchemy.sql import or_, func diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index cbdb20462..0dabeb766 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -26,7 +26,6 @@ import logging import locale -import operator from PyQt4 import QtCore, QtGui from sqlalchemy.sql import or_ From ce5c354e06c587df7c0b04ab68ff2dddf0bf2a66 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 23 May 2011 13:49:14 +0200 Subject: [PATCH 6/7] fix for head --- openlp/plugins/custom/lib/mediaitem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index 054a75424..e137d69e3 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -146,7 +146,7 @@ class CustomMediaItem(MediaManagerItem): QtCore.Qt.UserRole, QtCore.QVariant(custom_slide.id)) self.listView.addItem(custom_name) # Auto-select the item if name has been set - if customSlide.title == self.autoSelectItem : + if custom_slide.title == self.autoSelectItem: self.listView.setCurrentItem(custom_name) def onNewClick(self): From 5473d3c817febdad4e622c7d63df61efbff00623 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 24 May 2011 07:23:28 +0200 Subject: [PATCH 7/7] added windows comment --- openlp/plugins/custom/lib/mediaitem.py | 2 +- openlp/plugins/songs/lib/mediaitem.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index e137d69e3..85e6e51f2 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -137,7 +137,7 @@ class CustomMediaItem(MediaManagerItem): def loadList(self, custom_slides): self.listView.clear() # Sort the customs by its title considering language specific - # characters. + # characters. lower() is needed for windows! custom_slides.sort( cmp=locale.strcoll, key=lambda custom: custom.title.lower()) for custom_slide in custom_slides: diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 45827da0b..23632ca58 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -230,6 +230,7 @@ class SongMediaItem(MediaManagerItem): log.debug(u'display results Song') self.listView.clear() # Sort the songs by its title considering language specific characters. + # lower() is needed for windows! searchresults.sort( cmp=locale.strcoll, key=lambda song: song.title.lower()) for song in searchresults: