Display progress bar in torrentview properly.

This commit is contained in:
Andrew Resch 2007-09-21 22:54:46 +00:00
parent 0c012133cd
commit f7b537ad81
2 changed files with 29 additions and 6 deletions

View File

@ -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

View File

@ -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],