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
parent f185f19cfb
commit f3c80eb816
2 changed files with 71 additions and 110 deletions

View File

@ -69,7 +69,6 @@ class GtkUI:
self.torrentview.add_text_column("#",
col_type=int,
position=0,
get_function=self.column_get_function,
status_field=["queue"])
# Add a toolbar buttons
self.plugin.get_toolbar().add_separator()
@ -108,8 +107,3 @@ class GtkUI:
self.torrentview.update(["#"])
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
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",
listview.cell_data_size,
[long],
@ -104,9 +104,13 @@ class TorrentView(listview.ListView):
"""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)
# Iterates through every row and updates them accordingly
if self.liststore is not None:
self.liststore.foreach(self.update_row, columns)
def update_row(self, model, path, row, columns=None):
torrent_id = self.liststore.get_value(row,
self.columns["torrent_id"].column_indices[0])
# Store the 'status_fields' we need to send to core
status_keys = []
# Store the actual columns we will be updating
@ -162,54 +166,17 @@ class TorrentView(listview.ListView):
pass
i = i + 1
# Iterates through every row and updates them accordingly
if self.liststore is not None:
self.liststore.foreach(update_row, None)
def add_row(self, torrent_id):
"""Adds a new torrent row to the treeview"""
## REWRITE TO USE STATUS FIELDS
# Get the status and info dictionaries
status_keys = ["name", "total_size", "progress", "state",
"num_seeds", "num_peers", "download_payload_rate",
"upload_payload_rate", "eta"]
status = functions.get_torrent_status(self.core, torrent_id,
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
# plugins
for column in self.columns.values():
if column.get_function is not None:
if len(column.column_indices) == 1:
row_list.insert(column.column_indices[0],
column.get_function(torrent_id))
else:
result = column.get_function(torrent_id)
r_index = 0
for index in column.column_indices:
row_list.insert(index, result[r_index])
r_index = r_index + 1
# Insert the row with info provided from core
self.liststore.append(row_list)
# 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):
"""Removes a row with torrent_id"""