diff --git a/src/dgtk.py b/src/dgtk.py index 0443a9419..ffb17124f 100644 --- a/src/dgtk.py +++ b/src/dgtk.py @@ -31,12 +31,12 @@ # Similar to common, this contains any common functions # related to gtk that are needed by the client +from itertools import izip + import common -import gettext import pygtk pygtk.require('2.0') import gtk -import gtk.glade # This is a dummy tray object to allow Deluge to run on PyGTK < 2.9 class StupidTray: @@ -138,3 +138,28 @@ def add_texticon_column(view, header, icon_col, text_col): column.add_attribute(render, 'text', text_col) view.append_column(column) return column + +def update_store(store, iter, cols, new_values): + """gtk.ListStore update function + + Arguments: + store - gtk.ListStore instance + iter - a valid gtk.TreeIter for the row being modified + cols - iterable containing indexes of columns to change + new_values - iterable with new values for specified columns + + Example: + update_store(file_store, iter, (1, 3), ('test.txt', 9940)) + + """ + + old_values = store.get(iter, *cols) + + for col, old_value, new_value in izip(cols, old_values, new_values): + try: + # equality check because formatting and cell renderer functions + # called on self.torrent_model.set_value() are expensive + if old_value != new_value: + store.set_value(iter, col, new_value) + except: + print "ERR", col, type(new_value), new_value diff --git a/src/files.py b/src/files.py index 9c7fbfb2b..6b70ab46a 100644 --- a/src/files.py +++ b/src/files.py @@ -34,6 +34,7 @@ from itertools import izip import gobject import gtk +import gtk.glade import common import dgtk @@ -180,8 +181,8 @@ class FilesTabManager(FilesBaseManager): new_file_info = self.manager.get_torrent_file_info(self.file_unique_id) for file in new_file_info: iter = self.file_store_dict[file['path']] - if self.file_store.get_value(iter, 3) != round(file['progress'], 2): - self.file_store.set(iter, 3, file['progress']) + dgtk.update_store(self.file_store, iter, (3,), + (round(file['progress'], 2),)) # From UI to core def update_priorities(self): diff --git a/src/interface.py b/src/interface.py index fb9dd6b03..bedbf5851 100644 --- a/src/interface.py +++ b/src/interface.py @@ -837,16 +837,6 @@ class DelugeGTK: ## Call via a timer to update the interface def update(self): - def torrent_model_update(itr, col, new_value): - try: - # equality check because formatting and cell renderer - # functions called on self.torrent_model.set_value() are - # expensive - if self.torrent_model.get_value(itr, col) != new_value: - self.torrent_model.set_value(itr, col, new_value) - except: - print "ERR", col, type(new_value), new_value - # We need to apply the queue changes self.manager.apply_queue() @@ -921,15 +911,13 @@ class DelugeGTK: # For previosly and still paused torrents update only # queue pos and selected files size, all the rest # columns are unchanged for them. - for i, new_value in izip((1, 4), - (state['queue_pos'], - state['total_wanted'])): - torrent_model_update(itr, i, new_value) + dgtk.update_store(self.torrent_model, itr, (1, 4), + (state['queue_pos'], + state['total_wanted'])) else: tlist = self.get_torrent_state_list(unique_id, state) - - for i, new_value in enumerate(tlist): - torrent_model_update(itr, i, new_value) + dgtk.update_store(self.torrent_model, itr, + xrange(len(tlist)), tlist) itr = self.torrent_model.iter_next(itr) @@ -1085,11 +1073,12 @@ class DelugeGTK: for peer in new_peer_info: # Update peers already in peers list if peer['ip'] in self.peer_store_dict: - self.peer_store.set(self.peer_store_dict[peer['ip']], - 2, unicode(peer['client'], "latin-1"), - 3, round(peer["peer_has"], 2), - 4, peer["download_speed"], - 5, peer["upload_speed"]) + iter = self.peer_store_dict[peer['ip']] + + dgtk.update_store(self.peer_store, iter, (3, 4, 5), + (round(peer["peer_has"], 2), + peer["download_speed"], + peer["upload_speed"])) if peer['client'] != "": new_ips.add(peer['ip'])