Mercurial > MadButterfly
comparison 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 |
comparison
equal
deleted
inserted
replaced
1255:a8e01435e84e | 1256:8755415b5e99 |
---|---|
408 if ref is not None: | 408 if ref is not None: |
409 scene_node.setAttribute('ref', ref) | 409 scene_node.setAttribute('ref', ref) |
410 pass | 410 pass |
411 pass | 411 pass |
412 | 412 |
413 ## \brief Remove scene node from DOM-tree. | |
414 # | |
413 def rm_scene_node(self, scene_node): | 415 def rm_scene_node(self, scene_node): |
416 if not scene_node.parent(): | |
417 return # without this, may crash the Inkscape. | |
418 | |
414 self._scenes_node.removeChild(scene_node) | 419 self._scenes_node.removeChild(scene_node) |
415 for layer in self._layers: | 420 for layer in self._layers: |
416 try: | 421 try: |
417 layer.scenes.remove(scene_node) | 422 layer.scenes.remove(scene_node) |
418 except ValueError: # not in the list | 423 except ValueError: # not in the list |
420 else: | 425 else: |
421 break | 426 break |
422 pass | 427 pass |
423 pass | 428 pass |
424 | 429 |
430 ## \brief Remove scene node and asssociated scene group from DOM. | |
431 # | |
432 # It will remove as many as possible. Does not complain about | |
433 # error in the procedure of removing. | |
434 # | |
425 def rm_scene_node_n_group(self, scene_node): | 435 def rm_scene_node_n_group(self, scene_node): |
426 scene_group_id = scene_node.getAttribute('ref') | 436 scene_group_id = scene_node.getAttribute('ref') |
427 scene_group_node = self.get_node(scene_group_id) | 437 try: |
428 scene_group_node.parent().removeChild(scene_group_node) | 438 scene_group_node = self.get_node(scene_group_id) |
429 | 439 if scene_group_node.parent(): # Check it, or crash the |
430 self.rm_scene_node(scene_node) | 440 # Inkscape. |
441 scene_group_node.parent().removeChild(scene_group_node) | |
442 pass | |
443 except: | |
444 pass | |
445 | |
446 try: | |
447 self.rm_scene_node(scene_node) | |
448 except: | |
449 pass | |
431 pass | 450 pass |
432 | 451 |
433 ## \brief Create and add a svg:g for a scene under a group for a layer. | 452 ## \brief Create and add a svg:g for a scene under a group for a layer. |
434 # | 453 # |
435 def add_scene_group(self, layer_idx): | 454 def add_scene_group(self, layer_idx): |