Skip to content
This repository was archived by the owner on Mar 1, 2025. It is now read-only.

Commit e40cab8

Browse files
committed
Draft: Fix finish behavior of Draft_Edit on doc close
Forum topic: https://forum.freecad.org/viewtopic.php?p=794746#p794746
1 parent d010645 commit e40cab8

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

src/Mod/Draft/draftguitools/gui_edit.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)