[Draft] Added Draft Snap Statusbar
.
This commit is contained in:
committed by
Yorik van Havre
parent
78a5036048
commit
77c385631b
@@ -140,7 +140,7 @@ class DraftWorkbench(FreeCADGui.Workbench):
|
||||
if hasattr(FreeCADGui, "Snapper"):
|
||||
FreeCADGui.Snapper.hide()
|
||||
import draftutils.init_draft_statusbar as dsb
|
||||
dsb.hide_draft_statusbar()
|
||||
dsb.hide_draft_statusbar()
|
||||
FreeCAD.Console.PrintLog("Draft workbench deactivated.\n")
|
||||
|
||||
def ContextMenu(self, recipient):
|
||||
|
||||
@@ -32,9 +32,9 @@ This module provide the code for the Draft Statusbar, activated by initGui
|
||||
|
||||
import FreeCAD as App
|
||||
import FreeCADGui as Gui
|
||||
from PySide import QtGui
|
||||
from PySide import QtCore, QtGui
|
||||
from PySide.QtCore import QT_TRANSLATE_NOOP
|
||||
|
||||
from draftutils.init_tools import get_draft_snap_commands
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# SCALE WIDGET FUNCTIONS
|
||||
@@ -124,7 +124,8 @@ def label_to_scale(label):
|
||||
return scale
|
||||
except:
|
||||
err = QT_TRANSLATE_NOOP("draft",
|
||||
"Unable to convert input into a scale factor")
|
||||
"Unable to convert input into a "
|
||||
"scale factor")
|
||||
App.Console.PrintWarning(err)
|
||||
return None
|
||||
|
||||
@@ -137,25 +138,34 @@ def _set_scale(action):
|
||||
|
||||
mw = Gui.getMainWindow()
|
||||
sb = mw.statusBar()
|
||||
statuswidget = sb.findChild(QtGui.QToolBar,"draft_status_widget")
|
||||
scale_widget = sb.findChild(QtGui.QToolBar,"draft_status_scale_widget")
|
||||
if action.text() == QT_TRANSLATE_NOOP("draft","custom"):
|
||||
dialog_text = QT_TRANSLATE_NOOP("draft",
|
||||
"Set custom annotation scale in format x:x, x=x"
|
||||
"Set custom annotation scale in "
|
||||
"format x:x, x=x"
|
||||
)
|
||||
custom_scale = QtGui.QInputDialog.getText(None, "Set custom scale", dialog_text)
|
||||
custom_scale = QtGui.QInputDialog.getText(None, "Set custom scale",
|
||||
dialog_text)
|
||||
if custom_scale[1]:
|
||||
print(custom_scale[0])
|
||||
scale = label_to_scale(custom_scale[0])
|
||||
if scale is None: return
|
||||
param.SetFloat("DraftAnnotationScale", scale)
|
||||
cs = scale_to_label(scale)
|
||||
statuswidget.scaleLabel.setText(cs)
|
||||
scale_widget.scaleLabel.setText(cs)
|
||||
else:
|
||||
text_scale = action.text()
|
||||
statuswidget.scaleLabel.setText(text_scale)
|
||||
scale_widget.scaleLabel.setText(text_scale)
|
||||
scale = label_to_scale(text_scale)
|
||||
param.SetFloat("DraftAnnotationScale", scale)
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# SNAP WIDGET FUNCTIONS
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
def toggle_ortho():
|
||||
Gui.runCommand('Draft_Snap_Ortho',0)
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# MAIN DRAFT STATUSBAR FUNCTIONS
|
||||
#----------------------------------------------------------------------------
|
||||
@@ -164,21 +174,131 @@ def init_draft_statusbar(sb):
|
||||
"""
|
||||
this function initializes draft statusbar
|
||||
"""
|
||||
param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
|
||||
|
||||
# SNAP WIDGET - init ----------------------------------------------------
|
||||
|
||||
statuswidget = QtGui.QToolBar()
|
||||
statuswidget.setObjectName("draft_status_widget")
|
||||
snap_widget = QtGui.QToolBar()
|
||||
snap_widget.setObjectName("draft_snap_widget")
|
||||
snap_widget.setIconSize(QtCore.QSize(16,16))
|
||||
|
||||
# GRID BUTTON - init
|
||||
gridbutton = QtGui.QPushButton(snap_widget)
|
||||
gridbutton.setIcon(QtGui.QIcon.fromTheme("Draft",
|
||||
QtGui.QIcon(":/icons/"
|
||||
"Draft_Grid.svg")))
|
||||
gridbutton.setToolTip(QT_TRANSLATE_NOOP("Draft",
|
||||
"Toggles Grid On/Off"))
|
||||
gridbutton.setObjectName("Grid_Statusbutton")
|
||||
gridbutton.setWhatsThis("Draft_ToggleGrid")
|
||||
gridbutton.setFlat(True)
|
||||
QtCore.QObject.connect(gridbutton,QtCore.SIGNAL("clicked()"),
|
||||
lambda f=Gui.doCommand,
|
||||
arg='Gui.runCommand("Draft_ToggleGrid")':f(arg))
|
||||
snap_widget.addWidget(gridbutton)
|
||||
|
||||
# SNAP BUTTON - init
|
||||
snappref = param.GetString("snapModes","111111111101111")[0]
|
||||
snapbutton = QtGui.QPushButton(snap_widget)
|
||||
snapbutton.setIcon(QtGui.QIcon.fromTheme("Draft",
|
||||
QtGui.QIcon(":/icons/"
|
||||
"Snap_Lock.svg")))
|
||||
snapbutton.setObjectName("Snap_Statusbutton")
|
||||
snapbutton.setWhatsThis("Draft_ToggleLockSnap")
|
||||
snapbutton.setToolTip(QT_TRANSLATE_NOOP("Draft",
|
||||
"Object snapping"))
|
||||
snapbutton.setCheckable(True)
|
||||
snapbutton.setChecked(bool(int(snappref)))
|
||||
snapbutton.setFlat(True)
|
||||
|
||||
snaps_menu = QtGui.QMenu(snapbutton)
|
||||
snaps_menu.setObjectName("draft_statusbar_snap_toolbar")
|
||||
|
||||
snap_gui_commands = get_draft_snap_commands()
|
||||
if 'Draft_Snap_Ortho' in snap_gui_commands:
|
||||
snap_gui_commands.remove('Draft_Snap_Ortho')
|
||||
if 'Draft_Snap_WorkingPlane' in snap_gui_commands:
|
||||
snap_gui_commands.remove('Draft_Snap_WorkingPlane')
|
||||
if 'Draft_Snap_Dimensions' in snap_gui_commands:
|
||||
snap_gui_commands.remove('Draft_Snap_Dimensions')
|
||||
Gui.Snapper.init_draft_snap_buttons(snap_gui_commands,snaps_menu, "_Statusbutton")
|
||||
Gui.Snapper.restore_snap_buttons_state(snaps_menu, "_Statusbutton")
|
||||
|
||||
snapbutton.setMenu(snaps_menu)
|
||||
snap_widget.addWidget(snapbutton)
|
||||
|
||||
|
||||
# DIMENSION BUTTON - init
|
||||
dimpref = param.GetString("snapModes","111111111101111")[13]
|
||||
dimbutton = QtGui.QPushButton(snap_widget)
|
||||
dimbutton.setIcon(QtGui.QIcon.fromTheme("Draft",
|
||||
QtGui.QIcon(":/icons/"
|
||||
"Snap_Dimensions.svg")))
|
||||
dimbutton.setToolTip(QT_TRANSLATE_NOOP("Draft",
|
||||
"Toggles Visual Aid Dimensions On/Off"))
|
||||
dimbutton.setObjectName("Draft_Snap_Dimensions_Statusbutton")
|
||||
dimbutton.setWhatsThis("Draft_ToggleDimensions")
|
||||
dimbutton.setFlat(True)
|
||||
dimbutton.setCheckable(True)
|
||||
dimbutton.setChecked(bool(int(dimpref)))
|
||||
QtCore.QObject.connect(dimbutton,QtCore.SIGNAL("clicked()"),
|
||||
lambda f=Gui.doCommand,
|
||||
arg='Gui.runCommand("Draft_Snap_Dimensions")':f(arg))
|
||||
snap_widget.addWidget(dimbutton)
|
||||
|
||||
# ORTHO BUTTON - init
|
||||
ortopref = param.GetString("snapModes","111111111101111")[10]
|
||||
orthobutton = QtGui.QPushButton(snap_widget)
|
||||
orthobutton.setIcon(QtGui.QIcon.fromTheme("Draft",
|
||||
QtGui.QIcon(":/icons/"
|
||||
"Snap_Ortho.svg")))
|
||||
orthobutton.setObjectName("Draft_Snap_Ortho"+"_Statusbutton")
|
||||
orthobutton.setWhatsThis("Draft_ToggleOrtho")
|
||||
orthobutton.setToolTip(QT_TRANSLATE_NOOP("Draft",
|
||||
"Toggles Ortho On/Off"))
|
||||
orthobutton.setFlat(True)
|
||||
orthobutton.setCheckable(True)
|
||||
orthobutton.setChecked(bool(int(ortopref)))
|
||||
QtCore.QObject.connect(orthobutton,QtCore.SIGNAL("clicked()"),
|
||||
lambda f=Gui.doCommand,
|
||||
arg='Gui.runCommand("Draft_Snap_Ortho")':f(arg))
|
||||
snap_widget.addWidget(orthobutton)
|
||||
|
||||
# WORKINGPLANE BUTTON - init
|
||||
wppref = param.GetString("snapModes","111111111101111")[14]
|
||||
wpbutton = QtGui.QPushButton(snap_widget)
|
||||
wpbutton.setIcon(QtGui.QIcon.fromTheme("Draft",
|
||||
QtGui.QIcon(":/icons/"
|
||||
"Snap_WorkingPlane.svg")))
|
||||
wpbutton.setObjectName("Draft_Snap_WorkingPlane_Statusbutton")
|
||||
wpbutton.setWhatsThis("Draft_ToggleWorkingPlaneSnap")
|
||||
wpbutton.setToolTip(QT_TRANSLATE_NOOP("Draft",
|
||||
"Toggles Constrain to Working Plane On/Off"))
|
||||
wpbutton.setFlat(True)
|
||||
wpbutton.setCheckable(True)
|
||||
wpbutton.setChecked(bool(int(wppref)))
|
||||
QtCore.QObject.connect(wpbutton,QtCore.SIGNAL("clicked()"),
|
||||
lambda f=Gui.doCommand,
|
||||
arg='Gui.runCommand("Draft_Snap_WorkingPlane")':f(arg))
|
||||
snap_widget.addWidget(wpbutton)
|
||||
|
||||
# add snap widget to the statusbar
|
||||
sb.insertPermanentWidget(2, snap_widget)
|
||||
snap_widget.show()
|
||||
|
||||
|
||||
# SCALE TOOL -------------------------------------------------------------
|
||||
# SCALE WIDGET ----------------------------------------------------------
|
||||
scale_widget = QtGui.QToolBar()
|
||||
scale_widget.setObjectName("draft_status_scale_widget")
|
||||
|
||||
# get scales list according to system units
|
||||
draft_scales = get_scales()
|
||||
|
||||
# get draft annotation scale
|
||||
param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
|
||||
draft_annotation_scale = param.GetFloat("DraftAnnotationScale", 1.0)
|
||||
|
||||
# initializes scale widget
|
||||
statuswidget.draft_scales = draft_scales
|
||||
scale_widget.draft_scales = draft_scales
|
||||
scaleLabel = QtGui.QPushButton("Scale")
|
||||
scaleLabel.setObjectName("ScaleLabel")
|
||||
scaleLabel.setFlat(True)
|
||||
@@ -194,12 +314,12 @@ def init_draft_statusbar(sb):
|
||||
scaleLabel.setText(scale_label)
|
||||
tooltip = "Set the scale used by draft annotation tools"
|
||||
scaleLabel.setToolTip(QT_TRANSLATE_NOOP("draft",tooltip))
|
||||
statuswidget.addWidget(scaleLabel)
|
||||
statuswidget.scaleLabel = scaleLabel
|
||||
scale_widget.addWidget(scaleLabel)
|
||||
scale_widget.scaleLabel = scaleLabel
|
||||
|
||||
# ADD TOOLS TO STATUS BAR ------------------------------------------------
|
||||
sb.addPermanentWidget(statuswidget)
|
||||
statuswidget.show()
|
||||
# add scale widget to the statusbar
|
||||
sb.insertPermanentWidget(3, scale_widget)
|
||||
scale_widget.show()
|
||||
|
||||
def show_draft_statusbar():
|
||||
"""
|
||||
@@ -208,25 +328,50 @@ def show_draft_statusbar():
|
||||
mw = Gui.getMainWindow()
|
||||
if mw:
|
||||
sb = mw.statusBar()
|
||||
statuswidget = sb.findChild(QtGui.QToolBar,"draft_status_widget")
|
||||
if statuswidget:
|
||||
statuswidget.show()
|
||||
|
||||
scale_widget = sb.findChild(QtGui.QToolBar,
|
||||
"draft_status_scale_widget")
|
||||
if scale_widget:
|
||||
scale_widget.show()
|
||||
else:
|
||||
init_draft_statusbar(sb)
|
||||
|
||||
snap_widget = sb.findChild(QtGui.QToolBar,"draft_snap_widget")
|
||||
if snap_widget:
|
||||
snap_widget.show()
|
||||
else:
|
||||
init_draft_statusbar(sb)
|
||||
|
||||
|
||||
def hide_draft_statusbar():
|
||||
"""
|
||||
hides draft statusbar if present
|
||||
"""
|
||||
mw = Gui.getMainWindow()
|
||||
if mw:
|
||||
sb = mw.statusBar()
|
||||
statuswidget = sb.findChild(QtGui.QToolBar,"draft_status_widget")
|
||||
if statuswidget:
|
||||
statuswidget.hide()
|
||||
else:
|
||||
# when switching workbenches, the toolbar sometimes "jumps"
|
||||
# out of the status bar to any other dock area...
|
||||
statuswidget = mw.findChild(QtGui.QToolBar,"draft_status_widget")
|
||||
if statuswidget:
|
||||
statuswidget.hide()
|
||||
if not mw:
|
||||
return
|
||||
sb = mw.statusBar()
|
||||
|
||||
# hide scale widget
|
||||
scale_widget = sb.findChild(QtGui.QToolBar,
|
||||
"draft_status_scale_widget")
|
||||
if scale_widget:
|
||||
scale_widget.hide()
|
||||
else:
|
||||
# when switching workbenches, the toolbar sometimes "jumps"
|
||||
# out of the status bar to any other dock area...
|
||||
scale_widget = mw.findChild(QtGui.QToolBar,
|
||||
"draft_status_scale_widget")
|
||||
if scale_widget:
|
||||
scale_widget.hide()
|
||||
|
||||
# hide snap widget
|
||||
snap_widget = sb.findChild(QtGui.QToolBar,"draft_snap_widget")
|
||||
if snap_widget:
|
||||
snap_widget.hide()
|
||||
else:
|
||||
# when switching workbenches, the toolbar sometimes "jumps"
|
||||
# out of the status bar to any other dock area...
|
||||
snap_widget = mw.findChild(QtGui.QToolBar,"draft_snap_widget")
|
||||
if snap_widget:
|
||||
snap_widget.hide()
|
||||
Reference in New Issue
Block a user