[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [arm/master] Decouple list wrapper class for use by other panels.



commit 2079780c2c6b90022dda02fac36059476f69eec5
Author: Kamran Riaz Khan <krkhan@xxxxxxxxxxxxxx>
Date:   Fri Jul 22 04:08:31 2011 +0500

    Decouple list wrapper class for use by other panels.
---
 src/gui/configPanel.py |   40 +---------------------------------
 src/util/gtkTools.py   |   54 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 38 deletions(-)

diff --git a/src/gui/configPanel.py b/src/gui/configPanel.py
index ff8ec86..46f9aa7 100644
--- a/src/gui/configPanel.py
+++ b/src/gui/configPanel.py
@@ -13,36 +13,8 @@ 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):
+class ConfContents(gtkTools.ListWrapper):
+  def _create_row_from_entry(self, entry):
     option = entry.get(Field.OPTION)
     value = entry.get(Field.VALUE)
     summary = entry.get(Field.SUMMARY)
@@ -51,14 +23,6 @@ class ConfContents(object):
 
     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)
diff --git a/src/util/gtkTools.py b/src/util/gtkTools.py
index 083fb5d..2d00621 100644
--- a/src/util/gtkTools.py
+++ b/src/util/gtkTools.py
@@ -2,6 +2,7 @@
 Helper module for getting Gtk+ theme colors.
 """
 
+import gobject
 import gtk
 
 COLOR_MAP = {
@@ -19,3 +20,56 @@ class Theme:
     for (key, (prop, state)) in COLOR_MAP.items():
       self.colors[key] = getattr(widget.style, prop)[state]
 
+class ListWrapper(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 __len__(self):
+    return len(self.container)
+
+  def __iadd__(self, other):
+    for entry in other:
+      self.append(entry)
+
+  def __delitem__(self, key):
+    del self.container[key]
+
+    gobject.idle_add(self.__model_del, key)
+
+  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 __model_append(self, entry):
+    row = self._create_row_from_entry(entry)
+    self.model.append(row)
+
+  def __model_del(self, key):
+    treeIter = self.model.get_iter(key)
+    self.model.remove(treeIter)
+
+  def __model_set(self, key, entry):
+    row = self._create_row_from_entry(entry)
+    self.model[key] = row
+
+  def _create_row_from_entry(self, entry):
+    raise NotImplementedError("Subclass must implement abstract method")
+



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits