2019-10-13 15:13:39 +00:00
|
|
|
# ##########################################################
|
|
|
|
# FlatCAM: 2D Post-processing for Manufacturing #
|
|
|
|
# File Author: Marius Adrian Stanciu (c) #
|
|
|
|
# Date: 10/10/2019 #
|
|
|
|
# MIT Licence #
|
|
|
|
# ##########################################################
|
|
|
|
|
2020-07-22 12:49:52 +00:00
|
|
|
from appGUI.GUIElements import FCFileSaveDialog, FCEntry, FCTextAreaExtended, FCTextAreaLineNumber, FCButton
|
2020-04-10 23:55:32 +00:00
|
|
|
from PyQt5 import QtPrintSupport, QtWidgets, QtCore, QtGui
|
2019-10-02 02:47:18 +00:00
|
|
|
|
2019-12-17 12:47:44 +00:00
|
|
|
from reportlab.platypus import SimpleDocTemplate, Paragraph
|
|
|
|
from reportlab.lib.styles import getSampleStyleSheet
|
|
|
|
from reportlab.lib.units import inch, mm
|
|
|
|
|
2020-04-10 23:55:32 +00:00
|
|
|
# from io import StringIO
|
2019-12-17 12:47:44 +00:00
|
|
|
|
2019-10-02 02:47:18 +00:00
|
|
|
import gettext
|
2020-06-03 17:35:59 +00:00
|
|
|
import appTranslation as fcTranslate
|
2019-10-02 02:47:18 +00:00
|
|
|
import builtins
|
|
|
|
|
|
|
|
fcTranslate.apply_language('strings')
|
|
|
|
if '_' not in builtins.__dict__:
|
|
|
|
_ = gettext.gettext
|
|
|
|
|
|
|
|
|
2020-06-08 16:53:31 +00:00
|
|
|
class AppTextEditor(QtWidgets.QWidget):
|
2019-10-02 02:47:18 +00:00
|
|
|
|
2020-05-01 14:10:42 +00:00
|
|
|
def __init__(self, app, text=None, plain_text=None, parent=None):
|
|
|
|
super().__init__(parent=parent)
|
2019-10-02 02:47:18 +00:00
|
|
|
|
|
|
|
self.app = app
|
2020-02-01 04:59:15 +00:00
|
|
|
self.plain_text = plain_text
|
2020-07-22 12:49:52 +00:00
|
|
|
self.callback = lambda x: None
|
2020-02-01 04:59:15 +00:00
|
|
|
|
2019-10-02 02:47:18 +00:00
|
|
|
self.setSizePolicy(
|
|
|
|
QtWidgets.QSizePolicy.MinimumExpanding,
|
|
|
|
QtWidgets.QSizePolicy.MinimumExpanding
|
|
|
|
)
|
|
|
|
|
2020-10-24 12:58:20 +00:00
|
|
|
# UI Layout
|
2019-10-02 02:47:18 +00:00
|
|
|
self.main_editor_layout = QtWidgets.QVBoxLayout(self)
|
|
|
|
self.main_editor_layout.setContentsMargins(0, 0, 0, 0)
|
|
|
|
|
|
|
|
self.t_frame = QtWidgets.QFrame()
|
|
|
|
self.t_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
|
self.main_editor_layout.addWidget(self.t_frame)
|
|
|
|
|
|
|
|
self.work_editor_layout = QtWidgets.QGridLayout(self.t_frame)
|
|
|
|
self.work_editor_layout.setContentsMargins(2, 2, 2, 2)
|
|
|
|
self.t_frame.setLayout(self.work_editor_layout)
|
|
|
|
|
2020-10-24 12:58:20 +00:00
|
|
|
# CODE Editor
|
2020-02-01 04:59:15 +00:00
|
|
|
if self.plain_text:
|
2019-11-22 09:00:39 +00:00
|
|
|
self.editor_class = FCTextAreaLineNumber()
|
|
|
|
self.code_editor = self.editor_class.edit
|
|
|
|
|
2019-11-13 00:06:16 +00:00
|
|
|
stylesheet = """
|
|
|
|
QPlainTextEdit { selection-background-color:yellow;
|
|
|
|
selection-color:black;
|
|
|
|
}
|
|
|
|
"""
|
2019-11-22 14:31:40 +00:00
|
|
|
self.work_editor_layout.addWidget(self.editor_class, 0, 0, 1, 5)
|
2019-11-13 00:06:16 +00:00
|
|
|
else:
|
|
|
|
self.code_editor = FCTextAreaExtended()
|
|
|
|
stylesheet = """
|
|
|
|
QTextEdit { selection-background-color:yellow;
|
|
|
|
selection-color:black;
|
|
|
|
}
|
|
|
|
"""
|
2019-11-22 14:31:40 +00:00
|
|
|
self.work_editor_layout.addWidget(self.code_editor, 0, 0, 1, 5)
|
2019-10-02 02:47:18 +00:00
|
|
|
|
|
|
|
self.code_editor.setStyleSheet(stylesheet)
|
|
|
|
|
|
|
|
if text:
|
|
|
|
self.code_editor.setPlainText(text)
|
|
|
|
|
2020-10-24 12:58:20 +00:00
|
|
|
# #############################################################################################################
|
|
|
|
# UI SETUP
|
|
|
|
# #############################################################################################################
|
|
|
|
control_lay = QtWidgets.QHBoxLayout()
|
|
|
|
self.work_editor_layout.addLayout(control_lay, 1, 0, 1, 5)
|
2019-10-02 02:47:18 +00:00
|
|
|
|
2020-10-24 12:58:20 +00:00
|
|
|
# FIND
|
|
|
|
self.buttonFind = FCButton(_('Find'))
|
2020-07-17 21:26:03 +00:00
|
|
|
self.buttonFind.setIcon(QtGui.QIcon(self.app.resource_location + '/find32.png'))
|
2019-10-02 02:47:18 +00:00
|
|
|
self.buttonFind.setToolTip(_("Will search and highlight in yellow the string in the Find box."))
|
2020-10-24 12:58:20 +00:00
|
|
|
control_lay.addWidget(self.buttonFind)
|
2019-10-02 02:47:18 +00:00
|
|
|
|
2020-10-24 12:58:20 +00:00
|
|
|
# Entry FIND
|
2019-10-02 02:47:18 +00:00
|
|
|
self.entryFind = FCEntry()
|
|
|
|
self.entryFind.setToolTip(_("Find box. Enter here the strings to be searched in the text."))
|
2020-10-24 12:58:20 +00:00
|
|
|
control_lay.addWidget(self.entryFind)
|
2019-10-02 02:47:18 +00:00
|
|
|
|
2020-10-24 12:58:20 +00:00
|
|
|
# REPLACE
|
2020-07-22 12:49:52 +00:00
|
|
|
self.buttonReplace = FCButton(_('Replace With'))
|
2020-07-17 21:26:03 +00:00
|
|
|
self.buttonReplace.setIcon(QtGui.QIcon(self.app.resource_location + '/replace32.png'))
|
2019-10-02 02:47:18 +00:00
|
|
|
self.buttonReplace.setToolTip(_("Will replace the string from the Find box with the one in the Replace box."))
|
2020-10-24 12:58:20 +00:00
|
|
|
control_lay.addWidget(self.buttonReplace)
|
2019-10-02 02:47:18 +00:00
|
|
|
|
2020-10-24 12:58:20 +00:00
|
|
|
# Entry REPLACE
|
2019-10-02 02:47:18 +00:00
|
|
|
self.entryReplace = FCEntry()
|
|
|
|
self.entryReplace.setToolTip(_("String to replace the one in the Find box throughout the text."))
|
2020-10-24 12:58:20 +00:00
|
|
|
control_lay.addWidget(self.entryReplace)
|
2019-10-02 02:47:18 +00:00
|
|
|
|
2020-10-24 12:58:20 +00:00
|
|
|
# Select All
|
2019-10-02 02:47:18 +00:00
|
|
|
self.sel_all_cb = QtWidgets.QCheckBox(_('All'))
|
|
|
|
self.sel_all_cb.setToolTip(_("When checked it will replace all instances in the 'Find' box\n"
|
|
|
|
"with the text in the 'Replace' box.."))
|
2020-10-24 12:58:20 +00:00
|
|
|
control_lay.addWidget(self.sel_all_cb)
|
2019-10-02 02:47:18 +00:00
|
|
|
|
2020-10-24 12:58:20 +00:00
|
|
|
# COPY All
|
|
|
|
# self.button_copy_all = FCButton(_('Copy All'))
|
|
|
|
# self.button_copy_all.setIcon(QtGui.QIcon(self.app.resource_location + '/copy_file32.png'))
|
|
|
|
# self.button_copy_all.setToolTip(_("Will copy all the text in the Code Editor to the clipboard."))
|
|
|
|
# control_lay.addWidget(self.button_copy_all)
|
2019-10-02 02:47:18 +00:00
|
|
|
|
2020-10-24 12:58:20 +00:00
|
|
|
# Update
|
2020-08-23 21:51:07 +00:00
|
|
|
self.button_update_code = QtWidgets.QToolButton()
|
|
|
|
self.button_update_code.setIcon(QtGui.QIcon(self.app.resource_location + '/save_as.png'))
|
|
|
|
self.button_update_code.setToolTip(_("Save changes internally."))
|
|
|
|
self.button_update_code.hide()
|
2020-10-24 12:58:20 +00:00
|
|
|
control_lay.addWidget(self.button_update_code)
|
2020-08-23 21:51:07 +00:00
|
|
|
|
2020-10-24 12:58:20 +00:00
|
|
|
# Print PREVIEW
|
|
|
|
self.buttonPreview = QtWidgets.QToolButton()
|
|
|
|
self.buttonPreview.setIcon(QtGui.QIcon(self.app.resource_location + '/preview32.png'))
|
|
|
|
self.buttonPreview.setToolTip(_("Open a OS standard Preview Print window."))
|
|
|
|
control_lay.addWidget(self.buttonPreview)
|
|
|
|
|
|
|
|
# PRINT
|
|
|
|
self.buttonPrint = QtWidgets.QToolButton()
|
|
|
|
self.buttonPrint.setIcon(QtGui.QIcon(self.app.resource_location + '/printer32.png'))
|
|
|
|
self.buttonPrint.setToolTip(_("Open a OS standard Print window."))
|
|
|
|
control_lay.addWidget(self.buttonPrint)
|
|
|
|
|
|
|
|
# OPEN
|
|
|
|
self.buttonOpen = QtWidgets.QToolButton()
|
2020-07-17 21:26:03 +00:00
|
|
|
self.buttonOpen.setIcon(QtGui.QIcon(self.app.resource_location + '/folder32_bis.png'))
|
2019-10-02 02:47:18 +00:00
|
|
|
self.buttonOpen.setToolTip(_("Will open a text file in the editor."))
|
2020-10-24 12:58:20 +00:00
|
|
|
control_lay.addWidget(self.buttonOpen)
|
2019-10-02 02:47:18 +00:00
|
|
|
|
2020-10-24 12:58:20 +00:00
|
|
|
# SAVE
|
|
|
|
self.buttonSave = QtWidgets.QToolButton()
|
2020-07-17 21:26:03 +00:00
|
|
|
self.buttonSave.setIcon(QtGui.QIcon(self.app.resource_location + '/save_as.png'))
|
2019-10-02 02:47:18 +00:00
|
|
|
self.buttonSave.setToolTip(_("Will save the text in the editor into a file."))
|
2020-10-24 12:58:20 +00:00
|
|
|
control_lay.addWidget(self.buttonSave)
|
2019-10-02 02:47:18 +00:00
|
|
|
|
2020-10-24 12:58:20 +00:00
|
|
|
# RUN
|
|
|
|
self.buttonRun = FCButton(_('Run'))
|
2019-10-02 02:47:18 +00:00
|
|
|
self.buttonRun.setToolTip(_("Will run the TCL commands found in the text file, one by one."))
|
|
|
|
self.buttonRun.hide()
|
2020-10-24 12:58:20 +00:00
|
|
|
control_lay.addWidget(self.buttonRun)
|
2019-10-02 02:47:18 +00:00
|
|
|
|
2020-10-24 12:58:20 +00:00
|
|
|
# #############################################################################################################
|
|
|
|
# ################### SIGNALS #################################################################################
|
|
|
|
# #############################################################################################################
|
2019-10-02 02:47:18 +00:00
|
|
|
self.code_editor.textChanged.connect(self.handleTextChanged)
|
|
|
|
self.buttonOpen.clicked.connect(self.handleOpen)
|
|
|
|
self.buttonSave.clicked.connect(self.handleSaveGCode)
|
|
|
|
self.buttonPrint.clicked.connect(self.handlePrint)
|
|
|
|
self.buttonPreview.clicked.connect(self.handlePreview)
|
|
|
|
self.buttonFind.clicked.connect(self.handleFindGCode)
|
|
|
|
self.buttonReplace.clicked.connect(self.handleReplaceGCode)
|
2020-10-24 12:58:20 +00:00
|
|
|
# self.button_copy_all.clicked.connect(self.handleCopyAll)
|
2019-10-02 02:47:18 +00:00
|
|
|
|
|
|
|
self.code_editor.set_model_data(self.app.myKeywords)
|
|
|
|
|
2019-11-22 14:31:40 +00:00
|
|
|
self.code_edited = ''
|
2019-10-02 02:47:18 +00:00
|
|
|
|
2020-07-22 12:49:52 +00:00
|
|
|
def set_callback(self, callback):
|
|
|
|
self.callback = callback
|
|
|
|
|
2019-10-02 02:47:18 +00:00
|
|
|
def handlePrint(self):
|
|
|
|
dialog = QtPrintSupport.QPrintDialog()
|
2020-10-23 11:16:05 +00:00
|
|
|
if dialog.exec() == QtWidgets.QDialog.Accepted:
|
2019-10-02 02:47:18 +00:00
|
|
|
self.code_editor.document().print_(dialog.printer())
|
|
|
|
|
|
|
|
def handlePreview(self):
|
|
|
|
dialog = QtPrintSupport.QPrintPreviewDialog()
|
2020-10-23 11:16:05 +00:00
|
|
|
dialog.paintRequested.connect(self.code_editor.print)
|
|
|
|
dialog.exec()
|
2019-10-02 02:47:18 +00:00
|
|
|
|
|
|
|
def handleTextChanged(self):
|
|
|
|
# enable = not self.ui.code_editor.document().isEmpty()
|
|
|
|
# self.ui.buttonPrint.setEnabled(enable)
|
|
|
|
# self.ui.buttonPreview.setEnabled(enable)
|
2020-07-17 21:26:03 +00:00
|
|
|
|
|
|
|
self.buttonSave.setStyleSheet("QPushButton {color: red;}")
|
|
|
|
self.buttonSave.setIcon(QtGui.QIcon(self.app.resource_location + '/save_as_red.png'))
|
|
|
|
|
|
|
|
def load_text(self, text, move_to_start=False, move_to_end=False, clear_text=True, as_html=False):
|
|
|
|
self.code_editor.textChanged.disconnect()
|
|
|
|
if clear_text:
|
|
|
|
# first clear previous text in text editor (if any)
|
|
|
|
self.code_editor.clear()
|
|
|
|
|
|
|
|
self.code_editor.setReadOnly(False)
|
|
|
|
if as_html is False:
|
|
|
|
self.code_editor.setPlainText(text)
|
|
|
|
else:
|
|
|
|
self.code_editor.setHtml(text)
|
|
|
|
if move_to_start:
|
|
|
|
self.code_editor.moveCursor(QtGui.QTextCursor.Start)
|
|
|
|
elif move_to_end:
|
|
|
|
self.code_editor.moveCursor(QtGui.QTextCursor.End)
|
|
|
|
self.code_editor.textChanged.connect(self.handleTextChanged)
|
2019-10-02 02:47:18 +00:00
|
|
|
|
|
|
|
def handleOpen(self, filt=None):
|
2020-04-29 01:46:52 +00:00
|
|
|
self.app.defaults.report_usage("handleOpen()")
|
2019-10-02 02:47:18 +00:00
|
|
|
|
|
|
|
if filt:
|
|
|
|
_filter_ = filt
|
|
|
|
else:
|
|
|
|
_filter_ = "G-Code Files (*.nc);; G-Code Files (*.txt);; G-Code Files (*.tap);; G-Code Files (*.cnc);; " \
|
|
|
|
"All Files (*.*)"
|
|
|
|
|
|
|
|
path, _f = QtWidgets.QFileDialog.getOpenFileName(
|
|
|
|
caption=_('Open file'), directory=self.app.get_last_folder(), filter=_filter_)
|
|
|
|
|
|
|
|
if path:
|
|
|
|
file = QtCore.QFile(path)
|
|
|
|
if file.open(QtCore.QIODevice.ReadOnly):
|
|
|
|
stream = QtCore.QTextStream(file)
|
2019-11-22 14:31:40 +00:00
|
|
|
self.code_edited = stream.readAll()
|
|
|
|
self.code_editor.setPlainText(self.code_edited)
|
2019-10-02 02:47:18 +00:00
|
|
|
file.close()
|
|
|
|
|
2019-12-06 23:07:52 +00:00
|
|
|
def handleSaveGCode(self, name=None, filt=None, callback=None):
|
2020-04-29 01:46:52 +00:00
|
|
|
self.app.defaults.report_usage("handleSaveGCode()")
|
2019-10-02 02:47:18 +00:00
|
|
|
|
|
|
|
if filt:
|
|
|
|
_filter_ = filt
|
|
|
|
else:
|
|
|
|
_filter_ = "G-Code Files (*.nc);; G-Code Files (*.txt);; G-Code Files (*.tap);; G-Code Files (*.cnc);; " \
|
2019-12-19 14:26:19 +00:00
|
|
|
"PDF Files (*.pdf);;All Files (*.*)"
|
2019-10-02 02:47:18 +00:00
|
|
|
|
|
|
|
if name:
|
|
|
|
obj_name = name
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
obj_name = self.app.collection.get_active().options['name']
|
|
|
|
except AttributeError:
|
|
|
|
obj_name = 'file'
|
|
|
|
if filt is None:
|
2019-12-19 14:26:19 +00:00
|
|
|
_filter_ = "FlatConfig Files (*.FlatConfig);;PDF Files (*.pdf);;All Files (*.*)"
|
2019-10-02 02:47:18 +00:00
|
|
|
|
|
|
|
try:
|
2020-04-10 23:55:32 +00:00
|
|
|
filename = str(FCFileSaveDialog.get_saved_filename(
|
2019-11-09 16:04:49 +00:00
|
|
|
caption=_("Export Code ..."),
|
2019-10-02 02:47:18 +00:00
|
|
|
directory=self.app.defaults["global_last_folder"] + '/' + str(obj_name),
|
2020-06-02 15:29:45 +00:00
|
|
|
ext_filter=_filter_
|
2019-10-02 02:47:18 +00:00
|
|
|
)[0])
|
|
|
|
except TypeError:
|
2020-10-28 13:46:33 +00:00
|
|
|
filename = str(FCFileSaveDialog.get_saved_filename(
|
|
|
|
caption=_("Export Code ..."),
|
|
|
|
ext_filter=_filter_)[0])
|
2019-10-02 02:47:18 +00:00
|
|
|
|
|
|
|
if filename == "":
|
2020-04-24 04:23:14 +00:00
|
|
|
self.app.inform.emit('[WARNING_NOTCL] %s' % _("Cancelled."))
|
2019-10-02 02:47:18 +00:00
|
|
|
return
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
my_gcode = self.code_editor.toPlainText()
|
2019-12-17 01:42:24 +00:00
|
|
|
if filename.rpartition('.')[2].lower() == 'pdf':
|
2019-12-17 12:47:44 +00:00
|
|
|
page_size = (
|
|
|
|
self.app.plotcanvas.pagesize_dict[self.app.defaults['global_workspaceT']][0] * mm,
|
|
|
|
self.app.plotcanvas.pagesize_dict[self.app.defaults['global_workspaceT']][1] * mm
|
|
|
|
)
|
|
|
|
|
|
|
|
# add new line after each line
|
|
|
|
lined_gcode = my_gcode.replace("\n", "<br />")
|
2019-12-17 01:42:24 +00:00
|
|
|
|
|
|
|
styles = getSampleStyleSheet()
|
|
|
|
styleN = styles['Normal']
|
2020-04-10 23:55:32 +00:00
|
|
|
# styleH = styles['Heading1']
|
2019-12-17 01:42:24 +00:00
|
|
|
story = []
|
|
|
|
|
2019-12-19 14:26:19 +00:00
|
|
|
if self.app.defaults['units'].lower() == 'mm':
|
|
|
|
bmargin = self.app.defaults['global_tpdf_bmargin'] * mm
|
|
|
|
tmargin = self.app.defaults['global_tpdf_tmargin'] * mm
|
|
|
|
rmargin = self.app.defaults['global_tpdf_rmargin'] * mm
|
|
|
|
lmargin = self.app.defaults['global_tpdf_lmargin'] * mm
|
|
|
|
else:
|
|
|
|
bmargin = self.app.defaults['global_tpdf_bmargin'] * inch
|
|
|
|
tmargin = self.app.defaults['global_tpdf_tmargin'] * inch
|
|
|
|
rmargin = self.app.defaults['global_tpdf_rmargin'] * inch
|
|
|
|
lmargin = self.app.defaults['global_tpdf_lmargin'] * inch
|
|
|
|
|
2019-12-17 01:42:24 +00:00
|
|
|
doc = SimpleDocTemplate(
|
|
|
|
filename,
|
2019-12-17 12:47:44 +00:00
|
|
|
pagesize=page_size,
|
2019-12-19 14:26:19 +00:00
|
|
|
bottomMargin=bmargin,
|
|
|
|
topMargin=tmargin,
|
|
|
|
rightMargin=rmargin,
|
|
|
|
leftMargin=lmargin)
|
2019-12-17 01:42:24 +00:00
|
|
|
|
2019-12-17 12:47:44 +00:00
|
|
|
P = Paragraph(lined_gcode, styleN)
|
2019-12-17 01:42:24 +00:00
|
|
|
story.append(P)
|
|
|
|
|
|
|
|
doc.build(
|
|
|
|
story,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
with open(filename, 'w') as f:
|
|
|
|
for line in my_gcode:
|
|
|
|
f.write(line)
|
2020-07-17 21:26:03 +00:00
|
|
|
self.buttonSave.setStyleSheet("")
|
|
|
|
self.buttonSave.setIcon(QtGui.QIcon(self.app.resource_location + '/save_as.png'))
|
2019-10-02 02:47:18 +00:00
|
|
|
except FileNotFoundError:
|
|
|
|
self.app.inform.emit('[WARNING] %s' % _("No such file or directory"))
|
|
|
|
return
|
|
|
|
except PermissionError:
|
|
|
|
self.app.inform.emit('[WARNING] %s' %
|
|
|
|
_("Permission denied, saving not possible.\n"
|
|
|
|
"Most likely another app is holding the file open and not accessible."))
|
|
|
|
return
|
|
|
|
|
|
|
|
# Just for adding it to the recent files list.
|
|
|
|
if self.app.defaults["global_open_style"] is False:
|
|
|
|
self.app.file_opened.emit("cncjob", filename)
|
|
|
|
self.app.file_saved.emit("cncjob", filename)
|
|
|
|
self.app.inform.emit('%s: %s' % (_("Saved to"), str(filename)))
|
|
|
|
|
2019-12-06 23:07:52 +00:00
|
|
|
if callback is not None:
|
|
|
|
callback()
|
|
|
|
|
2019-10-02 02:47:18 +00:00
|
|
|
def handleFindGCode(self):
|
|
|
|
|
|
|
|
flags = QtGui.QTextDocument.FindCaseSensitively
|
|
|
|
text_to_be_found = self.entryFind.get_value()
|
|
|
|
|
|
|
|
r = self.code_editor.find(str(text_to_be_found), flags)
|
|
|
|
if r is False:
|
|
|
|
self.code_editor.moveCursor(QtGui.QTextCursor.Start)
|
2020-11-02 01:32:00 +00:00
|
|
|
self.code_editor.find(str(text_to_be_found), flags)
|
2019-10-02 02:47:18 +00:00
|
|
|
|
|
|
|
def handleReplaceGCode(self):
|
|
|
|
|
|
|
|
old = self.entryFind.get_value()
|
|
|
|
new = self.entryReplace.get_value()
|
|
|
|
|
|
|
|
if self.sel_all_cb.isChecked():
|
|
|
|
while True:
|
|
|
|
cursor = self.code_editor.textCursor()
|
|
|
|
cursor.beginEditBlock()
|
|
|
|
flags = QtGui.QTextDocument.FindCaseSensitively
|
|
|
|
# self.ui.editor is the QPlainTextEdit
|
|
|
|
r = self.code_editor.find(str(old), flags)
|
|
|
|
if r:
|
|
|
|
qc = self.code_editor.textCursor()
|
|
|
|
if qc.hasSelection():
|
|
|
|
qc.insertText(new)
|
|
|
|
else:
|
2020-02-01 02:01:48 +00:00
|
|
|
self.code_editor.moveCursor(QtGui.QTextCursor.Start)
|
2019-10-02 02:47:18 +00:00
|
|
|
break
|
|
|
|
# Mark end of undo block
|
|
|
|
cursor.endEditBlock()
|
|
|
|
else:
|
|
|
|
cursor = self.code_editor.textCursor()
|
|
|
|
cursor.beginEditBlock()
|
|
|
|
qc = self.code_editor.textCursor()
|
|
|
|
if qc.hasSelection():
|
|
|
|
qc.insertText(new)
|
|
|
|
# Mark end of undo block
|
|
|
|
cursor.endEditBlock()
|
|
|
|
|
2020-10-24 12:58:20 +00:00
|
|
|
# def handleCopyAll(self):
|
|
|
|
# text = self.code_editor.toPlainText()
|
|
|
|
# self.app.clipboard.setText(text)
|
|
|
|
# self.app.inform.emit(_("Content copied to clipboard ..."))
|
2019-10-02 02:47:18 +00:00
|
|
|
|
2019-10-02 14:58:48 +00:00
|
|
|
# def closeEvent(self, QCloseEvent):
|
|
|
|
# super().closeEvent(QCloseEvent)
|