From f5495502a5258bfeac350b50cc3633182ffe40f3 Mon Sep 17 00:00:00 2001 From: brad Date: Sat, 8 Jun 2019 08:48:20 -0500 Subject: [PATCH] PATH: Inspect editor now preserves last size and position --- src/Mod/Path/PathScripts/PathInspect.py | 48 ++++++++++++------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/Mod/Path/PathScripts/PathInspect.py b/src/Mod/Path/PathScripts/PathInspect.py index b25fa94a53..8779fa7461 100644 --- a/src/Mod/Path/PathScripts/PathInspect.py +++ b/src/Mod/Path/PathScripts/PathInspect.py @@ -27,26 +27,11 @@ import FreeCAD import FreeCADGui import Path + # Qt translation handling def translate(context, text, disambig=None): return QtCore.QCoreApplication.translate(context, text, disambig) -# class OldHighlighter(QtGui.QSyntaxHighlighter): - -# def highlightBlock(self, text): - -# myClassFormat = QtGui.QTextCharFormat() -# myClassFormat.setFontWeight(QtGui.QFont.Bold) -# myClassFormat.setForeground(QtCore.Qt.green) -# # the regex pattern to be colored -# pattern = "(G.*?|M.*?)\\s" -# expression = QtCore.QRegExp(pattern) -# index = text.index(expression) -# while index >= 0: -# length = expression.matchedLength() -# setFormat(index, length, myClassFormat) -# index = text.index(expression, index + length) - class GCodeHighlighter(QtGui.QSyntaxHighlighter): @@ -110,11 +95,11 @@ class GCodeEditorDialog(QtGui.QDialog): layout = QtGui.QVBoxLayout(self) p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path") - c = p.GetUnsigned("DefaultHighlightPathColor", 4286382335 ) + c = p.GetUnsigned("DefaultHighlightPathColor", 4286382335) Q = QtGui.QColor(int((c >> 24) & 0xFF), int((c >> 16) & 0xFF), int((c >> 8) & 0xFF)) - highlightcolor = (Q.red()/255., Q.green()/255., Q.blue()/255., Q.alpha()/255.) + highlightcolor = (Q.red() / 255., Q.green() / 255., Q.blue() / 255., Q.alpha() / 255.) - self.selectionobj = FreeCAD.ActiveDocument.addObject("Path::Feature","selection") + self.selectionobj = FreeCAD.ActiveDocument.addObject("Path::Feature", "selection") self.selectionobj.ViewObject.LineWidth = 4 self.selectionobj.ViewObject.NormalColor = highlightcolor @@ -146,7 +131,20 @@ class GCodeEditorDialog(QtGui.QDialog): self.editor.selectionChanged.connect(self.highlightpath) self.finished.connect(self.cleanup) + prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path") + Xpos = int(prefs.GetString('inspecteditorX', "0")) + Ypos = int(prefs.GetString('inspecteditorY', "0")) + height = int(prefs.GetString('inspecteditorH', "500")) + width = int(prefs.GetString('inspecteditorW', "600")) + self.move(Xpos, Ypos) + self.resize(width, height) + def cleanup(self): + prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path") + prefs.SetString('inspecteditorX', str(self.x())) + prefs.SetString('inspecteditorY', str(self.y())) + prefs.SetString('inspecteditorW', str(self.width())) + prefs.SetString('inspecteditorH', str(self.height())) FreeCAD.ActiveDocument.removeObject(self.selectionobj.Name) def highlightpath(self): @@ -160,7 +158,7 @@ class GCodeEditorDialog(QtGui.QDialog): commands = self.PathObj.Commands - #Derive the starting position for the first selected command + # Derive the starting position for the first selected command prevX = prevY = prevZ = None prevcommands = commands[:startrow] prevcommands.reverse() @@ -183,11 +181,11 @@ class GCodeEditorDialog(QtGui.QDialog): if prevZ is None: prevZ = 0.0 - #Build a new path with selection + # Build a new path with selection p = Path.Path() - firstrapid = Path.Command("G0", {"X": prevX, "Y":prevY, "Z":prevZ}) + firstrapid = Path.Command("G0", {"X": prevX, "Y": prevY, "Z": prevZ}) - selectionpath = [firstrapid] + commands[startrow:endrow +1] + selectionpath = [firstrapid] + commands[startrow:endrow + 1] p.Commands = selectionpath self.selectionobj.Path = p @@ -231,11 +229,11 @@ class CommandPathInspect: selection = FreeCADGui.Selection.getSelection() if len(selection) != 1: FreeCAD.Console.PrintError( - translate("Path_Inspect", "Please select exactly one path object")+"\n") + translate("Path_Inspect", "Please select exactly one path object") + "\n") return if not(selection[0].isDerivedFrom("Path::Feature")): FreeCAD.Console.PrintError( - translate("Path_Inspect", "Please select exactly one path object")+"\n") + translate("Path_Inspect", "Please select exactly one path object") + "\n") return # if everything is ok, execute