Add status icons to torrentview.
This commit is contained in:
parent
a9961adda7
commit
4ca7ced757
|
@ -89,6 +89,7 @@ def get_pixmap(fname):
|
||||||
"""Returns a pixmap file included with deluge"""
|
"""Returns a pixmap file included with deluge"""
|
||||||
return pkg_resources.resource_filename("deluge", os.path.join("data", \
|
return pkg_resources.resource_filename("deluge", os.path.join("data", \
|
||||||
"pixmaps", fname))
|
"pixmaps", fname))
|
||||||
|
|
||||||
def get_logo(size):
|
def get_logo(size):
|
||||||
"""Returns a deluge logo pixbuf based on the size parameter."""
|
"""Returns a deluge logo pixbuf based on the size parameter."""
|
||||||
import gtk
|
import gtk
|
||||||
|
|
|
@ -40,7 +40,6 @@ import deluge.common
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
# Cell data functions to pass to add_func_column()
|
# Cell data functions to pass to add_func_column()
|
||||||
|
|
||||||
def cell_data_speed(column, cell, model, row, data):
|
def cell_data_speed(column, cell, model, row, data):
|
||||||
"""Display value as a speed, eg. 2 KiB/s"""
|
"""Display value as a speed, eg. 2 KiB/s"""
|
||||||
speed = int(model.get_value(row, data))
|
speed = int(model.get_value(row, data))
|
||||||
|
@ -244,8 +243,9 @@ class ListView:
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def add_column(self, header, renderer, col_types, hidden, position,
|
def add_column(self, header, render, col_types, hidden, position,
|
||||||
status_field, sortid, text=0, value=0, function=None):
|
status_field, sortid, text=0, value=0, pixbuf=0, function=None,
|
||||||
|
column_type=None):
|
||||||
"""Adds a column to the ListView"""
|
"""Adds a column to the ListView"""
|
||||||
# Add the column types to liststore_columns
|
# Add the column types to liststore_columns
|
||||||
column_indices = []
|
column_indices = []
|
||||||
|
@ -272,21 +272,12 @@ class ListView:
|
||||||
# Create a new list with the added column
|
# Create a new list with the added column
|
||||||
self.create_new_liststore()
|
self.create_new_liststore()
|
||||||
|
|
||||||
if type(renderer) is not tuple and type(renderer) is not list:
|
|
||||||
renderer = [renderer]
|
|
||||||
|
|
||||||
column = gtk.TreeViewColumn(header)
|
column = gtk.TreeViewColumn(header)
|
||||||
for render in renderer:
|
if column_type == "text":
|
||||||
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
|
|
||||||
column.pack_start(render)
|
column.pack_start(render)
|
||||||
column.add_attribute(render, "text",
|
column.add_attribute(render, "text",
|
||||||
self.columns[header].column_indices[text])
|
self.columns[header].column_indices[text])
|
||||||
else:
|
elif column_type == "func":
|
||||||
# This is a function column
|
|
||||||
column.pack_start(render, True)
|
column.pack_start(render, True)
|
||||||
if len(self.columns[header].column_indices) > 1:
|
if len(self.columns[header].column_indices) > 1:
|
||||||
column.set_cell_data_func(render, function,
|
column.set_cell_data_func(render, function,
|
||||||
|
@ -294,21 +285,24 @@ class ListView:
|
||||||
else:
|
else:
|
||||||
column.set_cell_data_func(render, function,
|
column.set_cell_data_func(render, function,
|
||||||
self.columns[header].column_indices[0])
|
self.columns[header].column_indices[0])
|
||||||
elif type(render) is gtk.CellRendererProgress:
|
elif column_type == "progress":
|
||||||
# This is a progress column
|
|
||||||
column.pack_start(render)
|
column.pack_start(render)
|
||||||
column.add_attribute(render, "text",
|
column.add_attribute(render, "text",
|
||||||
self.columns[header].column_indices[text])
|
self.columns[header].column_indices[text])
|
||||||
column.add_attribute(render, "value",
|
column.add_attribute(render, "value",
|
||||||
self.columns[header].column_indices[value])
|
self.columns[header].column_indices[value])
|
||||||
|
elif column_type == "texticon":
|
||||||
elif type(render) is gtk.CellRendererPixbuf:
|
column.pack_start(render[pixbuf])
|
||||||
# This is a pixbuf column
|
if function is not None:
|
||||||
column.pack_start(render, expand=False)
|
column.set_cell_data_func(render[pixbuf], function,
|
||||||
column.add_attribute(render, "pixbuf",
|
|
||||||
self.columns[header].column_indices[pixbuf])
|
self.columns[header].column_indices[pixbuf])
|
||||||
else:
|
column.pack_start(render[text])
|
||||||
column.pack_start(render)
|
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_sort_column_id(self.columns[header].column_indices[sortid])
|
||||||
column.set_clickable(True)
|
column.set_clickable(True)
|
||||||
|
@ -332,23 +326,26 @@ class ListView:
|
||||||
def add_text_column(self, header, col_type=str, hidden=False,
|
def add_text_column(self, header, col_type=str, hidden=False,
|
||||||
position=None,
|
position=None,
|
||||||
status_field=None,
|
status_field=None,
|
||||||
sortid=0):
|
sortid=0,
|
||||||
|
column_type="text"):
|
||||||
"""Add a text column to the listview. Only the header name is required.
|
"""Add a text column to the listview. Only the header name is required.
|
||||||
"""
|
"""
|
||||||
render = gtk.CellRendererText()
|
render = gtk.CellRendererText()
|
||||||
self.add_column(header, render, col_type, hidden, position,
|
self.add_column(header, render, col_type, hidden, position,
|
||||||
status_field, sortid, text=0)
|
status_field, sortid, column_type=column_type)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def add_func_column(self, header, function, col_types, sortid=0,
|
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
|
"""Add a function column to the listview. Need a header name, the
|
||||||
function and the column types."""
|
function and the column types."""
|
||||||
|
|
||||||
render = gtk.CellRendererText()
|
render = gtk.CellRendererText()
|
||||||
self.add_column(header, render, col_types, hidden, position,
|
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
|
return True
|
||||||
|
|
||||||
|
@ -356,25 +353,31 @@ class ListView:
|
||||||
sortid=0,
|
sortid=0,
|
||||||
hidden=False,
|
hidden=False,
|
||||||
position=None,
|
position=None,
|
||||||
status_field=None):
|
status_field=None,
|
||||||
|
column_type="progress"):
|
||||||
"""Add a progress column to the listview."""
|
"""Add a progress column to the listview."""
|
||||||
|
|
||||||
render = gtk.CellRendererProgress()
|
render = gtk.CellRendererProgress()
|
||||||
self.add_column(header, render, col_types, hidden, position,
|
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
|
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,
|
sortid=0,
|
||||||
hidden=False,
|
hidden=False,
|
||||||
position=None,
|
position=None,
|
||||||
status_field=None):
|
status_field=None,
|
||||||
|
column_type="texticon",
|
||||||
|
function=None):
|
||||||
"""Adds a texticon column to the listview."""
|
"""Adds a texticon column to the listview."""
|
||||||
render1 = gtk.CellRendererPixbuf()
|
render1 = gtk.CellRendererPixbuf()
|
||||||
render2 = gtk.CellRendererText()
|
render2 = gtk.CellRendererText()
|
||||||
|
|
||||||
self.add_column(header, (render1, render2), col_types, hidden,
|
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
|
return True
|
||||||
|
|
|
@ -38,10 +38,34 @@ pygtk.require('2.0')
|
||||||
import gtk, gtk.glade
|
import gtk, gtk.glade
|
||||||
import gettext
|
import gettext
|
||||||
|
|
||||||
|
import deluge.common
|
||||||
import deluge.ui.functions as functions
|
import deluge.ui.functions as functions
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
import deluge.ui.gtkui.listview as listview
|
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):
|
class TorrentView(listview.ListView):
|
||||||
"""TorrentView handles the listing of torrents."""
|
"""TorrentView handles the listing of torrents."""
|
||||||
def __init__(self, window):
|
def __init__(self, window):
|
||||||
|
@ -59,7 +83,8 @@ class TorrentView(listview.ListView):
|
||||||
|
|
||||||
# Add the columns to the listview
|
# Add the columns to the listview
|
||||||
self.add_text_column("torrent_id", hidden=True)
|
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",
|
self.add_func_column("Size",
|
||||||
listview.cell_data_size,
|
listview.cell_data_size,
|
||||||
[long],
|
[long],
|
||||||
|
@ -143,6 +168,9 @@ class TorrentView(listview.ListView):
|
||||||
status_keys.append(field)
|
status_keys.append(field)
|
||||||
columns_to_update.append(column)
|
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 there is nothing in status_keys then we must not continue
|
||||||
if status_keys is []:
|
if status_keys is []:
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue