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:
42
src/Mod/Draft/draftutils/doc_observer.py
Normal file
42
src/Mod/Draft/draftutils/doc_observer.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import FreeCAD as App
|
||||
|
||||
if App.GuiUp:
|
||||
import FreeCADGui as Gui
|
||||
from draftutils.todo import ToDo
|
||||
|
||||
class _Draft_DocObserver():
|
||||
|
||||
# See: /src/Gui/DocumentObserverPython.h
|
||||
|
||||
def slotDeletedDocument(self, gui_doc):
|
||||
_finish_command_on_doc_close(gui_doc)
|
||||
|
||||
_doc_observer = None
|
||||
|
||||
def _doc_observer_start():
|
||||
global _doc_observer
|
||||
if _doc_observer is None:
|
||||
_doc_observer = _Draft_DocObserver()
|
||||
Gui.addDocumentObserver(_doc_observer)
|
||||
|
||||
def _doc_observer_stop():
|
||||
global _doc_observer
|
||||
try:
|
||||
if _doc_observer is not None:
|
||||
Gui.removeDocumentObserver(_doc_observer)
|
||||
except:
|
||||
pass
|
||||
_doc_observer = None
|
||||
|
||||
def _finish_command_on_doc_close(gui_doc):
|
||||
"""Finish the active Draft or BIM command if the related document has been
|
||||
closed. Only works for commands that have set `App.activeDraftCommand.doc`
|
||||
and use a task panel.
|
||||
"""
|
||||
if getattr(App, "activeDraftCommand", None) \
|
||||
and getattr(App.activeDraftCommand, "doc", None) == gui_doc.Document \
|
||||
and getattr(App.activeDraftCommand, "ui", None):
|
||||
if hasattr(App.activeDraftCommand.ui, "reject"):
|
||||
ToDo.delay(App.activeDraftCommand.ui.reject, None)
|
||||
elif hasattr(App.activeDraftCommand.ui, "escape"):
|
||||
ToDo.delay(App.activeDraftCommand.ui.escape, None)
|
||||
Reference in New Issue
Block a user