Moved the invariant code out of the loop in updateTorrents()

This commit is contained in:
Artem Glebov 2013-03-14 08:26:20 +03:00
parent 9e98d1a26b
commit 5a3573b15d

View file

@ -19,6 +19,10 @@ KEY_MENU_ID = 92
EXIT_SCRIPT = ( 6, 10, 247, 275, 61467, 216, 257, 61448, )
CANCEL_DIALOG = EXIT_SCRIPT + ( 216, 257, 61448, )
STATUS_ICONS = {'stopped': 'pause.png',
'seeding': 'ok.png',
'downloading': 'down.png'}
class TransmissionGUI(xbmcgui.WindowXMLDialog):
def __init__(self, strXMLname, strFallbackPath, strDefaultName, bforeFallback=0):
self.list = {}
@ -67,7 +71,7 @@ class TransmissionGUI(xbmcgui.WindowXMLDialog):
self.repeater.start()
def updateTorrents(self):
list = self.getControl(120)
torrents = self.transmission.info()
self.torrents = self.transmission.info()
for i, torrent in torrents.iteritems():
statusline = "[%(status)s] %(down)s down (%(pct).2f%%), %(up)s up (Ratio: %(ratio).2f)" % \
{'down': Bytes.format(torrent.downloadedEver), 'pct': torrent.progress, \
@ -81,13 +85,9 @@ class TransmissionGUI(xbmcgui.WindowXMLDialog):
else:
# Update existing list item
l = self.list[i]
self.torrents = torrents
statusicons = {'stopped': 'pause.png',
'seeding': 'ok.png',
'downloading': 'down.png'}
l.setLabel(torrent.name)
l.setLabel2(statusline)
l.setProperty('TorrentStatusIcon', statusicons.get(torrent.status, 'pending.png'))
l.setProperty('TorrentStatusIcon', STATUS_ICONS.get(torrent.status, 'pending.png'))
l.setProperty('TorrentID', str(i))
l.setProperty('TorrentProgress', "%.2f" % torrent.progress)
l.setInfo('torrent', torrent.fields)