From 58a6f05956cb8a4591c65d5197ac91e13b7a2415 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sun, 28 Feb 2021 21:42:46 -0600 Subject: [PATCH] [DRAFT] Refactor sync_snap_toolbar_button LGTM objected to the re-use of the loop variable a in the algorithm. Upon closer inspection, the algorithm in this function could be modified to match the algorithm in sync_snap_statusbar_button (which does the same thing to the statusbar that this does to the toolbar). This eliminates the double-use. This change does not affect the functionality of the routine. --- src/Mod/Draft/draftguitools/gui_snaps.py | 30 +++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Mod/Draft/draftguitools/gui_snaps.py b/src/Mod/Draft/draftguitools/gui_snaps.py index 2496965202..c1c05112b8 100644 --- a/src/Mod/Draft/draftguitools/gui_snaps.py +++ b/src/Mod/Draft/draftguitools/gui_snaps.py @@ -56,21 +56,23 @@ def sync_snap_toolbar_button(button, status): snap_toolbar = Gui.Snapper.get_snap_toolbar() if not snap_toolbar: return - for a in snap_toolbar.actions(): - if a.objectName() == button: - if button == "Draft_Snap_Lock_Button": - # for lock button - snap_toolbar.actions()[0].setChecked(status) - for a in snap_toolbar.actions()[1:]: - if a.objectName()[:10] == "Draft_Snap": - a.setEnabled(status) - else: - # for every other button - a.setChecked(status) - if a.isChecked(): - a.setToolTip(a.toolTip().replace("OFF","ON")) + + # Setting the snap lock button enables or disables all of the other snap actions: + if button == "Draft_Snap_Lock_Button": + snap_toolbar.actions()[0].setChecked(status) # Snap lock must be the first button + for action in snap_toolbar.actions()[1:]: + if action.objectName()[:10] == "Draft_Snap": + action.setEnabled(status) + + # All other buttons only affect themselves + else: + for action in snap_toolbar.actions(): + if action.objectName() == button: + action.setChecked(status) + if action.isChecked(): + action.setToolTip(a.toolTip().replace("OFF","ON")) else: - a.setToolTip(a.toolTip().replace("ON","OFF")) + action.setToolTip(a.toolTip().replace("ON","OFF")) def sync_snap_statusbar_button(button, status):