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