Clean-up torrentview.update_view() code.

This commit is contained in:
Andrew Resch 2008-10-21 10:23:42 +00:00
parent cb8125aa1b
commit 058c66bfa8
2 changed files with 13 additions and 30 deletions

View File

@ -242,13 +242,9 @@ class ListView:
def get_column_index(self, name): def get_column_index(self, name):
"""Get the liststore column indices belonging to this column. """Get the liststore column indices belonging to this column.
Will return a list if greater than 1 column. Will return a list.
""" """
# Only return as list if needed return self.columns[name].column_indices
if len(self.columns[name].column_indices) > 1:
return self.columns[name].column_indices
else:
return self.columns[name].column_indices[0]
def get_column_name(self, index): def get_column_name(self, index):
"""Get the header name for a liststore column index""" """Get the header name for a liststore column index"""

View File

@ -264,7 +264,7 @@ class TorrentView(listview.ListView, component.Component):
def update(self): def update(self):
# Send a status request # Send a status request
self.send_status_request() gobject.idle_add(self.send_status_request)
def update_view(self, columns=None): def update_view(self, columns=None):
"""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
@ -284,29 +284,16 @@ class TorrentView(listview.ListView, component.Component):
# Set values for each column in the row # Set values for each column in the row
for column in self.columns_to_update: for column in self.columns_to_update:
column_index = self.get_column_index(column) column_index = self.get_column_index(column)
if type(column_index) is not list: for index in column_index:
# We only have a single list store column we need to # Only update the column if the status field exists
# update
try: try:
# Only update if different # Only update if different
row_value = status[torrent_id][self.columns[column].status_field[0]] row_value = status[torrent_id][self.columns[column].status_field[column_index.index(index)]]
if row[column_index] != row_value: if row[index] != row_value:
row[column_index] = row_value row[index] = row_value
except (TypeError, KeyError), e: except Exception, e:
log.warning("Unable to update column %s: %s", log.debug("%s", e)
column, e)
else:
# We have more than 1 liststore column to update
for index in column_index:
# Only update the column if the status field exists
try:
# Only update if different
row_value = status[torrent_id][self.columns[column].status_field[column_index.index(index)]]
if row[index] != row_value:
row[index] = row_value
except:
pass
# Update the toolbar buttons just in case some state has changed # Update the toolbar buttons just in case some state has changed
component.get("ToolBar").update_buttons() component.get("ToolBar").update_buttons()
component.get("MenuBar").update_menu() component.get("MenuBar").update_menu()
@ -315,7 +302,7 @@ class TorrentView(listview.ListView, component.Component):
"""Callback function for get_torrents_status(). 'status' should be a """Callback function for get_torrents_status(). 'status' should be a
dictionary of {torrent_id: {key, value}}.""" dictionary of {torrent_id: {key, value}}."""
self.status = status self.status = status
self.update_view() gobject.idle_add(self.update_view)
def add_row(self, torrent_id, update=True): def add_row(self, torrent_id, update=True):
"""Adds a new torrent row to the treeview""" """Adds a new torrent row to the treeview"""
@ -341,7 +328,7 @@ class TorrentView(listview.ListView, component.Component):
def mark_dirty(self, torrent_id = None): def mark_dirty(self, torrent_id = None):
for row in self.liststore: for row in self.liststore:
if not torrent_id or row[self.columns["torrent_id"].column_indices[0]] == torrent_id: if not torrent_id or row[self.columns["torrent_id"].column_indices[0]] == torrent_id:
log.debug("marking %s dirty", torrent_id) #log.debug("marking %s dirty", torrent_id)
row[self.columns["dirty"].column_indices[0]] = True row[self.columns["dirty"].column_indices[0]] = True
if torrent_id: break if torrent_id: break