use ICU collator on Windows systems

This commit is contained in:
M2j 2011-12-19 01:20:39 +01:00
parent cbf91465e2
commit 15449372e1
10 changed files with 42 additions and 25 deletions

View File

@ -29,7 +29,6 @@ import os
import zipfile
import shutil
import logging
import locale
from xml.etree.ElementTree import ElementTree, XML
from PyQt4 import QtCore, QtGui
@ -44,7 +43,7 @@ from openlp.core.lib.ui import UiStrings, critical_error_message_box, \
from openlp.core.theme import Theme
from openlp.core.ui import FileRenameForm, ThemeForm
from openlp.core.utils import AppLocation, delete_file, file_is_unicode, \
get_filesystem_encoding
get_filesystem_encoding, get_local_collator
log = logging.getLogger(__name__)
@ -458,7 +457,7 @@ class ThemeManager(QtGui.QWidget):
# 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)
cmp=get_local_collator)
# now process the file list of png files
for name in files:
# check to see file is in theme root directory

View File

@ -33,6 +33,7 @@ import re
import sys
import time
import urllib2
import locale
from datetime import datetime
from subprocess import Popen, PIPE
@ -45,6 +46,18 @@ if sys.platform != u'win32' and sys.platform != u'darwin':
except ImportError:
XDG_BASE_AVAILABLE = False
LOCALE_COLLATOR = locale.strcoll
if sys.platform == u'win32':
try:
import icu
try:
icu_locale = icu.Locale(locale.getlocale()[0])
LOCALE_COLLATOR = icu.Collator.createInstance(icu_locale).compare
except icu.InvalidArgsError:
pass
except ImportError:
pass
import openlp
from openlp.core.lib import Receiver, translate, check_directory_exists
@ -502,10 +515,17 @@ def get_uno_instance(resolver):
return resolver.resolve(u'uno:socket,host=localhost,port=2002;' \
+ u'urp;StarOffice.ComponentContext')
def get_local_collator(string1, string2):
"""
Returns a collator for locale aware string sorting.
"""
return LOCALE_COLLATOR(string1, string2)
from languagemanager import LanguageManager
from actions import ActionList
__all__ = [u'AppLocation', u'get_application_version', u'check_latest_version',
u'add_actions', u'get_filesystem_encoding', u'LanguageManager',
u'ActionList', u'get_web_page', u'file_is_unicode', u'get_uno_command',
u'get_uno_instance', u'delete_file', u'clean_filename']
u'get_uno_instance', u'get_local_collator', u'delete_file',
u'clean_filename']

View File

@ -30,7 +30,6 @@ The bible import functions for OpenLP
import logging
import os
import os.path
import locale
from PyQt4 import QtCore, QtGui
@ -38,7 +37,7 @@ from openlp.core.lib import Receiver, translate
from openlp.core.lib.db import delete_database
from openlp.core.lib.ui import UiStrings, critical_error_message_box
from openlp.core.ui.wizard import OpenLPWizard, WizardStrings
from openlp.core.utils import AppLocation
from openlp.core.utils import AppLocation, get_local_collator
from openlp.plugins.bibles.lib.manager import BibleFormat
from openlp.plugins.bibles.lib.db import BiblesResourcesDB, clean_filename
@ -522,7 +521,7 @@ class BibleImportForm(OpenLPWizard):
"""
self.webTranslationComboBox.clear()
bibles = self.web_bible_list[index].keys()
bibles.sort(cmp=locale.strcoll)
bibles.sort(cmp=get_local_collator)
self.webTranslationComboBox.addItems(bibles)
def onOsisBrowseButtonClicked(self):

View File

@ -26,7 +26,6 @@
###############################################################################
import logging
import locale
from PyQt4 import QtCore, QtGui
@ -36,6 +35,7 @@ from openlp.core.lib.searchedit import SearchEdit
from openlp.core.lib.ui import UiStrings, add_widget_completer, \
media_item_combo_box, critical_error_message_box, \
find_and_set_in_combo_box, build_icon
from openlp.core.utils import get_local_collator
from openlp.plugins.bibles.forms import BibleImportForm
from openlp.plugins.bibles.lib import LayoutStyle, DisplayStyle, \
VerseReferenceList, get_reference_match
@ -373,7 +373,7 @@ class BibleMediaItem(MediaManagerItem):
self.advancedSecondComboBox.addItem(u'')
# Get all bibles and sort the list.
bibles = self.plugin.manager.get_bibles().keys()
bibles.sort(cmp=locale.strcoll)
bibles.sort(cmp=get_local_collator)
# Load the bibles into the combo boxes.
for bible in bibles:
if bible:
@ -481,7 +481,7 @@ class BibleMediaItem(MediaManagerItem):
book_data_temp.append(book)
book_data = book_data_temp
books = [book.name + u' ' for book in book_data]
books.sort(cmp=locale.strcoll)
books.sort(cmp=get_local_collator)
add_widget_completer(books, self.quickSearchEdit)
def onQuickVersionComboBox(self):

View File

@ -26,7 +26,6 @@
###############################################################################
import logging
import locale
from PyQt4 import QtCore, QtGui
from sqlalchemy.sql import or_, func
@ -35,6 +34,7 @@ from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \
check_item_selected, translate
from openlp.core.lib.searchedit import SearchEdit
from openlp.core.lib.ui import UiStrings
from oprnlp.core.utils import get_local_collator
from openlp.plugins.custom.forms import EditCustomForm
from openlp.plugins.custom.lib import CustomXMLParser
from openlp.plugins.custom.lib.db import CustomSlide
@ -137,7 +137,7 @@ class CustomMediaItem(MediaManagerItem):
# Sort the customs by its title considering language specific
# characters. lower() is needed for windows!
custom_slides.sort(
cmp=locale.strcoll, key=lambda custom: custom.title.lower())
cmp=get_local_collator, key=lambda custom: custom.title.lower())
for custom_slide in custom_slides:
custom_name = QtGui.QListWidgetItem(custom_slide.title)
custom_name.setData(

View File

@ -27,7 +27,6 @@
import logging
import os
import locale
from PyQt4 import QtCore, QtGui
@ -35,7 +34,8 @@ from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, \
SettingsManager, translate, check_item_selected, check_directory_exists, \
Receiver, create_thumb, validate_thumb
from openlp.core.lib.ui import UiStrings, critical_error_message_box
from openlp.core.utils import AppLocation, delete_file, get_images_filter
from openlp.core.utils import AppLocation, delete_file, get_images_filter, \
get_local_collator
log = logging.getLogger(__name__)
@ -120,7 +120,7 @@ class ImageMediaItem(MediaManagerItem):
self.plugin.formparent.displayProgressBar(len(images))
# Sort the themes by its filename considering language specific
# characters. lower() is needed for windows!
images.sort(cmp=locale.strcoll,
images.sort(cmp=get_local_collator,
key=lambda filename: os.path.split(unicode(filename))[1].lower())
for imageFile in images:
if not initialLoad:

View File

@ -27,7 +27,6 @@
import logging
import os
import locale
from PyQt4 import QtCore, QtGui
@ -37,6 +36,7 @@ from openlp.core.lib import MediaManagerItem, build_icon, ItemCapabilities, \
from openlp.core.lib.ui import UiStrings, critical_error_message_box, \
media_item_combo_box
from openlp.core.ui import Controller, Display
from openlp.core.utils import get_local_collator
log = logging.getLogger(__name__)
@ -278,7 +278,7 @@ class MediaMediaItem(MediaManagerItem):
def loadList(self, media):
# Sort the themes by its filename considering language specific
# characters. lower() is needed for windows!
media.sort(cmp=locale.strcoll,
media.sort(cmp=get_local_collator,
key=lambda filename: os.path.split(unicode(filename))[1].lower())
for track in media:
track_info = QtCore.QFileInfo(track)
@ -298,7 +298,7 @@ class MediaMediaItem(MediaManagerItem):
def getList(self, type=MediaType.Audio):
media = SettingsManager.load_list(self.settingsSection, u'media')
media.sort(cmp=locale.strcoll,
media.sort(cmp=get_local_collator,
key=lambda filename: os.path.split(unicode(filename))[1].lower())
ext = []
if type == MediaType.Audio:

View File

@ -27,7 +27,6 @@
import logging
import os
import locale
from PyQt4 import QtCore, QtGui
@ -36,6 +35,7 @@ from openlp.core.lib import MediaManagerItem, build_icon, SettingsManager, \
validate_thumb
from openlp.core.lib.ui import UiStrings, critical_error_message_box, \
media_item_combo_box
from openlp.core.utils import get_local_collator
from openlp.plugins.presentations.lib import MessageListener
log = logging.getLogger(__name__)
@ -168,7 +168,7 @@ class PresentationMediaItem(MediaManagerItem):
self.plugin.formparent.displayProgressBar(len(files))
# Sort the themes by its filename considering language specific
# characters. lower() is needed for windows!
files.sort(cmp=locale.strcoll,
files.sort(cmp=get_local_collator,
key=lambda filename: os.path.split(unicode(filename))[1].lower())
for file in files:
if not initialLoad:

View File

@ -28,7 +28,6 @@
The :mod:`songexportform` module provides the wizard for exporting songs to the
OpenLyrics format.
"""
import locale
import logging
from PyQt4 import QtCore, QtGui
@ -36,6 +35,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import build_icon, Receiver, SettingsManager, translate
from openlp.core.lib.ui import UiStrings, critical_error_message_box
from openlp.core.ui.wizard import OpenLPWizard, WizardStrings
from openlp.core.utils import get_local_collator
from openlp.plugins.songs.lib.db import Song
from openlp.plugins.songs.lib.openlyricsexport import OpenLyricsExport
@ -250,7 +250,7 @@ class SongExportForm(OpenLPWizard):
# Load the list of songs.
Receiver.send_message(u'cursor_busy')
songs = self.plugin.manager.get_all_objects(Song)
songs.sort(cmp=locale.strcoll, key=lambda song: song.title.lower())
songs.sort(cmp=get_local_collator, key=lambda song: song.title.lower())
for song in songs:
# No need to export temporary songs.
if song.temporary:

View File

@ -26,7 +26,6 @@
###############################################################################
import logging
import locale
import re
import os
import shutil
@ -39,7 +38,7 @@ from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \
from openlp.core.lib.searchedit import SearchEdit
from openlp.core.lib.ui import UiStrings, context_menu_action, \
context_menu_separator
from openlp.core.utils import AppLocation
from openlp.core.utils import AppLocation, get_local_collator
from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \
SongImportForm, SongExportForm
from openlp.plugins.songs.lib import OpenLyrics, SongXML, VerseType, \
@ -268,7 +267,7 @@ class SongMediaItem(MediaManagerItem):
# 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())
cmp=get_local_collator, key=lambda song: song.title.lower())
for song in searchresults:
# Do not display temporary songs
if song.temporary: