Merge pull request #3333 from fra589/master

[Path] Add size parameter for syntax highlighting of GCode editor
This commit is contained in:
sliptonic
2020-04-13 08:48:18 -05:00
committed by GitHub
2 changed files with 30 additions and 3 deletions

View File

@@ -112,7 +112,6 @@ class GCodeEditorDialog(QtGui.QDialog):
font.setPointSize(p.GetInt("FontSize", 10))
self.editor.setFont(font)
self.editor.setText("G01 X55 Y4.5 F300.0")
self.highlighter = GCodeHighlighter(self.editor.document())
layout.addWidget(self.editor)
# Note
@@ -192,11 +191,25 @@ class GCodeEditorDialog(QtGui.QDialog):
def show(obj):
"show(obj): shows the G-code data of the given Path object in a dialog"
prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
# default Max Highlighter Size = 512 Ko
defaultMHS = 512 * 1024
mhs = prefs.GetUnsigned('inspecteditorMaxHighlighterSize', defaultMHS)
if hasattr(obj, "Path"):
if obj.Path:
dia = GCodeEditorDialog(obj.Path)
dia.editor.setText(obj.Path.toGCode())
gcodeSize = len(dia.editor.toPlainText())
if (gcodeSize <= mhs):
# because of poor performance, syntax highlighting is
# limited to mhs octets (default 512 KB).
# It seems than the response time curve has an inflexion near 500 KB
# beyond 500 KB, the response time increases exponentially.
dia.highlighter = GCodeHighlighter(dia.editor.document())
else:
FreeCAD.Console.PrintMessage(translate("Path", "GCode size too big ({} o), disabling syntax highlighter.".format(gcodeSize)))
result = dia.exec_()
# exec_() returns 0 or 1 depending on the button pressed (Ok or
# Cancel)

View File

@@ -78,7 +78,6 @@ class GCodeEditorDialog(QtGui.QDialog):
font.setPointSize(10)
self.editor.setFont(font)
self.editor.setText("G01 X55 Y4.5 F300.0")
self.highlighter = GCodeHighlighter(self.editor.document())
layout.addWidget(self.editor)
# OK and Cancel buttons
@@ -134,8 +133,23 @@ def fmt(num,dec,units):
def editor(gcode):
'''pops up a handy little editor to look at the code output '''
prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Path")
# default Max Highlighter Size = 512 Ko
defaultMHS = 512 * 1024
mhs = prefs.GetUnsigned('inspecteditorMaxHighlighterSize', defaultMHS)
dia = GCodeEditorDialog()
dia.editor.setText(gcode)
gcodeSize = len(dia.editor.toPlainText())
if (gcodeSize <= mhs):
# because of poor performance, syntax highlighting is
# limited to mhs octets (default 512 KB).
# It seems than the response time curve has an inflexion near 500 KB
# beyond 500 KB, the response time increases exponentially.
dia.highlighter = GCodeHighlighter(dia.editor.document())
else:
FreeCAD.Console.PrintMessage(translate("Path", "GCode size too big ({} o), disabling syntax highlighter.".format(gcodeSize)))
result = dia.exec_()
if result: # If user selected 'OK' get modified G Code
final = dia.editor.toPlainText()