Draft: move statusbar widget hide delay to init_draft_statusbar.py

With this PR both the delays for `show_draft_statusbar` and `hide_draft_statusbar` are defined in the same file. This is more consistent.
This commit is contained in:
Roy-043
2025-03-21 20:29:36 +01:00
parent 176f91eea8
commit a3fd3bc546
2 changed files with 38 additions and 24 deletions

View File

@@ -167,10 +167,7 @@ class DraftWorkbench(FreeCADGui.Workbench):
FreeCADGui.Snapper.hide()
from PySide import QtCore
from draftutils import init_draft_statusbar
# Delay required in case the Draft WB is preloaded,
# else show_draft_statusbar will not yet be done:
t = QtCore.QTimer()
t.singleShot(700, init_draft_statusbar.hide_draft_statusbar)
init_draft_statusbar.hide_draft_statusbar()
import WorkingPlane
WorkingPlane._view_observer_stop()
from draftutils import grid_observer

View File

@@ -287,6 +287,38 @@ def init_draft_statusbar_snap():
snap_action.addAction(Gui.Command.get(cmd).getAction()[0])
def hide_draft_statusbar_scale():
"""
hides draft statusbar scale widget
"""
mw = Gui.getMainWindow()
sb = mw.statusBar()
scale_widget = sb.findChild(QtWidgets.QToolBar, "draft_scale_widget")
if scale_widget is None:
# when switching workbenches, the toolbar sometimes "jumps"
# out of the status bar to any other dock area...
scale_widget = mw.findChild(QtWidgets.QToolBar, "draft_scale_widget")
if scale_widget:
scale_widget.hide()
def hide_draft_statusbar_snap():
"""
hides draft statusbar snap widget
"""
mw = Gui.getMainWindow()
sb = mw.statusBar()
snap_widget = sb.findChild(QtWidgets.QToolBar,"draft_snap_widget")
if snap_widget is None:
# when switching workbenches, the toolbar sometimes "jumps"
# out of the status bar to any other dock area...
snap_widget = mw.findChild(QtWidgets.QToolBar,"draft_snap_widget")
if snap_widget:
snap_widget.hide()
def show_draft_statusbar():
"""
shows draft statusbar if present or initializes it
@@ -327,25 +359,10 @@ def hide_draft_statusbar():
"""
hides draft statusbar if present
"""
mw = Gui.getMainWindow()
sb = mw.statusBar()
# hide scale widget
scale_widget = sb.findChild(QtWidgets.QToolBar, "draft_scale_widget")
if scale_widget is None:
# when switching workbenches, the toolbar sometimes "jumps"
# out of the status bar to any other dock area...
scale_widget = mw.findChild(QtWidgets.QToolBar, "draft_scale_widget")
if scale_widget:
scale_widget.hide()
# hide snap widget
snap_widget = sb.findChild(QtWidgets.QToolBar,"draft_snap_widget")
if snap_widget is None:
# when switching workbenches, the toolbar sometimes "jumps"
# out of the status bar to any other dock area...
snap_widget = mw.findChild(QtWidgets.QToolBar,"draft_snap_widget")
if snap_widget:
snap_widget.hide()
# Delay required in case the Draft WB is autoloaded,
# else show_draft_statusbar will not yet be done.
t = QtCore.QTimer()
t.singleShot(500, hide_draft_statusbar_scale)
t.singleShot(500, hide_draft_statusbar_snap)
## @}