Start work on the addition of 'status_field' to ListViewColumn.

This commit is contained in:
Andrew Resch 2007-08-21 14:43:15 +00:00
parent d12e333e3a
commit 810c0813ce
2 changed files with 71 additions and 34 deletions

View File

@ -90,6 +90,9 @@ class ListView:
# The get_function is called when a column is in need of an update # The get_function is called when a column is in need of an update
# This is primarily used by plugins. # This is primarily used by plugins.
self.get_function = None 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 # If column is 'hidden' then it will not be visible and will not
# show up in any menu listing; it cannot be shown ever. # show up in any menu listing; it cannot be shown ever.
self.hidden = False self.hidden = False
@ -216,7 +219,8 @@ class ListView:
return return
def add_text_column(self, header, col_type=str, hidden=False, 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 # Create a new column object and add it to the list
self.liststore_columns.append(col_type) self.liststore_columns.append(col_type)
# Add to the index list so we know the order of the visible columns. # Add to the index list so we know the order of the visible columns.
@ -234,6 +238,8 @@ class ListView:
if get_function is not None: if get_function is not None:
self.columns[header].get_function = get_function self.columns[header].get_function = get_function
self.columns[header].status_field = status_field
# Create a new list with the added column # Create a new list with the added column
self.create_new_liststore() self.create_new_liststore()
@ -261,7 +267,8 @@ class ListView:
return True return True
def add_func_column(self, header, function, column_types, sortid=0, 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 # Add the new column types to the list and keep track of the liststore
# columns that this column object uses. # columns that this column object uses.
# Set sortid to the column index relative the to column_types used. # Set sortid to the column index relative the to column_types used.
@ -272,9 +279,6 @@ class ListView:
self.liststore_columns.append(column_type) self.liststore_columns.append(column_type)
column_indices.append(len(self.liststore_columns) - 1) 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. # Add to the index list so we know the order of the visible columns.
if position is not None: if position is not None:
self.column_index.insert(position, header) self.column_index.insert(position, header)
@ -284,6 +288,8 @@ class ListView:
# Create a new column object and add it to the list # Create a new column object and add it to the list
self.columns[header] = self.ListViewColumn(header, column_indices) self.columns[header] = self.ListViewColumn(header, column_indices)
self.columns[header].status_field = status_field
# Create new list with the added columns # Create new list with the added columns
self.create_new_liststore() self.create_new_liststore()
@ -316,16 +322,14 @@ class ListView:
return True return True
def add_progress_column(self, header, hidden=False, position=None, def add_progress_column(self, header, hidden=False, position=None,
get_function=None): get_function=None,
status_field=None):
# For the progress value # For the progress value
self.liststore_columns.append(float) self.liststore_columns.append(float)
# For the text # For the text
self.liststore_columns.append(str) self.liststore_columns.append(str)
column_indices = [len(self.liststore_columns) - 2, column_indices = [len(self.liststore_columns) - 2,
len(self.liststore_columns) - 1] 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. # Add to the index list so we know the order of the visible columns.
if position is not None: if position is not None:
self.column_index.insert(position, header) self.column_index.insert(position, header)
@ -334,6 +338,7 @@ class ListView:
# Create a new column object and add it to the list # Create a new column object and add it to the list
self.columns[header] = self.ListViewColumn(header, column_indices) self.columns[header] = self.ListViewColumn(header, column_indices)
self.columns[header].status_field = status_field
# Create new list with the added columns # Create new list with the added columns
self.create_new_liststore() self.create_new_liststore()
@ -361,15 +366,14 @@ class ListView:
return True return True
def add_texticon_column(self, header, hidden=False, position=None, def add_texticon_column(self, header, hidden=False, position=None,
get_function=None): get_function=None,
status_field=None):
# For icon # For icon
self.liststore_columns.append(gtk.gdk.Pixbuf) self.liststore_columns.append(gtk.gdk.Pixbuf)
# For text # For text
self.liststore_columns.append(str) self.liststore_columns.append(str)
column_indices = [len(self.liststore_columns) - 2, column_indices = [len(self.liststore_columns) - 2,
len(self.liststore_columns) - 1] 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. # Add to the index list so we know the order of the visible columns.
if position is not None: if position is not None:
@ -378,7 +382,7 @@ class ListView:
self.column_index.append(header) self.column_index.append(header)
self.columns[header] = self.ListViewColumn(header, column_indices) self.columns[header] = self.ListViewColumn(header, column_indices)
self.columns[header].status_field = status_field
# Create new list with the added columns # Create new list with the added columns
self.create_new_liststore() self.create_new_liststore()

View File

@ -56,29 +56,36 @@ 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_texticon_column("Name") self.add_texticon_column("Name", status_field=["name"])
self.add_func_column("Size", self.add_func_column("Size",
listview.cell_data_size, listview.cell_data_size,
[long]) [long],
self.add_progress_column("Progress") status_field=["total_size"])
self.add_progress_column("Progress", status_field=["progress", "state"])
self.add_func_column("Seeders", self.add_func_column("Seeders",
listview.cell_data_peer, listview.cell_data_peer,
[int, int]) [int, int],
status_field=["num_seeds", "num_seeds"])
self.add_func_column("Peers", self.add_func_column("Peers",
listview.cell_data_peer, listview.cell_data_peer,
[int, int]) [int, int],
status_field=["num_peers", "num_peers"])
self.add_func_column("Down Speed", self.add_func_column("Down Speed",
listview.cell_data_speed, listview.cell_data_speed,
[float]) [float],
status_field=["download_payload_rate"])
self.add_func_column("Up Speed", self.add_func_column("Up Speed",
listview.cell_data_speed, listview.cell_data_speed,
[float]) [float],
status_field=["upload_payload_rate"])
self.add_func_column("ETA", self.add_func_column("ETA",
listview.cell_data_time, listview.cell_data_time,
[int]) [int],
status_field=["eta"])
self.add_func_column("Ratio", self.add_func_column("Ratio",
listview.cell_data_ratio, listview.cell_data_ratio,
[float]) [float],
status_field=["ratio"])
self.window.main_glade.get_widget("menu_columns").set_submenu( self.window.main_glade.get_widget("menu_columns").set_submenu(
self.menu) self.menu)
@ -93,19 +100,45 @@ class TorrentView(listview.ListView):
self.treeview.get_selection().connect("changed", self.treeview.get_selection().connect("changed",
self.on_selection_changed) self.on_selection_changed)
def update(self): def update(self, columns=None):
"""Update the view, this is likely called by a timer""" """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 # This function is used for the foreach method of the treemodel
def update_row(model, path, row, user_data): def update_row(model, path, row, user_data):
torrent_id = self.liststore.get_value(row, 0) torrent_id = self.liststore.get_value(row, 0)
status_keys = ["progress", "state", "num_seeds", status_keys = []
"num_peers", "download_payload_rate", "upload_payload_rate", if columns is None:
"eta"] # 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 = functions.get_torrent_status(self.core, torrent_id,
status_keys) status_keys)
# Set values for each column in the row # Set values for each column in the row
# FIXME: Need to update based on 'status_keys'
self.liststore.set_value(row, self.liststore.set_value(row,
self.get_column_index("Progress")[0], self.get_column_index("Progress")[0],
status["progress"]*100) status["progress"]*100)