Start work on the addition of 'status_field' to ListViewColumn.
This commit is contained in:
parent
d12e333e3a
commit
810c0813ce
|
@ -90,6 +90,9 @@ class ListView:
|
|||
# The get_function is called when a column is in need of an update
|
||||
# This is primarily used by plugins.
|
||||
self.get_function = None
|
||||
# This is the name of the status field that the column will query
|
||||
# the core for if an update is called.
|
||||
self.status_field = None
|
||||
# If column is 'hidden' then it will not be visible and will not
|
||||
# show up in any menu listing; it cannot be shown ever.
|
||||
self.hidden = False
|
||||
|
@ -216,7 +219,8 @@ class ListView:
|
|||
return
|
||||
|
||||
def add_text_column(self, header, col_type=str, hidden=False,
|
||||
position=None, get_function=None):
|
||||
position=None, get_function=None,
|
||||
status_field=None):
|
||||
# Create a new column object and add it to the list
|
||||
self.liststore_columns.append(col_type)
|
||||
# Add to the index list so we know the order of the visible columns.
|
||||
|
@ -233,6 +237,8 @@ class ListView:
|
|||
# value.
|
||||
if get_function is not None:
|
||||
self.columns[header].get_function = get_function
|
||||
|
||||
self.columns[header].status_field = status_field
|
||||
|
||||
# Create a new list with the added column
|
||||
self.create_new_liststore()
|
||||
|
@ -261,7 +267,8 @@ class ListView:
|
|||
return True
|
||||
|
||||
def add_func_column(self, header, function, column_types, sortid=0,
|
||||
hidden=False, position=None, get_function=None):
|
||||
hidden=False, position=None, get_function=None,
|
||||
status_field=None):
|
||||
# Add the new column types to the list and keep track of the liststore
|
||||
# columns that this column object uses.
|
||||
# Set sortid to the column index relative the to column_types used.
|
||||
|
@ -272,9 +279,6 @@ class ListView:
|
|||
self.liststore_columns.append(column_type)
|
||||
column_indices.append(len(self.liststore_columns) - 1)
|
||||
|
||||
# Add to the index list so we know the order of the visible columns.
|
||||
self.column_index.append(header)
|
||||
|
||||
# Add to the index list so we know the order of the visible columns.
|
||||
if position is not None:
|
||||
self.column_index.insert(position, header)
|
||||
|
@ -283,7 +287,9 @@ class ListView:
|
|||
|
||||
# Create a new column object and add it to the list
|
||||
self.columns[header] = self.ListViewColumn(header, column_indices)
|
||||
|
||||
|
||||
self.columns[header].status_field = status_field
|
||||
|
||||
# Create new list with the added columns
|
||||
self.create_new_liststore()
|
||||
|
||||
|
@ -316,16 +322,14 @@ class ListView:
|
|||
return True
|
||||
|
||||
def add_progress_column(self, header, hidden=False, position=None,
|
||||
get_function=None):
|
||||
get_function=None,
|
||||
status_field=None):
|
||||
# For the progress value
|
||||
self.liststore_columns.append(float)
|
||||
# For the text
|
||||
self.liststore_columns.append(str)
|
||||
column_indices = [len(self.liststore_columns) - 2,
|
||||
len(self.liststore_columns) - 1]
|
||||
# Add to the index list so we know the order of the visible columns.
|
||||
self.column_index.append(header)
|
||||
|
||||
# Add to the index list so we know the order of the visible columns.
|
||||
if position is not None:
|
||||
self.column_index.insert(position, header)
|
||||
|
@ -333,7 +337,8 @@ class ListView:
|
|||
self.column_index.append(header)
|
||||
# Create a new column object and add it to the list
|
||||
self.columns[header] = self.ListViewColumn(header, column_indices)
|
||||
|
||||
|
||||
self.columns[header].status_field = status_field
|
||||
# Create new list with the added columns
|
||||
self.create_new_liststore()
|
||||
|
||||
|
@ -361,15 +366,14 @@ class ListView:
|
|||
return True
|
||||
|
||||
def add_texticon_column(self, header, hidden=False, position=None,
|
||||
get_function=None):
|
||||
get_function=None,
|
||||
status_field=None):
|
||||
# For icon
|
||||
self.liststore_columns.append(gtk.gdk.Pixbuf)
|
||||
# For text
|
||||
self.liststore_columns.append(str)
|
||||
column_indices = [len(self.liststore_columns) - 2,
|
||||
len(self.liststore_columns) - 1]
|
||||
# Add to the index list so we know the order of the visible columns.
|
||||
self.column_index.append(header)
|
||||
|
||||
# Add to the index list so we know the order of the visible columns.
|
||||
if position is not None:
|
||||
|
@ -378,7 +382,7 @@ class ListView:
|
|||
self.column_index.append(header)
|
||||
|
||||
self.columns[header] = self.ListViewColumn(header, column_indices)
|
||||
|
||||
self.columns[header].status_field = status_field
|
||||
# Create new list with the added columns
|
||||
self.create_new_liststore()
|
||||
|
||||
|
|
|
@ -56,29 +56,36 @@ class TorrentView(listview.ListView):
|
|||
|
||||
# Add the columns to the listview
|
||||
self.add_text_column("torrent_id", hidden=True)
|
||||
self.add_texticon_column("Name")
|
||||
self.add_texticon_column("Name", status_field=["name"])
|
||||
self.add_func_column("Size",
|
||||
listview.cell_data_size,
|
||||
[long])
|
||||
self.add_progress_column("Progress")
|
||||
[long],
|
||||
status_field=["total_size"])
|
||||
self.add_progress_column("Progress", status_field=["progress", "state"])
|
||||
self.add_func_column("Seeders",
|
||||
listview.cell_data_peer,
|
||||
[int, int])
|
||||
listview.cell_data_peer,
|
||||
[int, int],
|
||||
status_field=["num_seeds", "num_seeds"])
|
||||
self.add_func_column("Peers",
|
||||
listview.cell_data_peer,
|
||||
[int, int])
|
||||
listview.cell_data_peer,
|
||||
[int, int],
|
||||
status_field=["num_peers", "num_peers"])
|
||||
self.add_func_column("Down Speed",
|
||||
listview.cell_data_speed,
|
||||
[float])
|
||||
listview.cell_data_speed,
|
||||
[float],
|
||||
status_field=["download_payload_rate"])
|
||||
self.add_func_column("Up Speed",
|
||||
listview.cell_data_speed,
|
||||
[float])
|
||||
listview.cell_data_speed,
|
||||
[float],
|
||||
status_field=["upload_payload_rate"])
|
||||
self.add_func_column("ETA",
|
||||
listview.cell_data_time,
|
||||
[int])
|
||||
[int],
|
||||
status_field=["eta"])
|
||||
self.add_func_column("Ratio",
|
||||
listview.cell_data_ratio,
|
||||
[float])
|
||||
[float],
|
||||
status_field=["ratio"])
|
||||
|
||||
self.window.main_glade.get_widget("menu_columns").set_submenu(
|
||||
self.menu)
|
||||
|
@ -93,19 +100,45 @@ class TorrentView(listview.ListView):
|
|||
self.treeview.get_selection().connect("changed",
|
||||
self.on_selection_changed)
|
||||
|
||||
def update(self):
|
||||
"""Update the view, this is likely called by a timer"""
|
||||
def update(self, columns=None):
|
||||
"""Update the view. If columns is not None, it will attempt to only
|
||||
update those columns selected.
|
||||
"""
|
||||
# This function is used for the foreach method of the treemodel
|
||||
def update_row(model, path, row, user_data):
|
||||
torrent_id = self.liststore.get_value(row, 0)
|
||||
status_keys = ["progress", "state", "num_seeds",
|
||||
"num_peers", "download_payload_rate", "upload_payload_rate",
|
||||
"eta"]
|
||||
status_keys = []
|
||||
if columns is None:
|
||||
# Iterate through the list of columns and only add the
|
||||
# 'status-fields' of the visible ones.
|
||||
for column in self.columns.values():
|
||||
# Make sure column is visible and has 'status_field' set.
|
||||
# If not, we can ignore it.
|
||||
if column.column.get_visible() is True \
|
||||
and column.hidden is False \
|
||||
and column.status_field is not None:
|
||||
for field in column.status_field:
|
||||
status_keys.append(field)
|
||||
else:
|
||||
# Iterate through supplied list of columns to update
|
||||
for column in columns:
|
||||
if self.columns[column.name].column.get_visible() is True \
|
||||
and self.columns[column.name].hidden is False \
|
||||
and self.columns[column.name].status_field is not None:
|
||||
for field in self.columns[column.name].status_field:
|
||||
status_keys.append(field)
|
||||
|
||||
# If there is nothing in status_keys then we must not continue
|
||||
if status_keys is []:
|
||||
return
|
||||
|
||||
# Remove duplicates from status_key list
|
||||
status_keys = list(set(status_keys))
|
||||
status = functions.get_torrent_status(self.core, torrent_id,
|
||||
status_keys)
|
||||
|
||||
# Set values for each column in the row
|
||||
|
||||
# FIXME: Need to update based on 'status_keys'
|
||||
self.liststore.set_value(row,
|
||||
self.get_column_index("Progress")[0],
|
||||
status["progress"]*100)
|
||||
|
|
Loading…
Reference in New Issue