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

Commit 32fa1f7

Browse files
authored
Merge pull request FreeCAD#18212 from Roy-043/Draft-Fix-finish-behavior-of-Draft_Edit-on-doc-close
Draft: Fix finish behavior of commands on doc close
2 parents 96c838f + 0ae35d6 commit 32fa1f7

File tree

9 files changed

+101
-61
lines changed

9 files changed

+101
-61
lines changed

src/Mod/Draft/draftguitools/gui_circulararray.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,15 @@ def completed(self):
124124
We should remove the callbacks that were added to the 3D view
125125
and then close the task panel.
126126
"""
127-
self.view.removeEventCallbackPivy(self.location,
128-
self.callback_move)
129-
self.view.removeEventCallbackPivy(self.mouse_event,
130-
self.callback_click)
131-
gui_utils.end_all_events()
127+
try:
128+
self.view.removeEventCallbackPivy(self.location, self.callback_move)
129+
self.view.removeEventCallbackPivy(self.mouse_event, self.callback_click)
130+
gui_utils.end_all_events()
131+
except RuntimeError:
132+
# the view has been deleted already
133+
pass
134+
self.callback_move = None
135+
self.callback_click = None
132136
if Gui.Control.activeDialog():
133137
Gui.Control.closeDialog()
134138
self.finish()

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

src/Mod/Draft/draftguitools/gui_orthoarray.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,13 @@ def completed(self):
111111
We should remove the callbacks that were added to the 3D view
112112
and then close the task panel.
113113
"""
114-
# self.view.removeEventCallbackPivy(self.location,
115-
# self.callback_move)
116-
self.view.removeEventCallbackPivy(self.mouse_event,
117-
self.callback_click)
118-
gui_utils.end_all_events()
114+
try:
115+
self.view.removeEventCallbackPivy(self.mouse_event, self.callback_click)
116+
gui_utils.end_all_events()
117+
except RuntimeError:
118+
# the view has been deleted already
119+
pass
120+
self.callback_click = None
119121
if Gui.Control.activeDialog():
120122
Gui.Control.closeDialog()
121123
self.finish()

src/Mod/Draft/draftguitools/gui_points.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,17 @@ def finish(self, cont=False):
143143
Restart (continue) the command if `True`, or if `None` and
144144
`ui.continueMode` is `True`.
145145
"""
146-
if self.callbackClick:
147-
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick)
148-
if self.callbackMove:
149-
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.callbackMove)
150-
if self.callbackClick or self.callbackMove:
151-
# Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
152-
gui_utils.end_all_events()
146+
try:
147+
if self.callbackClick:
148+
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick)
149+
if self.callbackMove:
150+
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.callbackMove)
151+
if self.callbackClick or self.callbackMove:
152+
# Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
153+
gui_utils.end_all_events()
154+
except RuntimeError:
155+
# the view has been deleted already
156+
pass
153157
self.callbackClick = None
154158
self.callbackMove = None
155159
super().finish()

src/Mod/Draft/draftguitools/gui_polararray.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,15 @@ def completed(self):
124124
We should remove the callbacks that were added to the 3D view
125125
and then close the task panel.
126126
"""
127-
self.view.removeEventCallbackPivy(self.location,
128-
self.callback_move)
129-
self.view.removeEventCallbackPivy(self.mouse_event,
130-
self.callback_click)
131-
gui_utils.end_all_events()
127+
try:
128+
self.view.removeEventCallbackPivy(self.location, self.callback_move)
129+
self.view.removeEventCallbackPivy(self.mouse_event, self.callback_click)
130+
gui_utils.end_all_events()
131+
except RuntimeError:
132+
# the view has been deleted already
133+
pass
134+
self.callback_move = None
135+
self.callback_click = None
132136
if Gui.Control.activeDialog():
133137
Gui.Control.closeDialog()
134138
self.finish()

src/Mod/Draft/draftguitools/gui_snapper.py

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,13 +1385,17 @@ def cb(point):
13851385
self.view = Draft.get3DView()
13861386

13871387
# remove any previous leftover callbacks
1388-
if self.callbackClick:
1389-
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick)
1390-
if self.callbackMove:
1391-
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.callbackMove)
1392-
if self.callbackClick or self.callbackMove:
1393-
# Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
1394-
gui_utils.end_all_events()
1388+
try:
1389+
if self.callbackClick:
1390+
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick)
1391+
if self.callbackMove:
1392+
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.callbackMove)
1393+
if self.callbackClick or self.callbackMove:
1394+
# Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
1395+
gui_utils.end_all_events()
1396+
except RuntimeError:
1397+
# the view has been deleted already
1398+
pass
13951399
self.callbackClick = None
13961400
self.callbackMove = None
13971401

@@ -1428,13 +1432,17 @@ def click(event_cb):
14281432
accept()
14291433

14301434
def accept():
1431-
if self.callbackClick:
1432-
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick)
1433-
if self.callbackMove:
1434-
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.callbackMove)
1435-
if self.callbackClick or self.callbackMove:
1436-
# Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
1437-
gui_utils.end_all_events()
1435+
try:
1436+
if self.callbackClick:
1437+
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick)
1438+
if self.callbackMove:
1439+
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.callbackMove)
1440+
if self.callbackClick or self.callbackMove:
1441+
# Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
1442+
gui_utils.end_all_events()
1443+
except RuntimeError:
1444+
# the view has been deleted already
1445+
pass
14381446
self.callbackClick = None
14391447
self.callbackMove = None
14401448
Gui.Snapper.off()
@@ -1450,13 +1458,17 @@ def accept():
14501458
self.pt = None
14511459

14521460
def cancel():
1453-
if self.callbackClick:
1454-
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick)
1455-
if self.callbackMove:
1456-
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.callbackMove)
1457-
if self.callbackClick or self.callbackMove:
1458-
# Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
1459-
gui_utils.end_all_events()
1461+
try:
1462+
if self.callbackClick:
1463+
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick)
1464+
if self.callbackMove:
1465+
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.callbackMove)
1466+
if self.callbackClick or self.callbackMove:
1467+
# Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
1468+
gui_utils.end_all_events()
1469+
except RuntimeError:
1470+
# the view has been deleted already
1471+
pass
14601472
self.callbackClick = None
14611473
self.callbackMove = None
14621474
Gui.Snapper.off()

src/Mod/Draft/drafttaskpanels/task_circulararray.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,8 @@ def finish(self):
478478
the delayed functions, and perform cleanup.
479479
"""
480480
# App.ActiveDocument.commitTransaction()
481-
Gui.ActiveDocument.resetEdit()
481+
if Gui.ActiveDocument is not None:
482+
Gui.ActiveDocument.resetEdit()
482483
# Runs the parent command to complete the call
483484
self.source_command.completed()
484485

src/Mod/Draft/drafttaskpanels/task_orthoarray.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ def finish(self):
386386
the delayed functions, and perform cleanup.
387387
"""
388388
# App.ActiveDocument.commitTransaction()
389-
Gui.ActiveDocument.resetEdit()
389+
if Gui.ActiveDocument is not None:
390+
Gui.ActiveDocument.resetEdit()
390391
# Runs the parent command to complete the call
391392
self.source_command.completed()
392393

src/Mod/Draft/drafttaskpanels/task_polararray.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ def finish(self):
431431
the delayed functions, and perform cleanup.
432432
"""
433433
# App.ActiveDocument.commitTransaction()
434-
Gui.ActiveDocument.resetEdit()
434+
if Gui.ActiveDocument is not None:
435+
Gui.ActiveDocument.resetEdit()
435436
# Runs the parent command to complete the call
436437
self.source_command.completed()
437438

0 commit comments

Comments
 (0)