@@ -340,8 +340,11 @@ def finish(self, cont=False):
340340 self .running = False
341341 # delay resetting edit mode otherwise it doesn't happen
342342 from PySide import QtCore
343- QtCore .QTimer .singleShot (0 , Gui . ActiveDocument . resetEdit )
343+ QtCore .QTimer .singleShot (0 , self . reset_edit )
344344
345+ def reset_edit (self ):
346+ if Gui .ActiveDocument is not None :
347+ Gui .ActiveDocument .resetEdit ()
345348
346349 # -------------------------------------------------------------------------
347350 # SCENE EVENTS CALLBACKS
@@ -356,8 +359,12 @@ def unregister_selection_callback(self):
356359 """
357360 remove selection callback if it exists
358361 """
359- if self .selection_callback :
360- self .view .removeEventCallback ("SoEvent" , self .selection_callback )
362+ try :
363+ if self .selection_callback :
364+ self .view .removeEventCallback ("SoEvent" , self .selection_callback )
365+ except RuntimeError :
366+ # the view has been deleted already
367+ pass
361368 self .selection_callback = None
362369
363370 def register_editing_callbacks (self ):
@@ -380,18 +387,22 @@ def unregister_editing_callbacks(self):
380387 """
381388 remove callbacks used during editing if they exist
382389 """
383- if self ._keyPressedCB :
384- self .view .removeEventCallbackSWIG (coin .SoKeyboardEvent .getClassTypeId (), self ._keyPressedCB )
385- self ._keyPressedCB = None
386- #App.Console.PrintMessage("Draft edit keyboard callback unregistered \n")
387- if self ._mouseMovedCB :
388- self .view .removeEventCallbackSWIG (coin .SoLocation2Event .getClassTypeId (), self ._mouseMovedCB )
389- self ._mouseMovedCB = None
390- #App.Console.PrintMessage("Draft edit location callback unregistered \n")
391- if self ._mousePressedCB :
392- self .view .removeEventCallbackSWIG (coin .SoMouseButtonEvent .getClassTypeId (), self ._mousePressedCB )
393- self ._mousePressedCB = None
394- #App.Console.PrintMessage("Draft edit mouse button callback unregistered \n")
390+ try :
391+ if self ._keyPressedCB :
392+ self .view .removeEventCallbackSWIG (coin .SoKeyboardEvent .getClassTypeId (), self ._keyPressedCB )
393+ #App.Console.PrintMessage("Draft edit keyboard callback unregistered \n")
394+ if self ._mouseMovedCB :
395+ self .view .removeEventCallbackSWIG (coin .SoLocation2Event .getClassTypeId (), self ._mouseMovedCB )
396+ #App.Console.PrintMessage("Draft edit location callback unregistered \n")
397+ if self ._mousePressedCB :
398+ self .view .removeEventCallbackSWIG (coin .SoMouseButtonEvent .getClassTypeId (), self ._mousePressedCB )
399+ #App.Console.PrintMessage("Draft edit mouse button callback unregistered \n")
400+ except RuntimeError :
401+ # the view has been deleted already
402+ pass
403+ self ._keyPressedCB = None
404+ self ._mouseMovedCB = None
405+ self ._mousePressedCB = None
395406
396407 # -------------------------------------------------------------------------
397408 # SCENE EVENT HANDLERS
0 commit comments