Load table view asynchronously. Closes ticket #26.
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 14 Aug 2004 21:48:32 +0000 (21:48 +0000)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 14 Aug 2004 21:48:32 +0000 (21:48 +0000)
src/gkofoto/gkofoto/albummembers.py
src/gkofoto/gkofoto/objectcollection.py
src/gkofoto/gkofoto/objectcollectionview.py

index 984dc6b..dfe4973 100644 (file)
@@ -20,7 +20,9 @@ class AlbumMembers(ObjectCollection):
         return self.__album and self.__album.isMutable()
 
     def isMutable(self):
-        return self.__album and self.__album.isMutable()
+        return (self.__album and
+                self.__album.isMutable() and
+                not self.isLoading())
 
     def getContainer(self):
         return self.__album
index 35f6767..3246c71 100644 (file)
@@ -18,6 +18,7 @@ class ObjectCollection(object):
     def __init__(self):
         env.debug("Init ObjectCollection")
         self.__objectSelection = ObjectSelection(self)
+        self.__insertionWorkerTag = None
         self.__registeredViews = []
         self.__disabledFields = Set()
         self.__columnsType = [ gobject.TYPE_BOOLEAN,  # COLUMN_VALID_LOCATION
@@ -49,7 +50,11 @@ class ObjectCollection(object):
 
     # Return true if objects may be added and removed from the collection.
     def isMutable(self):
-        return False
+        return not self.isLoading()
+
+    # Return true if object collection has not finished loading.
+    def isLoading(self):
+        return self.__insertionWorkerTag != None
 
     def getCutLabel(self):
         return "Cut reference"
@@ -120,6 +125,7 @@ class ObjectCollection(object):
         env.debug("Clearing object collection")
         if freeze:
             self._freezeViews()
+        self.__stopInsertionWorker()
         self.__treeModel.clear()
         gc.collect()
         self.__nrOfAlbums = 0
@@ -223,19 +229,17 @@ class ObjectCollection(object):
         env.exit("Object collection loading objects. (albums=" + str(self.__nrOfAlbums) + " images=" + str(self.__nrOfImages) + ")")
 
     def _insertObjectList(self, objectList, location=None):
-        widgets = gtk.glade.XML(env.gladeFile, "loadingProgressDialog")
-        loadingProgressDialog = widgets.get_widget(
-            "loadingProgressDialog")
-        loadingProgressDialog.show()
-        while gtk.events_pending():
-            gtk.main_iteration()
-
         # location = None means insert last, otherwise insert before
         # location.
         #
-        # Note that this methods does NOT update objectSelection.
+        # Note that this method does NOT update objectSelection.
+
         if location == None:
             location = len(self.__treeModel)
+        self.__insertionWorkerTag = gobject.idle_add(
+            self.__insertionWorker(objectList, location).next)
+
+    def __insertionWorker(self, objectList, location):
         for obj in objectList:
             iterator = self.__treeModel.insert(location)
             self.__treeModel.set_value(iterator, self.COLUMN_OBJECT_ID, obj.getId())
@@ -257,9 +261,19 @@ class ObjectCollection(object):
             self.__treeModel.set_value(iterator, self.COLUMN_ROW_EDITABLE, True)
             self.__loadThumbnail(self.__treeModel, iterator)
             location += 1
+            yield True
+
         self._handleNrOfObjectsUpdate()
+        self.__insertionWorkerFinished()
+        yield False
+
+    def __stopInsertionWorker(self):
+        if self.__insertionWorkerTag:
+            gobject.source_remove(self.__insertionWorkerTag)
+            self.__insertionWorkerFinished()
 
-        loadingProgressDialog.destroy()
+    def __insertionWorkerFinished(self):
+        self.__insertionWorkerTag = None
 
     def _handleNrOfObjectsUpdate(self):
         updatedDisabledFields = Set()
index 7f57d5c..16caae6 100644 (file)
@@ -145,6 +145,7 @@ class ObjectCollectionView:
         self.__objectMenuGroup[self._objectCollection.getDestroyLabel()].set_sensitive(False)
         env.widgets["menubarDestroy"].set_sensitive(False)
         mutable = self._objectCollection.isMutable()
+        loading = self._objectCollection.isLoading()
         objectSelection = self._objectCollection.getObjectSelection()
         if objectSelection:
             model = self._objectCollection.getModel()
@@ -165,13 +166,14 @@ class ObjectCollectionView:
                 else:
                     imagesSelected += 1
 
-            self.__clipboardMenuGroup[self._objectCollection.getCutLabel()].set_sensitive(mutable)
-            env.widgets["menubarCut"].set_sensitive(mutable)
+            modifiable = mutable and not loading
+            self.__clipboardMenuGroup[self._objectCollection.getCutLabel()].set_sensitive(mutable and not loading)
+            env.widgets["menubarCut"].set_sensitive(mutable and not loading)
             self.__clipboardMenuGroup[self._objectCollection.getCopyLabel()].set_sensitive(True)
             env.widgets["menubarCopy"].set_sensitive(True)
-            self.__clipboardMenuGroup[self._objectCollection.getDeleteLabel()].set_sensitive(mutable)
-            env.widgets["menubarDelete"].set_sensitive(mutable)
-            destroyActive = (imagesSelected == 0) ^ (albumsSelected == 0) and not rootAlbumSelected
+            self.__clipboardMenuGroup[self._objectCollection.getDeleteLabel()].set_sensitive(mutable and not loading)
+            env.widgets["menubarDelete"].set_sensitive(mutable and not loading)
+            destroyActive = (imagesSelected == 0) ^ (albumsSelected == 0) and not rootAlbumSelected and not loading
             self.__objectMenuGroup[self._objectCollection.getDestroyLabel()].set_sensitive(destroyActive)
             env.widgets["menubarDestroy"].set_sensitive(destroyActive)
             if albumsSelected == 1 and imagesSelected == 0: