- 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:
Marius Stanciu 2019-11-23 18:20:37 +02:00 committed by Marius
parent f44e24695d
commit 8c4663f344
3 changed files with 41 additions and 43 deletions

View File

@ -4780,7 +4780,7 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
# count the tools
tool_cnt = 0
dia_cnc_dict = {}
dia_cnc_dict = dict()
# this turn on the FlatCAMCNCJob plot for multiple tools
job_obj.multitool = True
@ -4881,7 +4881,6 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
else:
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
# object is the source of gcode
job_obj.toolchange_xy_type = "geometry"
@ -4900,8 +4899,6 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
except Exception as 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({
tooluid_key: deepcopy(dia_cnc_dict)
})
@ -4924,7 +4921,7 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
# count the tools
tool_cnt = 0
dia_cnc_dict = {}
dia_cnc_dict = dict()
# this turn on the FlatCAMCNCJob plot for multiple tools
job_obj.multitool = True
@ -5056,8 +5053,6 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
# object is the source of gcode
job_obj.toolchange_xy_type = "geometry"
app_obj.progress.emit(80)
job_obj.cnc_tools.update({
tooluid_key: deepcopy(dia_cnc_dict)
})
@ -5071,15 +5066,11 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
if self.solid_geometry:
with self.app.proc_container.new(_("Generating CNC Code")):
if app_obj.new_object("cncjob", outname, job_init_single_geometry, plot=plot) != 'fail':
app_obj.inform.emit('[success] %s: %s' %
(_("CNCjob created"), outname))
app_obj.progress.emit(100)
app_obj.inform.emit('[success] %s: %s' % (_("CNCjob created"), outname))
else:
with self.app.proc_container.new(_("Generating CNC Code")):
if app_obj.new_object("cncjob", outname, job_init_multi_geometry) != 'fail':
app_obj.inform.emit('[success] %s: %s' %
(_("CNCjob created"), outname))
app_obj.progress.emit(100)
app_obj.inform.emit('[success] %s: %s' % (_("CNCjob created"), outname))
# Create a promise with the name
self.app.collection.promise(outname)
@ -6650,7 +6641,7 @@ class FlatCAMScript(FlatCAMObj):
self.script_code = ''
# 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):
FlatCAMObj.set_ui(self, ui)
@ -6722,10 +6713,10 @@ class FlatCAMScript(FlatCAMObj):
self.script_editor_tab.t_frame.hide()
try:
# self.script_editor_tab.code_editor.setPlainText(self.source_file)
for line in self.source_file.splitlines():
QtWidgets.QApplication.processEvents()
self.script_editor_tab.code_editor.append(line)
self.script_editor_tab.code_editor.setPlainText(self.source_file)
# for line in self.source_file.splitlines():
# QtWidgets.QApplication.processEvents()
# self.script_editor_tab.code_editor.append(line)
except Exception as e:
log.debug("FlatCAMScript.set_ui() --> %s" % str(e))

View File

@ -13,6 +13,7 @@ CAD program, and create G-Code for Isolation routing.
- in Tool Fiducials added a new fiducial type: chess pattern
- 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

View File

@ -2357,7 +2357,8 @@ class FCTextAreaLineNumber(QtWidgets.QFrame):
QtWidgets.QWidget.paintEvent(self, event)
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:
self.setFixedWidth(width)
@ -2376,15 +2377,16 @@ class FCTextAreaLineNumber(QtWidgets.QFrame):
"""
TextEdit with line numbers and highlight
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):
FCPlainTextAreaExtended.__init__(self, *args)
#self.setFrameStyle(QFrame.NoFrame)
# self.setFrameStyle(QFrame.NoFrame)
self.setFrameStyle(QtWidgets.QFrame.NoFrame)
self.highlight()
#self.setLineWrapMode(QPlainTextEdit.NoWrap)
# self.setLineWrapMode(QPlainTextEdit.NoWrap)
self.cursorPositionChanged.connect(self.highlight)
def highlight(self):
@ -2401,39 +2403,43 @@ class FCTextAreaLineNumber(QtWidgets.QFrame):
font_metrics = self.fontMetrics()
current_line = self.document().findBlock(self.textCursor().position()).blockNumber() + 1
block = self.firstVisibleBlock()
line_count = block.blockNumber()
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.
while block.isValid():
while block.isValid() and block_top <= event.rect().bottom():
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
# area.
if not block.isVisible() or block_top >= event.rect().bottom():
break
if block.isVisible() and block_bottom >= event.rect().top():
# We want the line number for the selected line to be bold.
if line_count == current_line:
font = painter.font()
# font.setBold(True)
painter.setPen(QtCore.Qt.blue)
painter.setFont(font)
else:
font = painter.font()
# font.setBold(False)
painter.setPen(QtCore.Qt.lightGray)
painter.setFont(font)
# We want the line number for the selected line to be bold.
if line_count == current_line:
font = painter.font()
# font.setBold(True)
painter.setPen(QtCore.Qt.blue)
painter.setFont(font)
else:
font = painter.font()
# font.setBold(False)
painter.setPen(self.palette().base().color())
painter.setFont(font)
# 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())
painter.drawText(paint_rect, Qt.AlignRight, ' ' + str(line_count) + ' ')
# 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())
# 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_top = block_bottom
block_bottom = block_top + self.blockBoundingRect(block).height()
painter.end()