Merge pull request #5108 from Roy-043/Draft-fix-context-menu

Draft: fix context menu
This commit is contained in:
Yorik van Havre
2021-10-13 11:43:12 +02:00
committed by GitHub
5 changed files with 11 additions and 202 deletions

View File

@@ -265,7 +265,6 @@ SET(Draft_GUI_tools
draftguitools/gui_edit_part_objects.py
draftguitools/gui_edit_sketcher_objects.py
draftguitools/gui_edit.py
draftguitools/gui_lineops.py
draftguitools/gui_togglemodes.py
draftguitools/gui_groups.py
draftguitools/gui_grid.py

View File

@@ -78,9 +78,6 @@ import draftguitools.gui_edit
import draftguitools.gui_selectplane
import draftguitools.gui_setstyle
import draftguitools.gui_planeproxy
from draftguitools.gui_lineops import FinishLine
from draftguitools.gui_lineops import CloseLine
from draftguitools.gui_lineops import UndoLine
from draftguitools.gui_togglemodes import ToggleConstructionMode
from draftguitools.gui_togglemodes import ToggleContinueMode
from draftguitools.gui_togglemodes import ToggleDisplayMode

View File

@@ -98,7 +98,6 @@ class DraftWorkbench(FreeCADGui.Workbench):
self.utility_commands_menu = it.get_draft_utility_commands_menu()
self.utility_commands_toolbar = it.get_draft_utility_commands_toolbar()
self.context_commands = it.get_draft_context_commands()
self.line_commands = it.get_draft_line_commands()
# Set up toolbars
it.init_toolbar(self,
@@ -162,25 +161,7 @@ class DraftWorkbench(FreeCADGui.Workbench):
def ContextMenu(self, recipient):
"""Define an optional custom context menu."""
from DraftGui import translate
if recipient == "View":
if FreeCAD.activeDraftCommand is None:
if FreeCADGui.Selection.getSelection():
self.appendContextMenu("Draft", self.drawing_commands + self.modification_commands)
self.appendContextMenu("Utilities", self.context_commands)
else:
self.appendContextMenu("Draft", self.drawing_commands)
else:
if FreeCAD.activeDraftCommand.featureName in ("Line",
"Wire",
"Polyline",
"BSpline",
"BezCurve",
"CubicBezCurve"):
self.appendContextMenu("", self.line_commands)
else:
if FreeCADGui.Selection.getSelection():
self.appendContextMenu("Utilities", self.context_commands)
self.appendContextMenu("Utilities", self.context_commands)
def GetClassName(self):
"""Type of workbench."""

View File

@@ -1,166 +0,0 @@
# ***************************************************************************
# * (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net> *
# * (c) 2009, 2010 Ken Cline <cline@frii.com> *
# * (c) 2020 Eliud Cabrera Castillo <e.cabrera-castillo@tum.de> *
# * *
# * This file is part of the FreeCAD CAx development system. *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * FreeCAD is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with FreeCAD; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
"""Provides GUI tools to do certain line operations.
These GuiCommands aren't really used anymore, as the same actions
are called from the task panel interface by other methods.
"""
## @package gui_lineops
# \ingroup draftguitools
# \brief Provides GUI tools to do certain line operations.
## \addtogroup draftguitools
# @{
from PySide.QtCore import QT_TRANSLATE_NOOP
import FreeCAD as App
import FreeCADGui as Gui
import Draft_rc
import draftguitools.gui_base as gui_base
from draftutils.messages import _msg
from draftutils.translate import translate
# The module is used to prevent complaints from code checkers (flake8)
True if Draft_rc.__name__ else False
class LineAction(gui_base.GuiCommandSimplest):
"""Base class for Line context GuiCommands.
This is inherited by the other GuiCommand classes to run
a set of similar actions when editing a line, wire, spline,
or bezier curve.
It inherits `GuiCommandSimplest` to set up the document
and other behavior. See this class for more information.
"""
def Activated(self, action="None"):
"""Execute when the command is called.
Parameters
----------
action: str
Indicates the type of action to perform with the line object.
It can be `'finish'`, `'close'`, or `'undo'`.
"""
if hasattr(App, "activeDraftCommand"):
_command = App.activeDraftCommand
else:
_msg(translate("draft","No active command."))
return
if (_command is not None
and _command.featureName in ("Line", "Polyline",
"BSpline", "BezCurve",
"CubicBezCurve")):
if action == "finish":
_command.finish(False)
elif action == "close":
_command.finish(True)
elif action == "undo":
_command.undolast()
class FinishLine(LineAction):
"""GuiCommand to finish any running line drawing operation."""
def __init__(self):
super(FinishLine, self).__init__(name=translate("draft","Finish line"))
def GetResources(self):
"""Set icon, menu and tooltip."""
d = {'Pixmap': 'Draft_Finish',
'MenuText': QT_TRANSLATE_NOOP("Draft_FinishLine", "Finish line"),
'ToolTip': QT_TRANSLATE_NOOP("Draft_FinishLine", "Finishes a line without closing it."),
'CmdType': 'ForEdit'}
return d
def Activated(self):
"""Execute when the command is called.
It calls the `finish(False)` method of the active Draft command.
"""
super(FinishLine, self).Activated(action="finish")
Gui.addCommand('Draft_FinishLine', FinishLine())
class CloseLine(LineAction):
"""GuiCommand to close the line being drawn and finish the operation."""
def __init__(self):
super(CloseLine, self).__init__(name=translate("draft","Close line"))
def GetResources(self):
"""Set icon, menu and tooltip."""
d = {'Pixmap': 'Draft_Lock',
'MenuText': QT_TRANSLATE_NOOP("Draft_CloseLine", "Close Line"),
'ToolTip': QT_TRANSLATE_NOOP("Draft_CloseLine", "Closes the line being drawn, and finishes the operation."),
'CmdType': 'ForEdit'}
return d
def Activated(self):
"""Execute when the command is called.
It calls the `finish(True)` method of the active Draft command.
"""
super(CloseLine, self).Activated(action="close")
Gui.addCommand('Draft_CloseLine', CloseLine())
class UndoLine(LineAction):
"""GuiCommand to undo the last drawn segment of a line."""
def __init__(self):
super(UndoLine, self).__init__(name=translate("draft","Undo line"))
def GetResources(self):
"""Set icon, menu and tooltip."""
d = {'Pixmap': 'Draft_Rotate',
'MenuText': QT_TRANSLATE_NOOP("Draft_UndoLine",
"Undo last segment"),
'ToolTip': QT_TRANSLATE_NOOP("Draft_UndoLine", "Undoes the last drawn segment of the line being drawn."),
'CmdType': 'ForEdit'}
return d
def Activated(self):
"""Execute when the command is called.
It calls the `undolast` method of the active Draft command.
"""
super(UndoLine, self).Activated(action="undo")
Gui.addCommand('Draft_UndoLine', UndoLine())
## @}

View File

@@ -159,22 +159,20 @@ def get_draft_snap_commands():
def get_draft_context_commands():
"""Return the context menu commands list."""
return ["Draft_ApplyStyle",
"Draft_ToggleDisplayMode",
return ["Draft_SetStyle",
"Draft_ApplyStyle",
"Separator",
"Draft_Layer",
"Draft_AddNamedGroup",
"Draft_AddToGroup",
"Draft_SelectGroup",
"Draft_SelectPlane",
"Draft_ShowSnapBar",
"Draft_ToggleConstructionMode",
"Draft_AddConstruction",
"Separator",
"Draft_ToggleDisplayMode",
"Draft_ToggleGrid",
"Draft_SetStyle"]
def get_draft_line_commands():
"""Return the line commands list."""
return ["Draft_UndoLine",
"Draft_FinishLine",
"Draft_CloseLine"]
"Draft_SelectPlane",
"Draft_WorkingPlaneProxy"]
def init_toolbar(workbench, toolbar, cmd_list):