Improve performance by only updating labels that have changed.

This commit is contained in:
Andrew Resch 2008-01-21 01:13:56 +00:00
parent bcd2bcd2d4
commit 799037a46b
1 changed files with 62 additions and 80 deletions

View File

@ -43,6 +43,18 @@ import deluge.ui.client as client
import deluge.common import deluge.common
from deluge.log import LOG as log from deluge.log import LOG as log
def fpeer_sized(first, second):
return "%s (%s)" % (deluge.common.fsize(first), deluge.common.fsize(second))
def fpeer_size_second(first, second):
return "%s (%s)" % (first, deluge.common.fsize(second))
def fratio(value):
return "%.3f" % value
def fpcnt(value):
return "%.2f%%" % value
class TorrentDetails(component.Component): class TorrentDetails(component.Component):
def __init__(self): def __init__(self):
component.Component.__init__(self, "TorrentDetails") component.Component.__init__(self, "TorrentDetails")
@ -61,25 +73,27 @@ class TorrentDetails(component.Component):
self.is_visible = True self.is_visible = True
# Get the labels we need to update. # Get the labels we need to update.
self.progress_bar = glade.get_widget("progressbar") # widgetname, modifier function, status keys
self.name = glade.get_widget("summary_name") self.label_widgets = [
self.total_size = glade.get_widget("summary_total_size") (glade.get_widget("summary_name"), None, ("name",)),
self.num_files = glade.get_widget("summary_num_files") (glade.get_widget("summary_total_size"), deluge.common.fsize, ("total_size",)),
self.pieces = glade.get_widget("summary_pieces") (glade.get_widget("summary_num_files"), str, ("num_files",)),
self.availability = glade.get_widget("summary_availability") (glade.get_widget("summary_pieces"), fpeer_size_second, ("num_pieces", "piece_length")),
self.total_downloaded = glade.get_widget("summary_total_downloaded") (glade.get_widget("summary_availability"), fratio, ("distributed_copies",)),
self.total_uploaded = glade.get_widget("summary_total_uploaded") (glade.get_widget("summary_total_downloaded"), fpeer_sized, ("total_done", "total_payload_download")),
self.download_speed = glade.get_widget("summary_download_speed") (glade.get_widget("summary_total_uploaded"), fpeer_sized, ("total_uploaded", "total_payload_upload")),
self.upload_speed = glade.get_widget("summary_upload_speed") (glade.get_widget("summary_download_speed"), deluge.common.fspeed, ("download_payload_rate",)),
self.seeders = glade.get_widget("summary_seeders") (glade.get_widget("summary_upload_speed"), deluge.common.fspeed, ("upload_payload_rate",)),
self.peers = glade.get_widget("summary_peers") (glade.get_widget("summary_seeders"), deluge.common.fpeer, ("num_seeds", "total_seeds")),
self.percentage_done = glade.get_widget("summary_percentage_done") (glade.get_widget("summary_peers"), deluge.common.fpeer, ("num_peers", "total_peers")),
self.share_ratio = glade.get_widget("summary_share_ratio") (glade.get_widget("summary_eta"), deluge.common.ftime, ("eta",)),
self.tracker = glade.get_widget("summary_tracker") (glade.get_widget("summary_share_ratio"), fratio, ("ratio",)),
self.tracker_status = glade.get_widget("summary_tracker_status") (glade.get_widget("summary_tracker"), None, ("tracker",)),
self.next_announce = glade.get_widget("summary_next_announce") (glade.get_widget("summary_tracker_status"), None, ("tracker_status",)),
self.eta = glade.get_widget("summary_eta") (glade.get_widget("summary_next_announce"), deluge.common.ftime, ("next_announce",)),
self.torrent_path = glade.get_widget("summary_torrent_path") (glade.get_widget("summary_torrent_path"), None, ("save_path",)),
(glade.get_widget("progressbar"), fpcnt, ("progress",))
]
def visible(self, visible): def visible(self, visible):
if visible: if visible:
@ -103,7 +117,6 @@ class TorrentDetails(component.Component):
self.notebook.get_current_page() and \ self.notebook.get_current_page() and \
self.notebook.get_property("visible"): self.notebook.get_property("visible"):
# Get the first selected torrent # Get the first selected torrent
#selected = self.window.torrentview.get_selected_torrents()
selected = component.get("TorrentView").get_selected_torrents() selected = component.get("TorrentView").get_selected_torrents()
# Only use the first torrent in the list or return if None selected # Only use the first torrent in the list or return if None selected
@ -129,67 +142,36 @@ class TorrentDetails(component.Component):
if status is None: if status is None:
return return
# We need to adjust the value core gives us for progress # Update all the label widgets
for widget in self.label_widgets:
if widget[1] != None:
args = []
try: try:
progress = status["progress"]/100 for key in widget[2]:
args.append(status[key])
except Exception, e:
log.debug("Unable to get status value: %s", e)
continue
self.progress_bar.set_fraction(progress) txt = widget[1](*args)
self.progress_bar.set_text(deluge.common.fpcnt(progress)) else:
txt = status[widget[2][0]]
self.name.set_text(status["name"])
self.total_size.set_text(
deluge.common.fsize(status["total_size"]))
self.num_files.set_text(str(status["num_files"]))
self.pieces.set_text("%s (%s)" % (status["num_pieces"],
deluge.common.fsize(status["piece_length"])))
self.availability.set_text(
"%.3f" % status["distributed_copies"])
self.total_downloaded.set_text("%s (%s)" % \
(deluge.common.fsize(status["total_done"]),
deluge.common.fsize(status["total_payload_download"])))
self.total_uploaded.set_text("%s (%s)" % \
(deluge.common.fsize(status["total_uploaded"]),
deluge.common.fsize(status["total_payload_upload"])))
self.download_speed.set_text(
deluge.common.fspeed(status["download_payload_rate"]))
self.upload_speed.set_text(
deluge.common.fspeed(status["upload_payload_rate"]))
self.seeders.set_text(deluge.common.fpeer(status["num_seeds"],
status["total_seeds"]))
self.peers.set_text(deluge.common.fpeer(status["num_peers"],
status["total_peers"]))
self.eta.set_text(deluge.common.ftime(status["eta"]))
self.share_ratio.set_text("%.3f" % status["ratio"])
self.tracker.set_text(status["tracker"])
self.tracker_status.set_text(status["tracker_status"])
self.next_announce.set_text(
deluge.common.ftime(status["next_announce"]))
self.torrent_path.set_text(status["save_path"])
except KeyError, e:
log.debug(e)
if widget[0].get_text() != txt:
widget[0].set_text(txt)
# Do the progress bar because it's a special case (not a label)
w = self.window.main_glade.get_widget("progressbar")
fraction = status["progress"] / 100
if w.get_fraction() != fraction:
w.set_fraction(fraction)
def clear(self): def clear(self):
# Only update if this page is showing # Only update if this page is showing
if self.notebook.page_num(self.details_tab) is \ if self.notebook.page_num(self.details_tab) is \
self.notebook.get_current_page(): self.notebook.get_current_page():
self.name.set_text("")
self.total_size.set_text("") for widget in self.label_widgets:
self.num_files.set_text("") widget[0].set_text("")
self.pieces.set_text("")
self.availability.set_text("") self.window.main_glade.get_widget("progressbar").set_fraction(0.0)
self.total_downloaded.set_text("")
self.total_uploaded.set_text("")
self.download_speed.set_text("")
self.upload_speed.set_text("")
self.seeders.set_text("")
self.peers.set_text("")
self.progress_bar.set_fraction(0.0)
self.progress_bar.set_text("")
self.share_ratio.set_text("")
self.tracker.set_text("")
self.tracker_status.set_text("")
self.next_announce.set_text("")
self.eta.set_text("")
self.torrent_path.set_text("")