Make quodlibet to use LC_LOCATE locale to sort From: RĂ©mi Vanicat --- browsers/albums.py | 6 +++--- browsers/paned.py | 4 ++-- qltk/information.py | 8 ++++---- qltk/songlist.py | 4 ++-- util/__init__.py | 11 +++++++++++ 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/browsers/albums.py b/browsers/albums.py index 61d969f..ad25f27 100644 --- a/browsers/albums.py +++ b/browsers/albums.py @@ -382,7 +382,7 @@ class AlbumList(Browser, gtk.VBox, util.InstanceTracker): if (a1 and a2) is None: return cmp(a1, a2) elif not a1.title: return 1 elif not a2.title: return -1 - else: return cmp(a1.key, a2.key) + else: return util.strcoll(a1.key, a2.key) def __compare_artist(self, model, i1, i2): a1, a2 = model[i1][0], model[i2][0] @@ -391,8 +391,8 @@ class AlbumList(Browser, gtk.VBox, util.InstanceTracker): elif not a2.title: return -1 elif not a1.people and a2.people: return 1 elif not a2.people and a1.people: return -1 - else: return (cmp(a1.people and a1.people[0], - a2.people and a2.people[0]) or + else: return (util.strcoll(a1.people and a1.people[0], + a2.people and a2.people[0]) or cmp(a1.date or "ZZZZ", a2.date or "ZZZZ") or cmp(a1.key, a2.key)) diff --git a/browsers/paned.py b/browsers/paned.py index 01dd660..0907f1e 100644 --- a/browsers/paned.py +++ b/browsers/paned.py @@ -251,7 +251,7 @@ class PanedBrowser(gtk.VBox, Browser, util.InstanceTracker): new[val].add(song) if new: - keys = sorted(new.keys()) + keys = sorted(new.keys(),key=util.strxfrm) if keys[0] == "": unknown = new[""] keys.pop(0) @@ -260,7 +260,7 @@ class PanedBrowser(gtk.VBox, Browser, util.InstanceTracker): if row[0][0] == "<": continue elif not keys: break - if util.unescape(row[0]) > keys[0]: + if util.strcoll(util.unescape(row[0]),keys[0]) > 0: key = keys.pop(0) model.insert_before( row.iter, row=[util.escape(key), new[key]]) diff --git a/qltk/information.py b/qltk/information.py index 6e8a80c..17e113d 100644 --- a/qltk/information.py +++ b/qltk/information.py @@ -349,8 +349,8 @@ class OneAlbum(qltk.Notebook): artists.update(song.list("artist")) performers.update(song.list("performer")) - artists = sorted(artists) - performers = sorted(performers) + artists = sorted(artists,key=util.strxfrm) + performers = sorted(performers,key=util.strxfrm) if artists: if len(artists) == 1: title = _("artist") @@ -485,7 +485,7 @@ class ManySongs(qltk.Notebook): for song in songs: if "artist" in song: artists.update(song.list("artist")) else: none += 1 - artists = sorted(artists) + artists = sorted(artists,key=util.strxfrm) num_artists = len(artists) if none: artists.append(ngettext("%d song with no artist", @@ -501,7 +501,7 @@ class ManySongs(qltk.Notebook): for song in songs: if "album" in song: albums.update(song.list("album")) else: none += 1 - albums = sorted(albums) + albums = sorted(albums,key=util.strxfrm) num_albums = len(albums) if none: albums.append(ngettext("%d song with no album", diff --git a/qltk/songlist.py b/qltk/songlist.py index d975f15..572f7de 100644 --- a/qltk/songlist.py +++ b/qltk/songlist.py @@ -733,9 +733,9 @@ class SongList(AllTreeView, util.InstanceTracker): if callable(tag): # A pattern is currently selected. - sort_func = lambda song: (tag(song), song.sort_key, song) + sort_func = lambda song: (util.strxfrm(tag(song)), song.sort_key, song) else: - sort_func = lambda song: (song(tag), song.sort_key, song) + sort_func = lambda song: (util.strxfrm(song(tag)), song.sort_key, song) songs.sort(key=sort_func, reverse=reverse) else: self.set_sort_by(None, refresh=False) diff --git a/util/__init__.py b/util/__init__.py index a9b5b33..7cd7d46 100644 --- a/util/__init__.py +++ b/util/__init__.py @@ -229,6 +229,17 @@ def to(string, frm="utf-8"): else: return string.decode(frm).encode(ENCODING, "replace") +def strcoll(string1,string2): + """compare two unicode string according to LC_COLLATE + """ + return locale.strcoll(to(string1),to(string2)) + +def strxfrm(string): + """transform a string with strxfrm, + return the argument unchanded when there is an AttributeError""" + try: return locale.strxfrm(to(string)) + except AttributeError: return string + def mtime(filename): """Return the mtime of a file, or 0 if an error occurs.""" try: return os.path.getmtime(filename)