Add status icons to torrentview.

This commit is contained in:
Andrew Resch 2007-09-21 00:08:12 +00:00
parent a9961adda7
commit 4ca7ced757
3 changed files with 80 additions and 48 deletions

View File

@ -89,6 +89,7 @@ def get_pixmap(fname):
"""Returns a pixmap file included with deluge"""
return pkg_resources.resource_filename("deluge", os.path.join("data", \
"pixmaps", fname))
def get_logo(size):
"""Returns a deluge logo pixbuf based on the size parameter."""
import gtk

View File

@ -40,7 +40,6 @@ import deluge.common
from deluge.log import LOG as log
# Cell data functions to pass to add_func_column()
def cell_data_speed(column, cell, model, row, data):
"""Display value as a speed, eg. 2 KiB/s"""
speed = int(model.get_value(row, data))
@ -244,8 +243,9 @@ class ListView:
return
def add_column(self, header, renderer, col_types, hidden, position,
status_field, sortid, text=0, value=0, function=None):
def add_column(self, header, render, col_types, hidden, position,
status_field, sortid, text=0, value=0, pixbuf=0, function=None,
column_type=None):
"""Adds a column to the ListView"""
# Add the column types to liststore_columns
column_indices = []
@ -272,21 +272,12 @@ class ListView:
# Create a new list with the added column
self.create_new_liststore()
if type(renderer) is not tuple and type(renderer) is not list:
renderer = [renderer]
column = gtk.TreeViewColumn(header)
for render in renderer:
if type(render) is gtk.CellRendererText:
# Check to see if this is a function column or not
if function is None:
# Not a function column, so lets treat it as a regular
# text col
if column_type == "text":
column.pack_start(render)
column.add_attribute(render, "text",
self.columns[header].column_indices[text])
else:
# This is a function column
elif column_type == "func":
column.pack_start(render, True)
if len(self.columns[header].column_indices) > 1:
column.set_cell_data_func(render, function,
@ -294,21 +285,24 @@ class ListView:
else:
column.set_cell_data_func(render, function,
self.columns[header].column_indices[0])
elif type(render) is gtk.CellRendererProgress:
# This is a progress column
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])
elif type(render) is gtk.CellRendererPixbuf:
# This is a pixbuf column
column.pack_start(render, expand=False)
column.add_attribute(render, "pixbuf",
elif column_type == "texticon":
column.pack_start(render[pixbuf])
if function is not None:
column.set_cell_data_func(render[pixbuf], function,
self.columns[header].column_indices[pixbuf])
else:
column.pack_start(render)
column.pack_start(render[text])
column.add_attribute(render[text], "text",
self.columns[header].column_indices[text])
elif column_type == None:
return
column.set_sort_column_id(self.columns[header].column_indices[sortid])
column.set_clickable(True)
@ -332,23 +326,26 @@ class ListView:
def add_text_column(self, header, col_type=str, hidden=False,
position=None,
status_field=None,
sortid=0):
sortid=0,
column_type="text"):
"""Add a text column to the listview. Only the header name is required.
"""
render = gtk.CellRendererText()
self.add_column(header, render, col_type, hidden, position,
status_field, sortid, text=0)
status_field, sortid, column_type=column_type)
return True
def add_func_column(self, header, function, col_types, sortid=0,
hidden=False, position=None, status_field=None):
hidden=False, position=None, status_field=None,
column_type="func"):
"""Add a function column to the listview. Need a header name, the
function and the column types."""
render = gtk.CellRendererText()
self.add_column(header, render, col_types, hidden, position,
status_field, sortid, function=function)
status_field, sortid, column_type=column_type,
function=function)
return True
@ -356,25 +353,31 @@ class ListView:
sortid=0,
hidden=False,
position=None,
status_field=None):
status_field=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, value=0, text=1)
status_field, sortid, column_type=column_type,
value=0, text=1)
return True
def add_texticon_column(self, header, col_types=[gtk.gdk.Pixbuf, str],
def add_texticon_column(self, header, col_types=[int, str],
sortid=0,
hidden=False,
position=None,
status_field=None):
status_field=None,
column_type="texticon",
function=None):
"""Adds a texticon column to the listview."""
render1 = gtk.CellRendererPixbuf()
render2 = gtk.CellRendererText()
self.add_column(header, (render1, render2), col_types, hidden,
position, status_field, sortid, text=1, pixbuf=0)
position, status_field, sortid,
column_type=column_type, function=function,
pixbuf=0, text=1)
return True

View File

@ -38,10 +38,34 @@ pygtk.require('2.0')
import gtk, gtk.glade
import gettext
import deluge.common
import deluge.ui.functions as functions
from deluge.log import LOG as log
import deluge.ui.gtkui.listview as listview
def cell_data_statusicon(column, cell, model, row, data):
"""Display text with an icon"""
state = model.get_value(row, data)
if state == deluge.common.TORRENT_STATE.index("Connecting"):
fname = "downloading16.png"
if state == deluge.common.TORRENT_STATE.index("Downloading"):
fname = "downloading16.png"
if state == deluge.common.TORRENT_STATE.index("Downloading Metadata"):
fname = "downloading16.png"
if state == deluge.common.TORRENT_STATE.index("Queued"):
fname = "inactive16.png"
if state == deluge.common.TORRENT_STATE.index("Checking"):
fname = "downloading16.png"
if state == deluge.common.TORRENT_STATE.index("Allocating"):
fname = "downloading16.png"
if state == deluge.common.TORRENT_STATE.index("Finished"):
fname = "seeding16.png"
if state == deluge.common.TORRENT_STATE.index("Seeding"):
fname = "seeding16.png"
icon = gtk.gdk.pixbuf_new_from_file(deluge.common.get_pixmap(fname))
cell.set_property("pixbuf", icon)
class TorrentView(listview.ListView):
"""TorrentView handles the listing of torrents."""
def __init__(self, window):
@ -59,7 +83,8 @@ class TorrentView(listview.ListView):
# Add the columns to the listview
self.add_text_column("torrent_id", hidden=True)
self.add_text_column("Name", status_field=["name"])
self.add_texticon_column("Name", status_field=["state", "name"],
function=cell_data_statusicon)
self.add_func_column("Size",
listview.cell_data_size,
[long],
@ -143,6 +168,9 @@ class TorrentView(listview.ListView):
status_keys.append(field)
columns_to_update.append(column)
# Remove duplicate keys
columns_to_update = list(set(columns_to_update))
# If there is nothing in status_keys then we must not continue
if status_keys is []:
return