Remove idea of a 'get_function'. Updated add_row() to use new

status_fields.
This commit is contained in:
Andrew Resch 2007-08-22 08:53:12 +00:00
commit f3c80eb816
2 changed files with 71 additions and 110 deletions

View file

@ -69,7 +69,6 @@ class GtkUI:
self.torrentview.add_text_column("#", self.torrentview.add_text_column("#",
col_type=int, col_type=int,
position=0, position=0,
get_function=self.column_get_function,
status_field=["queue"]) status_field=["queue"])
# Add a toolbar buttons # Add a toolbar buttons
self.plugin.get_toolbar().add_separator() self.plugin.get_toolbar().add_separator()
@ -107,9 +106,4 @@ class GtkUI:
# We only need to update the queue column # We only need to update the queue column
self.torrentview.update(["#"]) self.torrentview.update(["#"])
return return
def column_get_function(self, torrent_id):
"""Returns the queue position for torrent_id"""
# Return the value + 1 because we want the queue list to start at 1
# for the user display.
return self.core.get_position(torrent_id) + 1

View file

@ -56,7 +56,7 @@ 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", status_field=["name"]) self.add_text_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],
@ -104,113 +104,80 @@ class TorrentView(listview.ListView):
"""Update the view. If columns is not None, it will attempt to only """Update the view. If columns is not None, it will attempt to only
update those columns selected. 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)
# Store the 'status_fields' we need to send to core
status_keys = []
# Store the actual columns we will be updating
columns_to_update = []
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)
columns_to_update.append(column.name)
else:
# Iterate through supplied list of columns to update
for column in columns:
if self.columns[column].column.get_visible() is True \
and self.columns[column].hidden is False \
and self.columns[column].status_field is not None:
for field in self.columns[column].status_field:
status_keys.append(field)
columns_to_update.append(column)
# 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
for column in columns_to_update:
if type(self.get_column_index(column)) is not list:
# We only have a single list store column we need to update
self.liststore.set_value(row,
self.get_column_index(column),
status[self.columns[column].status_field[0]])
else:
# We have more than 1 liststore column to update
i = 0
for index in self.get_column_index(column):
# Only update the column if the status field exists
try:
self.liststore.set_value(row,
index,
status[self.columns[column].status_field[i]])
except:
pass
i = i + 1
# Iterates through every row and updates them accordingly # Iterates through every row and updates them accordingly
if self.liststore is not None: if self.liststore is not None:
self.liststore.foreach(update_row, None) self.liststore.foreach(self.update_row, columns)
def add_row(self, torrent_id): def update_row(self, model, path, row, columns=None):
"""Adds a new torrent row to the treeview""" torrent_id = self.liststore.get_value(row,
## REWRITE TO USE STATUS FIELDS self.columns["torrent_id"].column_indices[0])
# Get the status and info dictionaries # Store the 'status_fields' we need to send to core
status_keys = ["name", "total_size", "progress", "state", status_keys = []
"num_seeds", "num_peers", "download_payload_rate", # Store the actual columns we will be updating
"upload_payload_rate", "eta"] columns_to_update = []
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)
columns_to_update.append(column.name)
else:
# Iterate through supplied list of columns to update
for column in columns:
if self.columns[column].column.get_visible() is True \
and self.columns[column].hidden is False \
and self.columns[column].status_field is not None:
for field in self.columns[column].status_field:
status_keys.append(field)
columns_to_update.append(column)
# 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)
row_list = [
torrent_id,
None,
status["name"],
status["total_size"],
status["progress"]*100,
status["state"],
status["num_seeds"],
status["num_seeds"],
status["num_peers"],
status["num_peers"],
status["download_payload_rate"],
status["upload_payload_rate"],
status["eta"],
0.0
]
# Insert any column info from get_functions.. this is usually from # Set values for each column in the row
# plugins for column in columns_to_update:
for column in self.columns.values(): if type(self.get_column_index(column)) is not list:
if column.get_function is not None: # We only have a single list store column we need to update
if len(column.column_indices) == 1: self.liststore.set_value(row,
row_list.insert(column.column_indices[0], self.get_column_index(column),
column.get_function(torrent_id)) status[self.columns[column].status_field[0]])
else: else:
result = column.get_function(torrent_id) # We have more than 1 liststore column to update
r_index = 0 i = 0
for index in column.column_indices: for index in self.get_column_index(column):
row_list.insert(index, result[r_index]) # Only update the column if the status field exists
r_index = r_index + 1 try:
self.liststore.set_value(row,
# Insert the row with info provided from core index,
self.liststore.append(row_list) status[self.columns[column].status_field[i]])
except:
pass
i = i + 1
def add_row(self, torrent_id):
"""Adds a new torrent row to the treeview"""
# Insert a new row to the liststore
row = self.liststore.append()
# Store the torrent id
self.liststore.set_value(
row,
self.columns["torrent_id"].column_indices[0],
torrent_id)
# Update the new row so
self.update_row(None, None, row)
def remove_row(self, torrent_id): def remove_row(self, torrent_id):
"""Removes a row with torrent_id""" """Removes a row with torrent_id"""
row = self.liststore.get_iter_first() row = self.liststore.get_iter_first()