Fixed updating of the image view when loading a new query (ticket #47).
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 4 Sep 2004 18:51:32 +0000 (18:51 +0000)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 4 Sep 2004 18:51:32 +0000 (18:51 +0000)
src/gkofoto/gkofoto/objectcollection.py
src/gkofoto/gkofoto/singleobjectview.py
src/gkofoto/gkofoto/tableview.py

index c68c9ee..05bba1a 100644 (file)
@@ -21,6 +21,7 @@ class ObjectCollection(object):
         self.__insertionWorkerTag = None
         self.__registeredViews = []
         self.__disabledFields = Set()
+        self.__rowInsertedCallbacks = []
         self.__columnsType = [ gobject.TYPE_BOOLEAN,  # COLUMN_VALID_LOCATION
                                gobject.TYPE_BOOLEAN,  # COLUMN_VALID_CHECKSUM
                                gobject.TYPE_BOOLEAN,  # COLUMN_ROW_EDITABLE
@@ -101,6 +102,16 @@ class ObjectCollection(object):
     def getUnsortedModel(self):
         return self.__treeModel
 
+    def addInsertedRowCallback(self, callback, data=None):
+        self.__rowInsertedCallbacks.append((callback, data))
+
+    def removeInsertedRowCallback(self, callback, data=None):
+        self.__rowInsertedCallbacks.remove((callback, data))
+
+    def signalRowInserted(self):
+        for callback, data in self.__rowInsertedCallbacks:
+            callback(data)
+
     def convertToUnsortedRowNr(self, rowNr):
         return rowNr
 
@@ -259,6 +270,7 @@ class ObjectCollection(object):
                     column = self.__objectMetadataMap["@" + attribute][self.COLUMN_NR]
                     self.__treeModel.set_value(iterator, column, value)
             self.__treeModel.set_value(iterator, self.COLUMN_ROW_EDITABLE, True)
+            self.signalRowInserted()
             self.__loadThumbnail(self.__treeModel, iterator)
             location += 1
             yield True
index 4cd427d..8566926 100644 (file)
@@ -43,14 +43,13 @@ class SingleObjectView(ObjectCollectionView, ImageView):
                 if len(objectSelection) == 0:
                     # No objects is selected -> select first object
                     self.__selectedRowNr = 0
-                    objectSelection.setSelection([self.__selectedRowNr])
                 elif len(objectSelection) > 1:
                     # More than one object selected -> select first object
                     self.__selectedRowNr = objectSelection.getLowestSelectedRowNr()
-                    objectSelection.setSelection([self.__selectedRowNr])
                 else:
                     # Exactly one object selected
                     self.__selectedRowNr = objectSelection.getLowestSelectedRowNr()
+                objectSelection.setSelection([self.__selectedRowNr])
                 selectedObject = objectSelection[self.__selectedRowNr]
                 if selectedObject.isAlbum():
                     self.loadFile(env.albumIconFileName, False)
@@ -122,17 +121,17 @@ class SingleObjectView(ObjectCollectionView, ImageView):
         env.enter("SingleObjectView.freezeHelper()")
         self._clearAllConnections()
         self.clear()
+        self._objectCollection.removeInsertedRowCallback(self._modelUpdated)
         env.exit("SingleObjectView.freezeHelper()")
 
     def _thawHelper(self):
         env.enter("SingleObjectView.thawHelper()")
         model = self._objectCollection.getModel()
-        # The row_changed event is needed when the location attribute of the image object is changed.
-        self._connect(model, "row_changed", self._rowChanged)
-        # The following events are needed to update the previous and next navigation buttons.
+        # The following events are needed to update the previous and
+        # next navigation buttons.
         self._connect(model, "rows_reordered", self._modelUpdated)
-        self._connect(model, "row_inserted", self._modelUpdated)
         self._connect(model, "row_deleted", self._modelUpdated)
+        self._objectCollection.addInsertedRowCallback(self._modelUpdated)
         self.importSelection(self._objectCollection.getObjectSelection())
         env.exit("SingleObjectView.thawHelper()")
 
@@ -140,14 +139,6 @@ class SingleObjectView(ObjectCollectionView, ImageView):
         env.debug("SingleObjectView is handling model update")
         self.importSelection(self._objectCollection.getObjectSelection())
 
-    def _rowChanged(self, model, path, iter, arg, *unused):
-        if path[0] == self.__selectedRowNr:
-            env.debug("selected object in SingleObjectView changed")
-            objectSelection = self._objectCollection.getObjectSelection()
-            obj = objectSelection[path[0]]
-            if not obj.isAlbum():
-                self.loadFile(obj.getLocation(), True)
-
     def _goto(self, button, direction):
         objectSelection = self._objectCollection.getObjectSelection()
         objectSelection.setSelection([self.__selectedRowNr + direction])
index 1710148..f223bb3 100644 (file)
@@ -251,6 +251,7 @@ class TableView(ObjectCollectionView):
                                                               sourceRowNumber,
                                                               targetPath[0]))
                     model.insert_before(sibling=targetIter, row=sourceRow)
+                    self._objectCollection.signalRowInserted()
                     model.remove(sourceRow.iter)
                     # TODO update the album tree widget?
                 elif (dropPosition == gtk.TREE_VIEW_DROP_INTO_OR_AFTER