From f7b537ad81c59fc9e88eb1945231c36e1c0667d4 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Fri, 21 Sep 2007 22:54:46 +0000 Subject: [PATCH] Display progress bar in torrentview properly. --- deluge/ui/gtkui/listview.py | 16 +++++++++++----- deluge/ui/gtkui/torrentview.py | 19 ++++++++++++++++++- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/deluge/ui/gtkui/listview.py b/deluge/ui/gtkui/listview.py index 681cbf70b..ec6cb0aa8 100644 --- a/deluge/ui/gtkui/listview.py +++ b/deluge/ui/gtkui/listview.py @@ -287,10 +287,14 @@ class ListView: self.columns[header].column_indices[0]) elif column_type == "progress": column.pack_start(render) - column.add_attribute(render, "text", - self.columns[header].column_indices[text]) - column.add_attribute(render, "value", - self.columns[header].column_indices[value]) + if function is None: + column.add_attribute(render, "text", + self.columns[header].column_indices[text]) + column.add_attribute(render, "value", + self.columns[header].column_indices[value]) + else: + column.set_cell_data_func(render, function, + tuple(self.columns[header].column_indices)) elif column_type == "texticon": column.pack_start(render[pixbuf]) if function is not None: @@ -354,12 +358,14 @@ class ListView: hidden=False, position=None, status_field=None, + function=None, column_type="progress"): """Add a progress column to the listview.""" render = gtk.CellRendererProgress() self.add_column(header, render, col_types, hidden, position, - status_field, sortid, column_type=column_type, + status_field, sortid, function=function, + column_type=column_type, value=0, text=1) return True diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index 78b42a203..9337fc9fe 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -65,6 +65,20 @@ def cell_data_statusicon(column, cell, model, row, data): icon = gtk.gdk.pixbuf_new_from_file(deluge.common.get_pixmap(fname)) cell.set_property("pixbuf", icon) + +def cell_data_progress(column, cell, model, row, data): + """Display progress bar with text""" + column1, column2 = data + value = model.get_value(row, column1) + text = model.get_value(row, column2) + cell.set_property("value", value) + textstr = "%s" % _(deluge.common.TORRENT_STATE[text]) + if deluge.common.TORRENT_STATE[text] == "Downloading" or\ + deluge.common.TORRENT_STATE[text] == "Downloading Metadata" or\ + deluge.common.TORRENT_STATE[text] == "Checking" or\ + deluge.common.TORRENT_STATE[text] == "Allocating": + textstr = textstr + " %.2f%%" % value + cell.set_property("text", textstr) class TorrentView(listview.ListView): """TorrentView handles the listing of torrents.""" @@ -89,7 +103,10 @@ class TorrentView(listview.ListView): listview.cell_data_size, [long], status_field=["total_size"]) - self.add_progress_column(_("Progress"), status_field=["progress", "state"]) + self.add_progress_column(_("Progress"), + status_field=["progress", "state"], + col_types=[float, int], + function=cell_data_progress) self.add_func_column(_("Seeders"), listview.cell_data_peer, [int, int],