- fixed the line numbers in the TextPlainEdit to fit all digits of the line number; activated the line numbers for FlatCAMScript objects too
This commit is contained in:
parent
f44e24695d
commit
8c4663f344
|
@ -4780,7 +4780,7 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
|
||||||
# count the tools
|
# count the tools
|
||||||
tool_cnt = 0
|
tool_cnt = 0
|
||||||
|
|
||||||
dia_cnc_dict = {}
|
dia_cnc_dict = dict()
|
||||||
|
|
||||||
# this turn on the FlatCAMCNCJob plot for multiple tools
|
# this turn on the FlatCAMCNCJob plot for multiple tools
|
||||||
job_obj.multitool = True
|
job_obj.multitool = True
|
||||||
|
@ -4881,7 +4881,6 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
|
||||||
else:
|
else:
|
||||||
dia_cnc_dict['gcode'] = res
|
dia_cnc_dict['gcode'] = res
|
||||||
|
|
||||||
app_obj.progress.emit(50)
|
|
||||||
# tell gcode_parse from which point to start drawing the lines depending on what kind of
|
# tell gcode_parse from which point to start drawing the lines depending on what kind of
|
||||||
# object is the source of gcode
|
# object is the source of gcode
|
||||||
job_obj.toolchange_xy_type = "geometry"
|
job_obj.toolchange_xy_type = "geometry"
|
||||||
|
@ -4900,8 +4899,6 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.app.inform.emit('[ERROR] %s: %s' % (_("G-Code processing failed with error"), str(e)))
|
self.app.inform.emit('[ERROR] %s: %s' % (_("G-Code processing failed with error"), str(e)))
|
||||||
|
|
||||||
app_obj.progress.emit(80)
|
|
||||||
|
|
||||||
job_obj.cnc_tools.update({
|
job_obj.cnc_tools.update({
|
||||||
tooluid_key: deepcopy(dia_cnc_dict)
|
tooluid_key: deepcopy(dia_cnc_dict)
|
||||||
})
|
})
|
||||||
|
@ -4924,7 +4921,7 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
|
||||||
# count the tools
|
# count the tools
|
||||||
tool_cnt = 0
|
tool_cnt = 0
|
||||||
|
|
||||||
dia_cnc_dict = {}
|
dia_cnc_dict = dict()
|
||||||
|
|
||||||
# this turn on the FlatCAMCNCJob plot for multiple tools
|
# this turn on the FlatCAMCNCJob plot for multiple tools
|
||||||
job_obj.multitool = True
|
job_obj.multitool = True
|
||||||
|
@ -5056,8 +5053,6 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
|
||||||
# object is the source of gcode
|
# object is the source of gcode
|
||||||
job_obj.toolchange_xy_type = "geometry"
|
job_obj.toolchange_xy_type = "geometry"
|
||||||
|
|
||||||
app_obj.progress.emit(80)
|
|
||||||
|
|
||||||
job_obj.cnc_tools.update({
|
job_obj.cnc_tools.update({
|
||||||
tooluid_key: deepcopy(dia_cnc_dict)
|
tooluid_key: deepcopy(dia_cnc_dict)
|
||||||
})
|
})
|
||||||
|
@ -5071,15 +5066,11 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
|
||||||
if self.solid_geometry:
|
if self.solid_geometry:
|
||||||
with self.app.proc_container.new(_("Generating CNC Code")):
|
with self.app.proc_container.new(_("Generating CNC Code")):
|
||||||
if app_obj.new_object("cncjob", outname, job_init_single_geometry, plot=plot) != 'fail':
|
if app_obj.new_object("cncjob", outname, job_init_single_geometry, plot=plot) != 'fail':
|
||||||
app_obj.inform.emit('[success] %s: %s' %
|
app_obj.inform.emit('[success] %s: %s' % (_("CNCjob created"), outname))
|
||||||
(_("CNCjob created"), outname))
|
|
||||||
app_obj.progress.emit(100)
|
|
||||||
else:
|
else:
|
||||||
with self.app.proc_container.new(_("Generating CNC Code")):
|
with self.app.proc_container.new(_("Generating CNC Code")):
|
||||||
if app_obj.new_object("cncjob", outname, job_init_multi_geometry) != 'fail':
|
if app_obj.new_object("cncjob", outname, job_init_multi_geometry) != 'fail':
|
||||||
app_obj.inform.emit('[success] %s: %s' %
|
app_obj.inform.emit('[success] %s: %s' % (_("CNCjob created"), outname))
|
||||||
(_("CNCjob created"), outname))
|
|
||||||
app_obj.progress.emit(100)
|
|
||||||
|
|
||||||
# Create a promise with the name
|
# Create a promise with the name
|
||||||
self.app.collection.promise(outname)
|
self.app.collection.promise(outname)
|
||||||
|
@ -6650,7 +6641,7 @@ class FlatCAMScript(FlatCAMObj):
|
||||||
self.script_code = ''
|
self.script_code = ''
|
||||||
|
|
||||||
# self.script_editor_tab = TextEditor(app=self.app, plain_text=True)
|
# self.script_editor_tab = TextEditor(app=self.app, plain_text=True)
|
||||||
self.script_editor_tab = TextEditor(app=self.app)
|
self.script_editor_tab = TextEditor(app=self.app, plain_text=True)
|
||||||
|
|
||||||
def set_ui(self, ui):
|
def set_ui(self, ui):
|
||||||
FlatCAMObj.set_ui(self, ui)
|
FlatCAMObj.set_ui(self, ui)
|
||||||
|
@ -6722,10 +6713,10 @@ class FlatCAMScript(FlatCAMObj):
|
||||||
self.script_editor_tab.t_frame.hide()
|
self.script_editor_tab.t_frame.hide()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# self.script_editor_tab.code_editor.setPlainText(self.source_file)
|
self.script_editor_tab.code_editor.setPlainText(self.source_file)
|
||||||
for line in self.source_file.splitlines():
|
# for line in self.source_file.splitlines():
|
||||||
QtWidgets.QApplication.processEvents()
|
# QtWidgets.QApplication.processEvents()
|
||||||
self.script_editor_tab.code_editor.append(line)
|
# self.script_editor_tab.code_editor.append(line)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.debug("FlatCAMScript.set_ui() --> %s" % str(e))
|
log.debug("FlatCAMScript.set_ui() --> %s" % str(e))
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ CAD program, and create G-Code for Isolation routing.
|
||||||
|
|
||||||
- in Tool Fiducials added a new fiducial type: chess pattern
|
- in Tool Fiducials added a new fiducial type: chess pattern
|
||||||
- work in Calibrate Excellon Tool
|
- work in Calibrate Excellon Tool
|
||||||
|
- fixed the line numbers in the TextPlainEdit to fit all digits of the line number; activated the line numbers for FlatCAMScript objects too
|
||||||
|
|
||||||
22.11.2019
|
22.11.2019
|
||||||
|
|
||||||
|
|
|
@ -2357,7 +2357,8 @@ class FCTextAreaLineNumber(QtWidgets.QFrame):
|
||||||
QtWidgets.QWidget.paintEvent(self, event)
|
QtWidgets.QWidget.paintEvent(self, event)
|
||||||
|
|
||||||
def adjustWidth(self, count):
|
def adjustWidth(self, count):
|
||||||
width = self.fontMetrics().width(str(count))
|
# three spaces added to the width to make up for the space added in the line number
|
||||||
|
width = self.fontMetrics().width(str(count) + ' ')
|
||||||
if self.width() != width:
|
if self.width() != width:
|
||||||
self.setFixedWidth(width)
|
self.setFixedWidth(width)
|
||||||
|
|
||||||
|
@ -2376,15 +2377,16 @@ class FCTextAreaLineNumber(QtWidgets.QFrame):
|
||||||
"""
|
"""
|
||||||
TextEdit with line numbers and highlight
|
TextEdit with line numbers and highlight
|
||||||
From here: https://nachtimwald.com/2009/08/19/better-qplaintextedit-with-line-numbers/
|
From here: https://nachtimwald.com/2009/08/19/better-qplaintextedit-with-line-numbers/
|
||||||
|
and from here: https://doc.qt.io/qt-5/qtwidgets-widgets-codeeditor-example.html
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
FCPlainTextAreaExtended.__init__(self, *args)
|
FCPlainTextAreaExtended.__init__(self, *args)
|
||||||
|
|
||||||
#self.setFrameStyle(QFrame.NoFrame)
|
# self.setFrameStyle(QFrame.NoFrame)
|
||||||
self.setFrameStyle(QtWidgets.QFrame.NoFrame)
|
self.setFrameStyle(QtWidgets.QFrame.NoFrame)
|
||||||
self.highlight()
|
self.highlight()
|
||||||
#self.setLineWrapMode(QPlainTextEdit.NoWrap)
|
# self.setLineWrapMode(QPlainTextEdit.NoWrap)
|
||||||
self.cursorPositionChanged.connect(self.highlight)
|
self.cursorPositionChanged.connect(self.highlight)
|
||||||
|
|
||||||
def highlight(self):
|
def highlight(self):
|
||||||
|
@ -2401,39 +2403,43 @@ class FCTextAreaLineNumber(QtWidgets.QFrame):
|
||||||
font_metrics = self.fontMetrics()
|
font_metrics = self.fontMetrics()
|
||||||
current_line = self.document().findBlock(self.textCursor().position()).blockNumber() + 1
|
current_line = self.document().findBlock(self.textCursor().position()).blockNumber() + 1
|
||||||
|
|
||||||
block = self.firstVisibleBlock()
|
|
||||||
line_count = block.blockNumber()
|
|
||||||
|
|
||||||
painter = QtGui.QPainter(number_bar)
|
painter = QtGui.QPainter(number_bar)
|
||||||
painter.fillRect(event.rect(), self.palette().base())
|
painter.fillRect(event.rect(), QtCore.Qt.lightGray)
|
||||||
|
|
||||||
|
block = self.firstVisibleBlock()
|
||||||
|
line_count = int(block.blockNumber())
|
||||||
|
block_top = int(self.blockBoundingGeometry(block).translated(self.contentOffset()).top())
|
||||||
|
block_bottom = block_top + int(self.blockBoundingRect(block).height())
|
||||||
|
|
||||||
# Iterate over all visible text blocks in the document.
|
# Iterate over all visible text blocks in the document.
|
||||||
while block.isValid():
|
while block.isValid() and block_top <= event.rect().bottom():
|
||||||
line_count += 1
|
line_count += 1
|
||||||
block_top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top()
|
|
||||||
|
|
||||||
# Check if the position of the block is out side of the visible
|
# Check if the position of the block is out side of the visible
|
||||||
# area.
|
# area.
|
||||||
if not block.isVisible() or block_top >= event.rect().bottom():
|
if block.isVisible() and block_bottom >= event.rect().top():
|
||||||
break
|
|
||||||
|
|
||||||
# We want the line number for the selected line to be bold.
|
# We want the line number for the selected line to be bold.
|
||||||
if line_count == current_line:
|
if line_count == current_line:
|
||||||
font = painter.font()
|
font = painter.font()
|
||||||
# font.setBold(True)
|
# font.setBold(True)
|
||||||
painter.setPen(QtCore.Qt.blue)
|
painter.setPen(QtCore.Qt.blue)
|
||||||
painter.setFont(font)
|
painter.setFont(font)
|
||||||
else:
|
else:
|
||||||
font = painter.font()
|
font = painter.font()
|
||||||
# font.setBold(False)
|
# font.setBold(False)
|
||||||
painter.setPen(QtCore.Qt.lightGray)
|
painter.setPen(self.palette().base().color())
|
||||||
painter.setFont(font)
|
painter.setFont(font)
|
||||||
|
|
||||||
# Draw the line number right justified at the position of the line.
|
# Draw the line number right justified at the position of the line.
|
||||||
paint_rect = QtCore.QRect(0, block_top, number_bar.width(), font_metrics.height())
|
paint_rect = QtCore.QRect(0, block_top, number_bar.width(), font_metrics.height())
|
||||||
painter.drawText(paint_rect, Qt.AlignRight, ' ' + str(line_count) + ' ')
|
# I add some spaces to the line_count to prettify; make sure to remember adjust the width in the
|
||||||
|
# NumberBar() class above
|
||||||
|
painter.drawText(paint_rect, Qt.AlignRight, ' ' + str(line_count) + ' ')
|
||||||
|
|
||||||
block = block.next()
|
block = block.next()
|
||||||
|
block_top = block_bottom
|
||||||
|
block_bottom = block_top + self.blockBoundingRect(block).height()
|
||||||
|
|
||||||
painter.end()
|
painter.end()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue