Draft: improve Snap bar show-hide preference

This PR replaces the showSnapBar and hideSnapBar preferences with a single new preference: SnapBarShowOnlyDuringCommands.

Additonally:
Improved some param observer callbacks.
This commit is contained in:
Roy-043
2023-11-24 12:39:06 +01:00
committed by Yorik van Havre
parent 8298396350
commit a3f285cb46
5 changed files with 67 additions and 106 deletions

View File

@@ -247,38 +247,18 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_showSnapBar">
<widget class="Gui::PrefCheckBox" name="checkBox_SnapBarShowOnlyDuringCommands">
<property name="toolTip">
<string>If checked, the Snap toolbar will be shown whenever you use snapping</string>
<string>If checked, the Snap toolbar will only be visible during commands</string>
</property>
<property name="text">
<string>Show Draft snap toolbar</string>
<string>Only show the Draft snap toolbar during commands</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>showSnapBar</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_hideSnapBar">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>If checked, the Draft snap toolbar is hidden after use</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>hideSnapBar</cstring>
<cstring>SnapBarShowOnlyDuringCommands</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Draft</cstring>
@@ -402,7 +382,7 @@ if they match the X, Y or Z axis of the global coordinate system</string>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_gridEvery">
<property name="text">
@@ -448,7 +428,7 @@ if they match the X, Y or Z axis of the global coordinate system</string>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_gridSpacing">
<property name="text">
@@ -503,7 +483,7 @@ if they match the X, Y or Z axis of the global coordinate system</string>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="label_gridSize">
<property name="text">
@@ -555,7 +535,7 @@ if they match the X, Y or Z axis of the global coordinate system</string>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="label_gridColor_gridTransparency">
<property name="text">
@@ -636,7 +616,7 @@ if they match the X, Y or Z axis of the global coordinate system</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QLabel" name="label_DraftEditMaxObjects">
<property name="toolTip">
@@ -694,7 +674,7 @@ if they match the X, Y or Z axis of the global coordinate system</string>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QLabel" name="label_DraftEditPickRadius">
<property name="toolTip">
@@ -811,12 +791,6 @@ if they match the X, Y or Z axis of the global coordinate system</string>
<receiver>comboBox_modsnap</receiver>
<slot>setDisabled(bool)</slot>
</connection>
<connection>
<sender>checkBox_showSnapBar</sender>
<signal>toggled(bool)</signal>
<receiver>checkBox_hideSnapBar</receiver>
<slot>setEnabled(bool)</slot>
</connection>
<connection>
<sender>checkBox_alwaysShowGrid</sender>
<signal>toggled(bool)</signal>

View File

@@ -244,7 +244,7 @@ class Snapper:
self.spoint = None
if Draft.getParam("showSnapBar", True):
if Draft.getParam("SnapBarShowOnlyDuringCommands", False):
toolbar = self.get_snap_toolbar()
if toolbar:
toolbar.show()
@@ -1213,7 +1213,7 @@ class Snapper:
self.grid.lowerTracker()
def off(self, hideSnapBar=False):
def off(self):
"""Finish snapping."""
if self.tracker:
self.tracker.off()
@@ -1238,7 +1238,7 @@ class Snapper:
self.unconstrain()
self.radius = 0
self.setCursor()
if hideSnapBar or Draft.getParam("hideSnapBar", False):
if Draft.getParam("SnapBarShowOnlyDuringCommands", False):
toolbar = self.get_snap_toolbar()
if toolbar:
toolbar.hide()
@@ -1486,31 +1486,12 @@ class Snapper:
def get_snap_toolbar(self):
"""Get the snap toolbar."""
if not (hasattr(self, "toolbar") and self.toolbar):
mw = Gui.getMainWindow()
self.toolbar = mw.findChild(QtGui.QToolBar, "Draft snap")
if self.toolbar:
# Make sure the Python generated BIM snap toolbar shows up in the
# toolbar area context menu after switching back to that workbench:
self.toolbar.toggleViewAction().setVisible(True)
return self.toolbar
# Code required for the BIM workbench which has to work with FC0.20
# and FC0.21/1.0. The code relies on the Snapping menu in the BIM WB
# to create the actions.
self.toolbar = QtGui.QToolBar(mw)
mw.addToolBar(QtCore.Qt.TopToolBarArea, self.toolbar)
self.toolbar.setObjectName("Draft snap")
self.toolbar.setWindowTitle(translate("Workbench", "Draft snap"))
for cmd in get_draft_snap_commands():
if cmd == "Separator":
self.toolbar.addSeparator()
else:
action = Gui.Command.get(cmd).getAction()[0]
self.toolbar.addAction(action)
return self.toolbar
def toggleGrid(self):
"""Toggle FreeCAD Draft Grid."""
@@ -1593,24 +1574,12 @@ class Snapper:
def show(self):
"""Show the toolbar, show the grid in all 3D views where it was
previously visible, and start the trackers for the active 3D view
if it is `tracker-less`.
"""
toolbar = self.get_snap_toolbar()
if toolbar:
if Draft.getParam("showSnapBar", True):
toolbar.show()
else:
toolbar.hide()
"""Show the grid in all 3D views where it was previously visible."""
self.show_hide_grids(show=True)
def hide(self):
"""Hide the toolbar and hide the grid in all 3D views."""
if hasattr(self, "toolbar") and self.toolbar:
self.toolbar.hide()
self.toolbar.toggleViewAction().setVisible(False)
"""Hide the grid in all 3D views."""
self.show_hide_grids(show=False)

View File

@@ -282,7 +282,9 @@ class ShowSnapBar(Draft_Snap_Base):
def Activated(self):
"""Execute when the command is called."""
if hasattr(Gui, "Snapper"):
Gui.Snapper.show()
toolbar = Gui.Snapper.get_snap_toolbar()
if toolbar is not None:
toolbar.show()
Gui.addCommand('Draft_ShowSnapBar', ShowSnapBar())

View File

@@ -32,6 +32,7 @@ from draftutils import utils
from draftutils.translate import translate
from draftviewproviders import view_base
class ParamObserver:
def slotParamChanged(self, param, tp, name, value):
@@ -39,6 +40,9 @@ class ParamObserver:
"gridSpacing", "gridSize", "gridTransparency", "gridColor"):
_param_observer_callback_grid()
return
if name == "SnapBarShowOnlyDuringCommands":
_param_observer_callback_snapbar(value)
return
if name == "DisplayStatusbarSnapWidget":
_param_observer_callback_snapwidget()
return
@@ -73,28 +77,26 @@ def _param_observer_callback_grid():
pass
def _param_observer_callback_snapbar(value):
# value is a string: "0" or "1"
if Gui.activeWorkbench().name() not in ("DraftWorkbench", "ArchWorkbench", "BIMWorkbench"):
return
if hasattr(Gui, "Snapper"):
toolbar = Gui.Snapper.get_snap_toolbar()
if toolbar is not None:
toolbar.setVisible(value == "0")
def _param_observer_callback_snapwidget():
if Gui.activeWorkbench().name() == "DraftWorkbench":
init_draft_statusbar.hide_draft_statusbar()
init_draft_statusbar.show_draft_statusbar()
return
msg = translate("draft",
"""The Snap widget is only available in the Draft Workbench.
Switch to that workbench to see the result of this change.""")
QtGui.QMessageBox.information(None, "Update Draft statusbar widget", msg,
QtGui.QMessageBox.Ok)
def _param_observer_callback_scalewidget():
if Gui.activeWorkbench().name() == "DraftWorkbench":
init_draft_statusbar.hide_draft_statusbar()
init_draft_statusbar.show_draft_statusbar()
return
msg = translate("draft",
"""The Annotation scale widget is only available in the Draft Workbench.
Switch to that workbench to see the result of this change.""")
QtGui.QMessageBox.information(None, "Update Draft statusbar widget", msg,
QtGui.QMessageBox.Ok)
def _param_observer_callback_snapstyle():
@@ -112,6 +114,27 @@ def _param_observer_callback_svg_pattern():
utils.load_svg_patterns()
if App.ActiveDocument is None:
return
pats = list(utils.svg_patterns())
pats.sort()
pats = ["None"] + pats
data = []
for doc in App.listDocuments().values():
vobjs = []
for obj in doc.Objects:
if hasattr(obj, "ViewObject"):
vobj = obj.ViewObject
if hasattr(vobj, "Pattern") \
and hasattr(vobj, "Proxy") \
and isinstance(vobj.Proxy, view_base.ViewProviderDraft) \
and vobj.getEnumerationsOfProperty("Pattern") != pats:
vobjs.append(vobj)
if vobjs:
data.append([doc, vobjs])
if not data:
return
msg = translate("draft",
"""Do you want to update the SVG pattern options
of existing objects in all opened documents?""")
@@ -120,25 +143,18 @@ of existing objects in all opened documents?""")
QtGui.QMessageBox.No)
if res == QtGui.QMessageBox.No:
return
pats = list(utils.svg_patterns())
pats.sort()
pats = ["None"] + pats
for doc in App.listDocuments().values():
for doc, vobjs in data:
doc.openTransaction("SVG pattern update")
for obj in doc.Objects:
if hasattr(obj, "ViewObject") \
and hasattr(obj.ViewObject, "Pattern") \
and hasattr(obj.ViewObject, "Proxy") \
and isinstance(obj.ViewObject.Proxy, view_base.ViewProviderDraft):
vobj = obj.ViewObject
old = vobj.Pattern
if old in pats:
vobj.Pattern = pats
else:
tmp_pats = [old] + pats[1:]
tmp_pats.sort()
vobj.Pattern = ["None"] + tmp_pats
vobj.Pattern = old
for vobj in vobjs:
old = vobj.Pattern
if old in pats:
vobj.Pattern = pats
else:
tmp_pats = [old] + pats[1:]
tmp_pats.sort()
vobj.Pattern = ["None"] + tmp_pats
vobj.Pattern = old
doc.commitTransaction()

View File

@@ -185,8 +185,8 @@ def get_param_type(param):
return "float"
elif param in ("selectBaseObjects", "alwaysSnap", "grid",
"fillmode", "maxSnap", "DimShowLine",
"SvgLinesBlack", "dxfStdSize", "showSnapBar",
"hideSnapBar", "alwaysShowGrid", "renderPolylineWidth",
"SvgLinesBlack", "dxfStdSize", "SnapBarShowOnlyDuringCommands",
"alwaysShowGrid", "renderPolylineWidth",
"showPlaneTracker", "UsePartPrimitives",
"DiscretizeEllipses", "showUnit", "coloredGridAxes",
"Draft_array_fuse", "Draft_array_Link", "gridBorder"):