From 06d561f9fc3c80053950f3732c03ab932ed9f778 Mon Sep 17 00:00:00 2001 From: M2j Date: Mon, 23 May 2011 22:42:07 +0200 Subject: [PATCH 1/2] localized string sorting --- openlp/core/ui/thememanager.py | 3 ++- openlp/plugins/bibles/forms/bibleimportform.py | 5 +++-- openlp/plugins/bibles/lib/mediaitem.py | 5 +++-- openlp/plugins/songs/lib/mediaitem.py | 10 ++-------- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 190939ab9..659ee4137 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -28,6 +28,7 @@ import os import zipfile import shutil import logging +import locale from xml.etree.ElementTree import ElementTree, XML from PyQt4 import QtCore, QtGui @@ -461,7 +462,7 @@ class ThemeManager(QtGui.QWidget): QtCore.QVariant(theme.theme_name)) self.configUpdated() files = SettingsManager.get_files(self.settingsSection, u'.png') - files.sort() + files.sort(key=lambda filename: unicode(filename), cmp=locale.strcoll) # now process the file list of png files for name in files: # check to see file is in theme root directory diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py index 439724b66..10815af46 100644 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ b/openlp/plugins/bibles/forms/bibleimportform.py @@ -30,6 +30,7 @@ import csv import logging import os import os.path +import locale from PyQt4 import QtCore, QtGui @@ -531,7 +532,7 @@ class BibleImportForm(OpenLPWizard): """ self.webTranslationComboBox.clear() bibles = self.web_bible_list[index].keys() - bibles.sort() + bibles.sort(cmp=locale.strcoll) self.webTranslationComboBox.addItems(bibles) def onOsisBrowseButtonClicked(self): @@ -765,4 +766,4 @@ class BibleImportForm(OpenLPWizard): self.progressLabel.setText(translate( 'BiblesPlugin.ImportWizardForm', 'Your Bible import failed.')) del self.manager.db_cache[importer.name] - delete_database(self.plugin.settingsSection, importer.file) \ No newline at end of file + delete_database(self.plugin.settingsSection, importer.file) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index 9a9e3f9ec..2e21b9172 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -25,6 +25,7 @@ ############################################################################### import logging +import locale from PyQt4 import QtCore, QtGui @@ -358,7 +359,7 @@ class BibleMediaItem(MediaManagerItem): self.advancedSecondComboBox.addItem(u'') # Get all bibles and sort the list. bibles = self.parent.manager.get_bibles().keys() - bibles.sort() + bibles.sort(cmp=locale.strcoll) # Load the bibles into the combo boxes. for bible in bibles: if bible: @@ -442,7 +443,7 @@ class BibleMediaItem(MediaManagerItem): if bible: book_data = bibles[bible].get_books() books = [book.name + u' ' for book in book_data] - books.sort() + books.sort(cmp=locale.strcoll) add_widget_completer(books, self.quickSearchEdit) def onImportClick(self): diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 78c7825be..f4d4ee607 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -229,7 +229,8 @@ class SongMediaItem(MediaManagerItem): def displayResultsSong(self, searchresults): log.debug(u'display results Song') self.listView.clear() - searchresults.sort(cmp=self.collateSongTitles) + searchresults.sort(key=lambda song: unicode(song.title), + cmp=locale.strcoll) for song in searchresults: author_list = [author.display_name for author in song.authors] song_title = unicode(song.title) @@ -475,13 +476,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 6f0bdad784c4c50a05dd25586671ec89eef41ba4 Mon Sep 17 00:00:00 2001 From: M2j Date: Wed, 25 May 2011 20:47:13 +0200 Subject: [PATCH 2/2] all lower() for theme sorting to consider Windows --- openlp/core/ui/thememanager.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index c432b0706..38a00f1a1 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -463,7 +463,10 @@ class ThemeManager(QtGui.QWidget): QtCore.QVariant(theme.theme_name)) self.configUpdated() files = SettingsManager.get_files(self.settingsSection, u'.png') - files.sort(key=lambda filename: unicode(filename), cmp=locale.strcoll) + # Sort the themes by its name considering language specific characters. + # lower() is needed for windows! + files.sort(key=lambda filename: unicode(filename).lower(), + cmp=locale.strcoll) # now process the file list of png files for name in files: # check to see file is in theme root directory