From ecc2a8e4c7cbd5e397c7171070cf6ded5d05a3d0 Mon Sep 17 00:00:00 2001 From: Christopher Roy Bratusek Date: Tue, 21 Aug 2012 20:06:52 +0200 Subject: [PATCH] logical sorting of IOS in downloader --- ChangeLog | 2 ++ GUI/VenPri.py | 2 +- TitleIDs.py | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3712273..b3464b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * add new IOS to downloader * show available versions of selected IOS in downloader * downloading channels is currently not possible +* logical sorting of IOS in downloader (IOS4 is the first, not after IOS39) + taken from: [http://code.activestate.com/recipes/135435/] -- 0.3 -- * Updated some porject's files which still referenced wii signer diff --git a/GUI/VenPri.py b/GUI/VenPri.py index 291acf8..9170201 100644 --- a/GUI/VenPri.py +++ b/GUI/VenPri.py @@ -26,7 +26,7 @@ class MWQwad(QMainWindow, Ui_Qwad): self.setupUi(self) self.defaultversion = self.trUtf8("""(Latest)""") self.VersionlineEdit.setText(self.defaultversion) - for key in sorted(TitleIDs.TitleDict): + for key in TitleIDs.sorted_copy(TitleIDs.TitleDict): self.comboBox.addItem(key) for ios in sorted(TitleIDs.IOSdict): self.IOSversion.addItem(ios) diff --git a/TitleIDs.py b/TitleIDs.py index 0c2a6e4..5a20f97 100644 --- a/TitleIDs.py +++ b/TitleIDs.py @@ -5,6 +5,44 @@ module storing a titleid dictionary import binascii, re from PyQt4.QtCore import QT_TR_NOOP + +def sorted_copy(alist): + # inspired by Alex Martelli + # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52234 + indices = map(_generate_index, alist) + decorated = zip(indices, alist) + decorated.sort() + return [ item for index, item in decorated ] + +def _generate_index(str): + """ + Splits a string into alpha and numeric elements, which + is used as an index for sorting" + """ + # + # the index is built progressively + # using the _append function + # + index = [] + def _append(fragment, alist=index): + if fragment.isdigit(): fragment = int(fragment) + alist.append(fragment) + + # initialize loop + prev_isdigit = str[0].isdigit() + current_fragment = '' + # group a string into digit and non-digit parts + for char in str: + curr_isdigit = char.isdigit() + if curr_isdigit == prev_isdigit: + current_fragment += char + else: + _append(current_fragment) + current_fragment = char + prev_isdigit = curr_isdigit + _append(current_fragment) + return tuple(index) + TitleDict = { "BOOT2":"0000000100000001", "System Menu [JAP]":"0000000100000002",