Skip to content

Commit

Permalink
Draft: reintroduced grid button in snap toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
carlopav authored and yorikvanhavre committed Apr 22, 2020
1 parent d59224a commit 18cfafe
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/Mod/Draft/draftguitools/gui_snapper.py
Expand Up @@ -1422,6 +1422,7 @@ def makeSnapToolBar(self):
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")
Expand All @@ -1443,6 +1444,15 @@ def init_draft_snap_buttons(self, commands, context, button_suffix):
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)
Expand All @@ -1464,6 +1474,18 @@ def init_draft_snap_buttons(self, commands, context, button_suffix):
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
Expand Down
6 changes: 4 additions & 2 deletions src/Mod/Draft/draftguitools/gui_snaps.py
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/Draft/draftutils/init_draft_statusbar.py
Expand Up @@ -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")

Expand Down
1 change: 1 addition & 0 deletions src/Mod/Draft/draftutils/init_tools.py
Expand Up @@ -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'
]


Expand Down

0 comments on commit 18cfafe

Please sign in to comment.