Merge pull request #18212 from Roy-043/Draft-Fix-finish-behavior-of-Draft_Edit-on-doc-close

Draft: Fix finish behavior of commands on doc close
This commit is contained in:
Roy-043
2024-12-05 11:52:07 +01:00
committed by GitHub
9 changed files with 101 additions and 61 deletions

View File

@@ -124,11 +124,15 @@ class CircularArray(gui_base.GuiCommandBase):
We should remove the callbacks that were added to the 3D view
and then close the task panel.
"""
self.view.removeEventCallbackPivy(self.location,
self.callback_move)
self.view.removeEventCallbackPivy(self.mouse_event,
self.callback_click)
gui_utils.end_all_events()
try:
self.view.removeEventCallbackPivy(self.location, self.callback_move)
self.view.removeEventCallbackPivy(self.mouse_event, self.callback_click)
gui_utils.end_all_events()
except RuntimeError:
# the view has been deleted already
pass
self.callback_move = None
self.callback_click = None
if Gui.Control.activeDialog():
Gui.Control.closeDialog()
self.finish()

View File

@@ -340,8 +340,11 @@ class Edit(gui_base_original.Modifier):
self.running = False
# delay resetting edit mode otherwise it doesn't happen
from PySide import QtCore
QtCore.QTimer.singleShot(0, Gui.ActiveDocument.resetEdit)
QtCore.QTimer.singleShot(0, self.reset_edit)
def reset_edit(self):
if Gui.ActiveDocument is not None:
Gui.ActiveDocument.resetEdit()
# -------------------------------------------------------------------------
# SCENE EVENTS CALLBACKS
@@ -356,8 +359,12 @@ class Edit(gui_base_original.Modifier):
"""
remove selection callback if it exists
"""
if self.selection_callback:
self.view.removeEventCallback("SoEvent", self.selection_callback)
try:
if self.selection_callback:
self.view.removeEventCallback("SoEvent", self.selection_callback)
except RuntimeError:
# the view has been deleted already
pass
self.selection_callback = None
def register_editing_callbacks(self):
@@ -380,18 +387,22 @@ class Edit(gui_base_original.Modifier):
"""
remove callbacks used during editing if they exist
"""
if self._keyPressedCB:
self.view.removeEventCallbackSWIG(coin.SoKeyboardEvent.getClassTypeId(), self._keyPressedCB)
self._keyPressedCB = None
#App.Console.PrintMessage("Draft edit keyboard callback unregistered \n")
if self._mouseMovedCB:
self.view.removeEventCallbackSWIG(coin.SoLocation2Event.getClassTypeId(), self._mouseMovedCB)
self._mouseMovedCB = None
#App.Console.PrintMessage("Draft edit location callback unregistered \n")
if self._mousePressedCB:
self.view.removeEventCallbackSWIG(coin.SoMouseButtonEvent.getClassTypeId(), self._mousePressedCB)
self._mousePressedCB = None
#App.Console.PrintMessage("Draft edit mouse button callback unregistered \n")
try:
if self._keyPressedCB:
self.view.removeEventCallbackSWIG(coin.SoKeyboardEvent.getClassTypeId(), self._keyPressedCB)
#App.Console.PrintMessage("Draft edit keyboard callback unregistered \n")
if self._mouseMovedCB:
self.view.removeEventCallbackSWIG(coin.SoLocation2Event.getClassTypeId(), self._mouseMovedCB)
#App.Console.PrintMessage("Draft edit location callback unregistered \n")
if self._mousePressedCB:
self.view.removeEventCallbackSWIG(coin.SoMouseButtonEvent.getClassTypeId(), self._mousePressedCB)
#App.Console.PrintMessage("Draft edit mouse button callback unregistered \n")
except RuntimeError:
# the view has been deleted already
pass
self._keyPressedCB = None
self._mouseMovedCB = None
self._mousePressedCB = None
# -------------------------------------------------------------------------
# SCENE EVENT HANDLERS

View File

@@ -111,11 +111,13 @@ class OrthoArray(gui_base.GuiCommandBase):
We should remove the callbacks that were added to the 3D view
and then close the task panel.
"""
# self.view.removeEventCallbackPivy(self.location,
# self.callback_move)
self.view.removeEventCallbackPivy(self.mouse_event,
self.callback_click)
gui_utils.end_all_events()
try:
self.view.removeEventCallbackPivy(self.mouse_event, self.callback_click)
gui_utils.end_all_events()
except RuntimeError:
# the view has been deleted already
pass
self.callback_click = None
if Gui.Control.activeDialog():
Gui.Control.closeDialog()
self.finish()

View File

@@ -143,13 +143,17 @@ class Point(gui_base_original.Creator):
Restart (continue) the command if `True`, or if `None` and
`ui.continueMode` is `True`.
"""
if self.callbackClick:
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick)
if self.callbackMove:
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.callbackMove)
if self.callbackClick or self.callbackMove:
# Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
gui_utils.end_all_events()
try:
if self.callbackClick:
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick)
if self.callbackMove:
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.callbackMove)
if self.callbackClick or self.callbackMove:
# Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
gui_utils.end_all_events()
except RuntimeError:
# the view has been deleted already
pass
self.callbackClick = None
self.callbackMove = None
super().finish()

View File

@@ -124,11 +124,15 @@ class PolarArray(gui_base.GuiCommandBase):
We should remove the callbacks that were added to the 3D view
and then close the task panel.
"""
self.view.removeEventCallbackPivy(self.location,
self.callback_move)
self.view.removeEventCallbackPivy(self.mouse_event,
self.callback_click)
gui_utils.end_all_events()
try:
self.view.removeEventCallbackPivy(self.location, self.callback_move)
self.view.removeEventCallbackPivy(self.mouse_event, self.callback_click)
gui_utils.end_all_events()
except RuntimeError:
# the view has been deleted already
pass
self.callback_move = None
self.callback_click = None
if Gui.Control.activeDialog():
Gui.Control.closeDialog()
self.finish()

View File

@@ -1385,13 +1385,17 @@ class Snapper:
self.view = Draft.get3DView()
# remove any previous leftover callbacks
if self.callbackClick:
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick)
if self.callbackMove:
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.callbackMove)
if self.callbackClick or self.callbackMove:
# Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
gui_utils.end_all_events()
try:
if self.callbackClick:
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick)
if self.callbackMove:
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.callbackMove)
if self.callbackClick or self.callbackMove:
# Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
gui_utils.end_all_events()
except RuntimeError:
# the view has been deleted already
pass
self.callbackClick = None
self.callbackMove = None
@@ -1428,13 +1432,17 @@ class Snapper:
accept()
def accept():
if self.callbackClick:
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick)
if self.callbackMove:
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.callbackMove)
if self.callbackClick or self.callbackMove:
# Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
gui_utils.end_all_events()
try:
if self.callbackClick:
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick)
if self.callbackMove:
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.callbackMove)
if self.callbackClick or self.callbackMove:
# Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
gui_utils.end_all_events()
except RuntimeError:
# the view has been deleted already
pass
self.callbackClick = None
self.callbackMove = None
Gui.Snapper.off()
@@ -1450,13 +1458,17 @@ class Snapper:
self.pt = None
def cancel():
if self.callbackClick:
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick)
if self.callbackMove:
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.callbackMove)
if self.callbackClick or self.callbackMove:
# Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
gui_utils.end_all_events()
try:
if self.callbackClick:
self.view.removeEventCallbackPivy(coin.SoMouseButtonEvent.getClassTypeId(), self.callbackClick)
if self.callbackMove:
self.view.removeEventCallbackPivy(coin.SoLocation2Event.getClassTypeId(), self.callbackMove)
if self.callbackClick or self.callbackMove:
# Next line fixes https://github.com/FreeCAD/FreeCAD/issues/10469:
gui_utils.end_all_events()
except RuntimeError:
# the view has been deleted already
pass
self.callbackClick = None
self.callbackMove = None
Gui.Snapper.off()

View File

@@ -478,7 +478,8 @@ class TaskPanelCircularArray:
the delayed functions, and perform cleanup.
"""
# App.ActiveDocument.commitTransaction()
Gui.ActiveDocument.resetEdit()
if Gui.ActiveDocument is not None:
Gui.ActiveDocument.resetEdit()
# Runs the parent command to complete the call
self.source_command.completed()

View File

@@ -386,7 +386,8 @@ class TaskPanelOrthoArray:
the delayed functions, and perform cleanup.
"""
# App.ActiveDocument.commitTransaction()
Gui.ActiveDocument.resetEdit()
if Gui.ActiveDocument is not None:
Gui.ActiveDocument.resetEdit()
# Runs the parent command to complete the call
self.source_command.completed()

View File

@@ -431,7 +431,8 @@ class TaskPanelPolarArray:
the delayed functions, and perform cleanup.
"""
# App.ActiveDocument.commitTransaction()
Gui.ActiveDocument.resetEdit()
if Gui.ActiveDocument is not None:
Gui.ActiveDocument.resetEdit()
# Runs the parent command to complete the call
self.source_command.completed()