logical sorting of IOS in downloader

This commit is contained in:
Christopher Roy Bratusek 2012-08-21 20:06:52 +02:00
parent 9b64027fd7
commit ecc2a8e4c7
3 changed files with 41 additions and 1 deletions

View File

@ -2,6 +2,8 @@
* add new IOS to downloader * add new IOS to downloader
* show available versions of selected IOS in downloader * show available versions of selected IOS in downloader
* downloading channels is currently not possible * 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 -- -- 0.3 --
* Updated some porject's files which still referenced wii signer * Updated some porject's files which still referenced wii signer

View File

@ -26,7 +26,7 @@ class MWQwad(QMainWindow, Ui_Qwad):
self.setupUi(self) self.setupUi(self)
self.defaultversion = self.trUtf8("""(Latest)""") self.defaultversion = self.trUtf8("""(Latest)""")
self.VersionlineEdit.setText(self.defaultversion) self.VersionlineEdit.setText(self.defaultversion)
for key in sorted(TitleIDs.TitleDict): for key in TitleIDs.sorted_copy(TitleIDs.TitleDict):
self.comboBox.addItem(key) self.comboBox.addItem(key)
for ios in sorted(TitleIDs.IOSdict): for ios in sorted(TitleIDs.IOSdict):
self.IOSversion.addItem(ios) self.IOSversion.addItem(ios)

View File

@ -5,6 +5,44 @@ module storing a titleid dictionary
import binascii, re import binascii, re
from PyQt4.QtCore import QT_TR_NOOP 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 = { TitleDict = {
"BOOT2":"0000000100000001", "BOOT2":"0000000100000001",
"System Menu [JAP]":"0000000100000002", "System Menu [JAP]":"0000000100000002",