Draft: reintroduced grid button in snap toolbar

This commit is contained in:
carlopav
2020-04-22 09:15:48 +02:00
committed by Yorik van Havre
parent d59224a4be
commit 18cfafeed8
4 changed files with 30 additions and 2 deletions

View File

@@ -1422,6 +1422,7 @@ class Snapper:
self.toolbar.setObjectName("Draft Snap")
self.toolbar.setWindowTitle(QtCore.QCoreApplication.translate("Workbench", "Draft Snap"))
# make snap buttons
snap_gui_commands = get_draft_snap_commands()
self.init_draft_snap_buttons(snap_gui_commands, self.toolbar, "_Button")
self.restore_snap_buttons_state(self.toolbar,"_Button")
@@ -1443,6 +1444,15 @@ class Snapper:
to define the button name
"""
for gc in commands:
if gc == "Separator":
continue
if gc == "Draft_ToggleGrid":
gb = self.init_grid_button(self.toolbar)
context.addAction(gb)
QtCore.QObject.connect(gb, QtCore.SIGNAL("triggered()"),
lambda f=Gui.doCommand,
arg='Gui.runCommand("Draft_ToggleGrid")':f(arg))
continue
# setup toolbar buttons
command = 'Gui.runCommand("' + gc + '")'
b = QtGui.QAction(context)
@@ -1464,6 +1474,18 @@ class Snapper:
b.setStatusTip(b.toolTip())
def init_grid_button(self, context):
"""Add grid button to the given toolbar"""
b = QtGui.QAction(context)
b.setIcon(QtGui.QIcon.fromTheme("Draft", QtGui.QIcon(":/icons/"
"Draft_Grid.svg")))
b.setText(QtCore.QCoreApplication.translate("Draft_Snap", "Toggles Grid On/Off"))
b.setToolTip(QtCore.QCoreApplication.translate("Draft_Snap", "Toggle Draft Grid"))
b.setObjectName("Grid_Button")
b.setWhatsThis("Draft_ToggleGrid")
return b
def restore_snap_buttons_state(self, toolbar, button_suffix):
"""
Restore toolbar button's checked state according to

View File

@@ -61,7 +61,8 @@ def sync_snap_toolbar_button(button, status):
# for lock button
snap_toolbar.actions()[0].setChecked(status)
for a in snap_toolbar.actions()[1:]:
a.setEnabled(status)
if a.objectName()[:10] == "Draft_Snap":
a.setEnabled(status)
else:
# for every other button
a.setChecked(status)
@@ -86,7 +87,8 @@ def sync_snap_statusbar_button(button, status):
if button == "Draft_Snap_Lock_Statusbutton":
ssb.setChecked(status)
for a in actions[1:]:
a.setEnabled(status)
if a.objectName()[:10] == "Draft_Snap":
a.setEnabled(status)
else:
for a in actions:
if a.objectName() == button:

View File

@@ -217,6 +217,9 @@ def init_draft_statusbar(sb):
snap_gui_commands.remove('Draft_Snap_WorkingPlane')
if 'Draft_Snap_Dimensions' in snap_gui_commands:
snap_gui_commands.remove('Draft_Snap_Dimensions')
if 'Draft_ToggleGrid' in snap_gui_commands:
snap_gui_commands.remove('Draft_ToggleGrid')
Gui.Snapper.init_draft_snap_buttons(snap_gui_commands,snaps_menu, "_Statusbutton")
Gui.Snapper.restore_snap_buttons_state(snaps_menu, "_Statusbutton")

View File

@@ -123,6 +123,7 @@ def get_draft_snap_commands():
'Draft_Snap_Special', 'Draft_Snap_Near',
'Draft_Snap_Ortho', 'Draft_Snap_Grid',
'Draft_Snap_WorkingPlane', 'Draft_Snap_Dimensions',
'Separator', 'Draft_ToggleGrid'
]