commit 2526e7160753d5953df392a8c6fde1197f63e4d9 Author: Kamran Riaz Khan krkhan@inspirated.com Date: Fri Jul 22 03:03:25 2011 +0500
Replace "interval updates" by consistent list->model mapping.
The CLI config panel stored entries in ConfigPanel.confImportantContents which were regularly polled and exported to GUI treestore.
This created problems with selections as the liststore was essentially emptied at each timeout.
The new approach is to override ConfigPanel.confImportantContents with a wrapper class which maintains consistency between the Python list and GUI liststore at each append/setitem. --- src/gui/configPanel.py | 72 ++++++++++++++++++++++++++++++++---------------- 1 files changed, 48 insertions(+), 24 deletions(-)
diff --git a/src/gui/configPanel.py b/src/gui/configPanel.py index 4001058..ff8ec86 100644 --- a/src/gui/configPanel.py +++ b/src/gui/configPanel.py @@ -13,40 +13,65 @@ from cli.configPanel import (ConfigPanel as CliConfigPanel, Field, State) from util import connections, gtkTools, sysTools, torTools, uiTools from TorCtl import TorCtl
+class ConfContents(object): + def __init__(self, container, model): + self.container = [] + self.model = model + + for entry in container: + self.append(entry) + + def append(self, entry): + self.container.append(entry) + gobject.idle_add(self.__model_append, entry) + + def __str__(self): + return str(self.container) + + def __repr__(self): + return str(self.container) + + def __getitem__(self, key): + return self.container[key] + + def __setitem__(self, key, entry): + self.container[key] = entry + + gobject.idle_add(self.__model_set, key, entry) + + def __len__(self): + return len(self.container) + + def __create_row_from_entry(self, entry): + option = entry.get(Field.OPTION) + value = entry.get(Field.VALUE) + summary = entry.get(Field.SUMMARY) + desc = entry.get(Field.DESCRIPTION) + row = (option, value, summary, '#368918', desc) + + return row + + def __model_append(self, entry): + row = self.__create_row_from_entry(entry) + self.model.append(row) + + def __model_set(self, key, entry): + row = self.__create_row_from_entry(entry) + self.model[key] = row + class ConfigPanel(CliConfigPanel): def __init__(self, builder): CliConfigPanel.__init__(self, None, State.TOR)
self.builder = builder
- gobject.idle_add(self._fill_entries) - gobject.timeout_add(3000, self._timeout_fill_entries) + listStore = self.builder.get_object('liststore_config') + self.confImportantContents = ConfContents(self.confImportantContents, listStore)
def pack_widgets(self): treeView = self.builder.get_object('treeview_config') treeView.connect('cursor-changed', self.on_treeview_config_cursor_changed)
- def _timeout_fill_entries(self): - self._fill_entries() - - return True - - def _fill_entries(self): - self.valsLock.acquire() - - listStore = self.builder.get_object('liststore_config') - listStore.clear() - - for entry in self._getConfigOptions(): - option = entry.get(Field.OPTION) - value = entry.get(Field.VALUE) - summary = entry.get(Field.SUMMARY) - desc = entry.get(Field.DESCRIPTION) - row = (option, value, summary, '#368918', desc) - listStore.append(row) - - self.valsLock.release() - def on_treeview_config_cursor_changed(self, widget, data=None): treeSelection = widget.get_selection()
@@ -55,5 +80,4 @@ class ConfigPanel(CliConfigPanel):
textBuffer = self.builder.get_object('textbuffer_config_desc') textBuffer.set_text(desc) - print desc
tor-commits@lists.torproject.org