diff pyink/domview.py @ 1256:8755415b5e99

More check for remvoing scene and scene group. - Without this check, it can make Inkscape crashed if we remove a node that had been removed. - Check whether it owns a parent node before removing. - A removed node has no parent node.
author Thinker K.F. Li <thinker@codemud.net>
date Tue, 11 Jan 2011 15:02:27 +0800
parents 07e0cb1e051d
children df474448364e
line wrap: on
line diff
--- a/pyink/domview.py	Tue Jan 11 12:35:28 2011 +0800
+++ b/pyink/domview.py	Tue Jan 11 15:02:27 2011 +0800
@@ -410,7 +410,12 @@
 	    pass
 	pass
 
+    ## \brief Remove scene node from DOM-tree.
+    #
     def rm_scene_node(self, scene_node):
+        if not scene_node.parent():
+            return              # without this, may crash the Inkscape.
+        
 	self._scenes_node.removeChild(scene_node)
         for layer in self._layers:
             try:
@@ -422,12 +427,26 @@
             pass
 	pass
 
+    ## \brief Remove scene node and asssociated scene group from DOM.
+    #
+    # It will remove as many as possible.  Does not complain about
+    # error in the procedure of removing.
+    #
     def rm_scene_node_n_group(self, scene_node):
 	scene_group_id = scene_node.getAttribute('ref')
-	scene_group_node = self.get_node(scene_group_id)
-	scene_group_node.parent().removeChild(scene_group_node)
+        try:
+            scene_group_node = self.get_node(scene_group_id)
+            if scene_group_node.parent(): # Check it, or crash the
+                                          # Inkscape.
+                scene_group_node.parent().removeChild(scene_group_node)
+                pass
+        except:
+            pass
 	
-        self.rm_scene_node(scene_node)
+        try:
+            self.rm_scene_node(scene_node)
+        except:
+            pass
 	pass
 
     ## \brief Create and add a svg:g for a scene under a group for a layer.