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_circulararray
# The module is used to prevent complaints from code checkers (flake8)
bool(Draft_rc.__name__)
class CircularArray(gui_base.GuiCommandBase):
"""Gui command for the CircularArray tool."""
def __init__(self):
super().__init__()
self.command_name = "Circular array"
super().__init__(name="CircularArray")
self.location = None
self.mouse_event = None
self.view = None
self.callback_move = None
self.callback_click = None
self.ui = None
@@ -61,9 +54,9 @@ class CircularArray(gui_base.GuiCommandBase):
def GetResources(self):
"""Set icon, menu and tooltip."""
return {'Pixmap': 'Draft_CircularArray',
'MenuText': QT_TRANSLATE_NOOP("Draft_CircularArray", "Circular array"),
'ToolTip': QT_TRANSLATE_NOOP("Draft_CircularArray", "Creates copies of the selected object, and places the copies in a radial pattern\ncreating various circular layers.\n\nThe array can be turned into an orthogonal or a polar array by changing its type.")}
return {"Pixmap": "Draft_CircularArray",
"MenuText": QT_TRANSLATE_NOOP("Draft_CircularArray", "Circular array"),
"ToolTip": QT_TRANSLATE_NOOP("Draft_CircularArray", "Creates copies of the selected object, and places the copies in a radial pattern\ncreating various circular layers.\n\nThe array can be turned into an orthogonal or a polar array by changing its type.")}
def Activated(self):
"""Execute when the command is called.
@@ -71,11 +64,10 @@ class CircularArray(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 = \
@@ -135,7 +127,7 @@ class CircularArray(gui_base.GuiCommandBase):
self.callback_click = None
if Gui.Control.activeDialog():
Gui.Control.closeDialog()
self.finish()
self.finish()
Gui.addCommand('Draft_CircularArray', CircularArray())