Package: playonlinux
Version: 3.7.6-1
Tags: patch

it's been bugging me for months that the version numbers in the
Available Wine Versions list box are ASCII-sorted rather than
natural-sorted, so i hacked in a natural sort i found on the net at
http://code.activestate.com/recipes/285264/#c6

It was written by Paul Clinch, and the license is the PSF Python
License, http://www.python.org/psf/license/ (GPL compatible)


this sorts version numbers properly (e.g. so 0.9.7 sorts lower than
0.9.10) and ensures that the latest versions are always at the top of
the list, so you don't have to scroll to the middle of the long list
just to find out if there's a new version of wine available.

(there may be other places in the code where a natural sort would be
more useful than an ascii sort. don't know, haven't looked.)


the playonlinux.com web site doesn't seem to have a contact email
address, so please also submit upstream.

thanks,

craig

-- 
craig sanders <c...@taz.net.au>
--- wine_versions.py.orig	2010-08-15 10:09:41.694307235 +1000
+++ wine_versions.py	2010-08-15 10:40:56.040327576 +1000
@@ -27,6 +27,35 @@
 timeout = 2
 socket.setdefaulttimeout(timeout)
 
+def keynat(string):
+    r'''A natural sort helper function for sort() and sorted()
+    without using regular expressions or exceptions.
+
+    >>> items = ('Z', 'a', '10th', '1st', '9')
+    >>> sorted(items)
+    ['10th', '1st', '9', 'Z', 'a']
+    >>> sorted(items, key=keynat)
+    ['1st', '9', '10th', 'a', 'Z']    
+
+    Borrowed from http://code.activestate.com/recipes/285264/#c6
+    by paul clinch.  
+
+    License is the PSF Python License, http://www.python.org/psf/license/ (GPL compatible)
+    '''
+    it = type(1)
+    r = []
+    for c in string:
+        if c.isdigit():
+            d = int(c)
+            if r and type( r[-1] ) == it: 
+                r[-1] = r[-1] * 10 + d
+            else: 
+                r.append(d)
+        else:
+            r.append(c.lower())
+    return r
+
+
 class getVersions(threading.Thread):
   def __init__(self):
 	threading.Thread.__init__(self)
@@ -58,6 +87,7 @@
 					if(not os.path.exists(Variables.playonlinux_rep+"/WineVersions/"+version)):
 						self.versions_.append(version)
 					self.i += 1	
+				self.versions_.sort(key=keynat)
 				self.versions_.reverse()
 				self.versions = self.versions_[:]
 
@@ -316,7 +346,7 @@
 
 	root2 = self.onglets.list_ver_installed.AddRoot("")
 	installed_versions = os.listdir(Variables.playonlinux_rep+"/WineVersions/")
-	installed_versions.sort()
+	installed_versions.sort(key=keynat)
 	installed_versions.reverse()
 	self.i = 0
 	self.j = 0

Reply via email to