[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.
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user