Draft: close task panels on doc close

Related: #17952.

This PR introduces a document observer to close task panels on doc close.

For now it is for the Draft Workbench only. The BIM Workbench will be dealt with in a future PR.

The basic code is simple, but to make things works some additional things were addressed:
* gui_base.py: the GuiCommandBase class was enhanced to handle App.activeDraftCommand, self.doc, self.view and self.planetracker. Strictly speaking only the first 2 are required for this PR.
* gui_base.py: self.command_name was changed to self.featureName for compatibility with gui_base_original.py. Not required for this PR.
* gui_arcs.py, gui_circulararray.py, gui_polararray.py and gui_orthoarray.py: updated in relation to the GuiCommandBase class.
* gui_arcs.py Arc_3Points: The command now has a ui property and shows a plane tracker. Only the first is required for this PR.
* gui_shapestrings.py: This command had two ui attributes: self.ui and self.task. This was problematic. To fix this the base class of the command was changed from gui_base_original.Creator to gui_base.GuiCommandBase. As a result the getStrings method is no longer available meaning that the useSupport parameter is ignored when creating a ShapeString. But since that mechanism does not work properly anyway, I feel that this is acceptable. Should many user complain the functionality can of course be reintroduced.
This commit is contained in:
Roy-043
2025-04-09 12:04:02 +02:00
committed by Chris Hennes
parent 0009ddbd0b
commit ca340da86c
10 changed files with 146 additions and 115 deletions

View File

@@ -32,8 +32,6 @@ from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD as App
import FreeCADGui as Gui
import Draft
import Draft_rc # include resources, icons, ui files
from draftguitools import gui_base
from draftutils import gui_utils
from draftutils import todo
@@ -41,19 +39,14 @@ from draftutils.messages import _log
from draftutils.translate import translate
from drafttaskpanels import task_orthoarray
# The module is used to prevent complaints from code checkers (flake8)
bool(Draft_rc.__name__)
class OrthoArray(gui_base.GuiCommandBase):
"""Gui command for the OrthoArray tool."""
def __init__(self):
super().__init__()
self.command_name = "Orthogonal array"
super().__init__(name="OrthoArray")
# self.location = None
self.mouse_event = None
self.view = None
# self.callback_move = None
self.callback_click = None
self.ui = None
@@ -71,11 +64,10 @@ class OrthoArray(gui_base.GuiCommandBase):
We add callbacks that connect the 3D view with
the widgets of the task panel.
"""
_log("GuiCommand: {}".format(self.command_name))
super().Activated()
# self.location = coin.SoLocation2Event.getClassTypeId()
self.mouse_event = coin.SoMouseButtonEvent.getClassTypeId()
self.view = Draft.get3DView()
# self.callback_move = \
# self.view.addEventCallbackPivy(self.location, self.move)
self.callback_click = \
@@ -120,7 +112,7 @@ class OrthoArray(gui_base.GuiCommandBase):
self.callback_click = None
if Gui.Control.activeDialog():
Gui.Control.closeDialog()
self.finish()
self.finish()
Gui.addCommand('Draft_OrthoArray', OrthoArray())