[POS-commit] Kiwi/Kiwi Delegates.py,1.122,1.123

Juan Pinazo pinazo at async.com.br
Wed Oct 15 20:58:07 BRST 2003


Update of /usr/local/cvssrc/Kiwi/Kiwi
In directory anthem:/tmp/cvs-serv30344/Kiwi

Modified Files:
	Delegates.py 
Log Message:
Adding a call to a progress handler to the add_list, for getting
information about the progress (in percentage) of the objects insertion
in the clist. r=kiko


Index: Delegates.py
===================================================================
RCS file: /usr/local/cvssrc/Kiwi/Kiwi/Delegates.py,v
retrieving revision 1.122
retrieving revision 1.123
diff -u -d -r1.122 -r1.123
--- Delegates.py	15 Oct 2003 03:55:41 -0000	1.122
+++ Delegates.py	15 Oct 2003 20:58:05 -0000	1.123
@@ -357,7 +357,8 @@
         """Returns the number of instances in the list"""
         return len(self._list)
 
-    def add_list(self, list, clear=TRUE, restore_selection=FALSE):
+    def add_list(self, list, clear=TRUE, restore_selection=FALSE,
+                 progress_handler=None):
         """
 Allows a list to be loaded in the CList, by default clearing it first.
 freeze() and thaw() are called internally to avoid flashing.
@@ -366,6 +367,8 @@
     - restore_selection: a boolean that specifies whether or not to
       try and preserve the original selection in the list (provided that
       at least some instances are still present in the new list.)
+    - progress_handler: a callback function to be called while the clist
+      is being filled
 
       There is a problem with select=TRUE and mode SELECTION_BROWSE. The
       focus_row is not updated, and the end result is that you have a
@@ -385,7 +388,7 @@
             clist.clear()
             self._list = [] # reset _list; this is required because 
                             # _load() does not reset it 
-        self._load(list)
+        self._load(list, progress_handler)
 
         # Avoid spurious selection or signal emissions when swapping
         # selection mode
@@ -633,7 +636,7 @@
             text.append(value)
         return text
 
-    def _load(self, l):
+    def _load(self, l, progress_handler=None):
         if not l: # do nothing if empty list or None provided
             return
 
@@ -658,17 +661,33 @@
         else:
             decimal = None
         convert = clist._get_column_converter(column)
+    
+        list_len = len(l)
+        # Call progress handler a total of 50 times or less
+        step = list_len / (50 % list_len or list_len)
+        i = 0
+
         _get_text = self._get_instance_text
         _get_row = clist._get_insert_sorted_row
         _insert = clist._raw_insert
         _set_row_data = clist.set_row_data
         _o = clist._o
+
         for item in l:
             text = _get_text(item)
             row = _get_row(text[column], column, decimal, convert=convert)
             _insert(_o, row, text)
             _set_row_data(row, item)
-    
+            if progress_handler is None:
+                continue
+            i = i + 1
+            if i % step: 
+                percent = i / float(list_len)
+                progress_handler(percent)
+
+        if progress_handler:
+            progress_handler(1)
+
         self._list = self._list + list(l)
         # End speed-hack
         # XXX XXX XXX XXX XXX XXX XXX



More information about the POS-commit mailing list