ontv r442 - trunk/ontv
- From: johans svn gnome org
- To: svn-commits-list gnome org
- Subject: ontv r442 - trunk/ontv
- Date: Thu, 31 Jan 2008 09:58:47 +0000 (GMT)
Author: johans
Date: Thu Jan 31 09:58:47 2008
New Revision: 442
URL: http://svn.gnome.org/viewvc/ontv?rev=442&view=rev
Log:
Use natural sorting in the channel tab. Patch from John Daiker <daikerjohn gmail com>.
Modified:
trunk/ontv/PreferencesDialog.py
trunk/ontv/Utils.py
Modified: trunk/ontv/PreferencesDialog.py
==============================================================================
--- trunk/ontv/PreferencesDialog.py (original)
+++ trunk/ontv/PreferencesDialog.py Thu Jan 31 09:58:47 2008
@@ -157,8 +157,8 @@
channel = model.get_value(iter1, 0)
other_channel = model.get_value(iter2, 0)
if object:
- return cmp(channel.name.lower(), other_channel.name.lower())
- return cmp(channel.lower(), other_channel.lower())
+ return Utils.natcmp(channel.name.lower(), other_channel.name.lower())
+ return Utils.natcmp(channel.lower(), other_channel.lower())
def __channels_treeview_toggled(self, cell, path, model):
channel = model[path][0]
Modified: trunk/ontv/Utils.py
==============================================================================
--- trunk/ontv/Utils.py (original)
+++ trunk/ontv/Utils.py Thu Jan 31 09:58:47 2008
@@ -19,6 +19,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import os.path
+import re
def is_in_path(file):
paths = ["/usr/bin", "/usr/local/bin"]
@@ -26,3 +27,32 @@
if os.path.isfile(os.path.join(path_dir, file)):
return True
return False
+
+
+def try_int(i):
+ # Convert to an interger if we can
+ try: return int(i)
+ except: return i
+
+def natsort_key(s):
+ # Used to get a tuple sorted
+ return map(try_int, re.findall(r'(\d+|\D+)', s))
+
+def natcmp(a, b):
+ # Natural comparison - case sensitive
+ return cmp(natsort_key(a), natsort_key(b))
+
+def natcasecmp(a, b):
+ # Natural comparison - case insensitive
+ return natcmp(a.lower(), b.lower())
+
+def natsort(seq, cmp=natcmp):
+ # Inplace natural sorting
+ seq.sort(cmp)
+
+def natsorted(seq, cmp=natcmp):
+ # Returns a copy of seq, naturally sorted
+ import copy
+ temp = copy.copy(seq)
+ natsort(temp, cmp)
+ return temp
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]