- added more editing features in the Selected Tab for the FlatCAMDocument object

This commit is contained in:
Marius Stanciu 2019-10-03 21:44:37 +03:00 committed by Marius
parent 1d2c046ecc
commit fb0edc6c18
13 changed files with 296 additions and 14 deletions

View File

@ -1232,10 +1232,15 @@ class App(QtCore.QObject):
"script_text": "",
"script_plot": True,
"script_source_file": "",
"document_autocompleter": False,
"document_text": "",
"document_plot": True,
"document_source_file": "",
"document_font_color": '#000000',
"document_sel_color": '#0055ff',
"document_font_size": 6,
"document_tab_size": 80,
})
# ############################################################
@ -4192,7 +4197,7 @@ class App(QtCore.QObject):
kind=obj.kind.capitalize(), color='orange', name=str(obj.options['name'])))
elif obj.kind == 'document':
self.inform.emit(_('[selected] {kind} created/selected: <span style="color:{color};">{name}</span>').format(
kind=obj.kind.capitalize(), color='violet', name=str(obj.options['name'])))
kind=obj.kind.capitalize(), color='darkCyan', name=str(obj.options['name'])))
# update the SHELL auto-completer model with the name of the new object
self.shell._edit.set_model_data(self.myKeywords)

View File

@ -6683,6 +6683,10 @@ class FlatCAMDocument(FlatCAMObj):
self.source_file = ''
self.doc_code = ''
self.font_italic = None
self.font_bold = None
self.font_underline =None
self.document_editor_tab = None
def set_ui(self, ui):
@ -6713,6 +6717,13 @@ class FlatCAMDocument(FlatCAMObj):
))
self.document_editor_tab = TextEditor(app=self.app)
stylesheet = """
QTextEdit {selection-background-color:%s;
selection-color:white;
}
""" % self.app.defaults["document_sel_color"]
self.document_editor_tab.code_editor.setStyleSheet(stylesheet)
# first clear previous text in text editor (if any)
self.document_editor_tab.code_editor.clear()
@ -6722,18 +6733,53 @@ class FlatCAMDocument(FlatCAMObj):
self.ui.autocomplete_cb.set_value(self.app.defaults['document_autocompleter'])
self.on_autocomplete_changed(state=self.app.defaults['document_autocompleter'])
self.on_tab_size_change(val=self.app.defaults['document_tab_size'])
flt = "FlatCAM Docs (*.FlatDoc);;All Files (*.*)"
# ######################################################################
# ######################## SIGNALS #####################################
# ######################################################################
self.document_editor_tab.buttonOpen.clicked.disconnect()
self.document_editor_tab.buttonOpen.clicked.connect(lambda: self.document_editor_tab.handleOpen(filt=flt))
self.document_editor_tab.buttonSave.clicked.disconnect()
self.document_editor_tab.buttonSave.clicked.connect(lambda: self.document_editor_tab.handleSaveGCode(filt=flt))
self.document_editor_tab.code_editor.textChanged.connect(self.on_text_changed)
self.document_editor_tab.handleTextChanged()
self.ui.font_type_cb.currentFontChanged.connect(self.font_family)
self.ui.font_size_cb.activated.connect(self.font_size)
self.ui.font_bold_tb.clicked.connect(self.on_bold_button)
self.ui.font_italic_tb.clicked.connect(self.on_italic_button)
self.ui.font_under_tb.clicked.connect(self.on_underline_button)
self.ui.font_color_entry.editingFinished.connect(self.on_font_color_entry)
self.ui.font_color_button.clicked.connect(self.on_font_color_button)
self.ui.sel_color_entry.editingFinished.connect(self.on_selection_color_entry)
self.ui.sel_color_button.clicked.connect(self.on_selection_color_button)
self.ui.al_left_tb.clicked.connect(lambda: self.document_editor_tab.code_editor.setAlignment(Qt.AlignLeft))
self.ui.al_center_tb.clicked.connect(lambda: self.document_editor_tab.code_editor.setAlignment(Qt.AlignCenter))
self.ui.al_right_tb.clicked.connect(lambda: self.document_editor_tab.code_editor.setAlignment(Qt.AlignRight))
self.ui.al_justify_tb.clicked.connect(
lambda: self.document_editor_tab.code_editor.setAlignment(Qt.AlignJustify)
)
self.ui.autocomplete_cb.stateChanged.connect(self.on_autocomplete_changed)
self.ui.tab_size_spinner.editingFinished.connect(self.on_tab_size_change)
# #######################################################################
self.ui.font_color_entry.set_value(self.app.defaults['document_font_color'])
self.ui.font_color_button.setStyleSheet(
"background-color:%s" % str(self.app.defaults['document_font_color']))
self.ui.sel_color_entry.set_value(self.app.defaults['document_sel_color'])
self.ui.sel_color_button.setStyleSheet(
"background-color:%s" % self.app.defaults['document_sel_color'])
self.ui.font_size_cb.setCurrentIndex(int(self.app.defaults['document_font_size']))
self.document_editor_tab.handleTextChanged()
self.ser_attrs = ['options', 'kind', 'source_file']
for line in self.source_file.splitlines():
@ -6765,10 +6811,106 @@ class FlatCAMDocument(FlatCAMObj):
else:
self.document_editor_tab.code_editor.completer_enable = False
def on_tab_size_change(self, val=None):
try:
self.ui.tab_size_spinner.editingFinished.disconnect(self.on_tab_size_change)
except TypeError:
pass
if val:
self.ui.tab_size_spinner.set_value(val)
tab_balue = int(self.ui.tab_size_spinner.get_value())
self.document_editor_tab.code_editor.setTabStopWidth(tab_balue)
self.app.defaults['document_tab_size'] = tab_balue
self.ui.tab_size_spinner.editingFinished.connect(self.on_tab_size_change)
def on_text_changed(self):
self.source_file = self.document_editor_tab.code_editor.toHtml()
print(self.source_file)
def font_family(self, font):
# self.document_editor_tab.code_editor.selectAll()
font.setPointSize(float(self.ui.font_size_cb.get_value()))
self.document_editor_tab.code_editor.setCurrentFont(font)
self.font_name = self.ui.font_type_cb.currentFont().family()
def font_size(self):
# self.document_editor_tab.code_editor.selectAll()
self.document_editor_tab.code_editor.setFontPointSize(float(self.ui.font_size_cb.get_value()))
def on_bold_button(self):
if self.ui.font_bold_tb.isChecked():
self.document_editor_tab.code_editor.setFontWeight(QtGui.QFont.Bold)
self.font_bold = True
else:
self.document_editor_tab.code_editor.setFontWeight(QtGui.QFont.Normal)
self.font_bold = False
def on_italic_button(self):
if self.ui.font_italic_tb.isChecked():
self.document_editor_tab.code_editor.setFontItalic(True)
self.font_italic = True
else:
self.document_editor_tab.code_editor.setFontItalic(False)
self.font_italic = False
def on_underline_button(self):
if self.ui.font_under_tb.isChecked():
self.document_editor_tab.code_editor.setFontUnderline(True)
self.font_underline = True
else:
self.document_editor_tab.code_editor.setFontUnderline(False)
self.font_underline = False
# Setting font colors handlers
def on_font_color_entry(self):
self.app.defaults['document_font_color'] = self.ui.font_color_entry.get_value()
self.ui.font_color_button.setStyleSheet("background-color:%s" % str(self.app.defaults['document_font_color']))
def on_font_color_button(self):
current_color = QtGui.QColor(self.app.defaults['document_font_color'])
c_dialog = QtWidgets.QColorDialog()
font_color = c_dialog.getColor(initial=current_color)
if font_color.isValid() is False:
return
self.document_editor_tab.code_editor.setTextColor(font_color)
self.ui.font_color_button.setStyleSheet("background-color:%s" % str(font_color.name()))
new_val = str(font_color.name())
self.ui.font_color_entry.set_value(new_val)
self.app.defaults['document_font_color'] = new_val
# Setting selection colors handlers
def on_selection_color_entry(self):
self.app.defaults['document_sel_color'] = self.ui.sel_color_entry.get_value()
self.ui.sel_color_button.setStyleSheet("background-color:%s" % str(self.app.defaults['document_sel_color']))
def on_selection_color_button(self):
current_color = QtGui.QColor(self.app.defaults['document_sel_color'])
c_dialog = QtWidgets.QColorDialog()
sel_color = c_dialog.getColor(initial=current_color)
if sel_color.isValid() is False:
return
p = QtGui.QPalette()
p.setColor(QtGui.QPalette.Highlight, sel_color)
p.setColor(QtGui.QPalette.HighlightedText, QtGui.QColor('white'))
self.document_editor_tab.code_editor.setPalette(p)
self.ui.sel_color_button.setStyleSheet("background-color:%s" % str(sel_color.name()))
new_val = str(sel_color.name())
self.ui.sel_color_entry.set_value(new_val)
self.app.defaults['document_sel_color'] = new_val
def to_dict(self):
"""
Returns a representation of the object as a dictionary.

View File

@ -762,7 +762,7 @@ class ObjectCollection(QtCore.QAbstractItemModel):
color='orange', name=str(obj.options['name'])))
elif obj.kind == 'document':
self.app.inform.emit(_('[selected]<span style="color:{color};">{name}</span> selected').format(
color='violet', name=str(obj.options['name'])))
color='darkCyan', name=str(obj.options['name'])))
except IndexError:
# FlatCAMApp.App.log.debug("on_list_selection_change(): Index Error (Nothing selected?)")
self.app.inform.emit('')

View File

@ -12,7 +12,8 @@ CAD program, and create G-Code for Isolation routing.
3.10.2019
-
- previously I've added the initial layout for the FlatCAMDocument object
- added more editing features in the Selected Tab for the FlatCAMDocument object
2.10.2019

View File

@ -236,7 +236,7 @@ class TextInputTool(FlatCAMTool):
self.font_type_cb = QtWidgets.QFontComboBox(self)
self.font_type_cb.setCurrentFont(f_current)
self.form_layout.addRow("Font:", self.font_type_cb)
self.form_layout.addRow(QtWidgets.QLabel('%s:' % _("Font")), self.font_type_cb)
# Flag variables to show if font is bold, italic, both or none (regular)
self.font_bold = False
@ -308,7 +308,7 @@ class TextInputTool(FlatCAMTool):
self.font_italic_tb.setIcon(QtGui.QIcon('share/italic32.png'))
hlay.addWidget(self.font_italic_tb)
self.form_layout.addRow("Size:", hlay)
self.form_layout.addRow(QtWidgets.QLabel('%s:' % "Size"), hlay)
# Text input
self.text_input_entry = FCTextAreaRich()
@ -317,7 +317,7 @@ class TextInputTool(FlatCAMTool):
# self.text_input_entry.setMaximumHeight(150)
self.text_input_entry.setCurrentFont(f_current)
self.text_input_entry.setFontPointSize(10)
self.form_layout.addRow("Text:", self.text_input_entry)
self.form_layout.addRow(QtWidgets.QLabel('%s:' % _("Text")), self.text_input_entry)
# Buttons
hlay1 = QtWidgets.QHBoxLayout()

View File

@ -2591,6 +2591,10 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
if key == QtCore.Qt.Key_B:
self.app.new_gerber_object()
# New Geometry
if key == QtCore.Qt.Key_D:
self.app.new_document_object()
# Copy Object Name
if key == QtCore.Qt.Key_E:
self.app.object2editor()

View File

@ -660,7 +660,7 @@ class FCTextAreaRich(QtWidgets.QTextEdit):
class FCTextAreaExtended(QtWidgets.QTextEdit):
def __init__(self, parent=None):
super(FCTextAreaExtended, self).__init__(parent)
super().__init__(parent)
self.completer = MyCompleter()

View File

@ -14,6 +14,7 @@
from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5.QtCore import Qt
from flatcamGUI.GUIElements import *
import sys
import gettext
import FlatCAMTranslation as fcTranslate
@ -1793,6 +1794,13 @@ class DocumentObjectUI(ObjectUI):
self.name_hlay.addWidget(name_label)
self.name_hlay.addWidget(self.name_entry)
# Plot CB - this is added only for compatibility; other FlatCAM objects expect it and the mechanism is already
# established and I don't want to changed it right now
self.plot_cb = FCCheckBox()
self.plot_cb.setLayoutDirection(QtCore.Qt.RightToLeft)
self.custom_box.addWidget(self.plot_cb)
self.plot_cb.hide()
h_lay = QtWidgets.QHBoxLayout()
h_lay.setAlignment(QtCore.Qt.AlignVCenter)
self.custom_box.addLayout(h_lay)
@ -1809,12 +1817,134 @@ class DocumentObjectUI(ObjectUI):
h_lay.addWidget(self.autocomplete_cb)
h_lay.addStretch()
# Plot CB - this is added only for compatibility; other FlatCAM objects expect it and the mechanism is already
# established and I don't want to changed it right now
self.plot_cb = FCCheckBox()
self.plot_cb.setLayoutDirection(QtCore.Qt.RightToLeft)
self.custom_box.addWidget(self.plot_cb)
self.plot_cb.hide()
# ##############################################################
# ############ FORM LAYOUT #####################################
# ##############################################################
self.form_box = QtWidgets.QFormLayout()
self.custom_box.addLayout(self.form_box)
# Font
self.font_type_label = QtWidgets.QLabel('%s:' % _("Font Type"))
if sys.platform == "win32":
f_current = QtGui.QFont("Arial")
elif sys.platform == "linux":
f_current = QtGui.QFont("FreeMono")
else:
f_current = QtGui.QFont("Helvetica Neue")
self.font_name = f_current.family()
self.font_type_cb = QtWidgets.QFontComboBox(self)
self.font_type_cb.setCurrentFont(f_current)
self.form_box.addRow(self.font_type_label, self.font_type_cb)
# Font Size
self.font_size_label = QtWidgets.QLabel('%s:' % _("Font Size"))
self.font_size_cb = FCComboBox()
self.font_size_cb.setEditable(True)
self.font_size_cb.setMinimumContentsLength(3)
self.font_size_cb.setMaximumWidth(70)
font_sizes = ['6', '7', '8', '9', '10', '11', '12', '13', '14',
'15', '16', '18', '20', '22', '24', '26', '28',
'32', '36', '40', '44', '48', '54', '60', '66',
'72', '80', '88', '96']
for i in font_sizes:
self.font_size_cb.addItem(i)
size_hlay = QtWidgets.QHBoxLayout()
size_hlay.addWidget(self.font_size_cb)
size_hlay.addStretch()
self.font_bold_tb = QtWidgets.QToolButton()
self.font_bold_tb.setCheckable(True)
self.font_bold_tb.setIcon(QtGui.QIcon('share/bold32.png'))
size_hlay.addWidget(self.font_bold_tb)
self.font_italic_tb = QtWidgets.QToolButton()
self.font_italic_tb.setCheckable(True)
self.font_italic_tb.setIcon(QtGui.QIcon('share/italic32.png'))
size_hlay.addWidget(self.font_italic_tb)
self.font_under_tb = QtWidgets.QToolButton()
self.font_under_tb.setCheckable(True)
self.font_under_tb.setIcon(QtGui.QIcon('share/underline32.png'))
size_hlay.addWidget(self.font_under_tb)
self.form_box.addRow(self.font_size_label, size_hlay)
# Alignment Choices
self.alignment_label = QtWidgets.QLabel('%s:' % _("Alignment"))
al_hlay = QtWidgets.QHBoxLayout()
self.al_left_tb = QtWidgets.QToolButton()
self.al_left_tb.setToolTip(_("Align Left"))
self.al_left_tb.setIcon(QtGui.QIcon('share/align_left32.png'))
al_hlay.addWidget(self.al_left_tb)
self.al_center_tb = QtWidgets.QToolButton()
self.al_center_tb.setToolTip(_("Center"))
self.al_center_tb.setIcon(QtGui.QIcon('share/align_center32.png'))
al_hlay.addWidget(self.al_center_tb)
self.al_right_tb = QtWidgets.QToolButton()
self.al_right_tb.setToolTip(_("Align Right"))
self.al_right_tb.setIcon(QtGui.QIcon('share/align_right32.png'))
al_hlay.addWidget(self.al_right_tb)
self.al_justify_tb = QtWidgets.QToolButton()
self.al_justify_tb.setToolTip(_("Justify"))
self.al_justify_tb.setIcon(QtGui.QIcon('share/align_justify32.png'))
al_hlay.addWidget(self.al_justify_tb)
self.form_box.addRow(self.alignment_label, al_hlay)
# Font Color
self.font_color_label = QtWidgets.QLabel('%s:' % _('Font Color'))
self.font_color_label.setToolTip(
_("Set the font color for the selected text")
)
self.font_color_entry = FCEntry()
self.font_color_button = QtWidgets.QPushButton()
self.font_color_button.setFixedSize(15, 15)
self.form_box_child_1 = QtWidgets.QHBoxLayout()
self.form_box_child_1.addWidget(self.font_color_entry)
self.form_box_child_1.addWidget(self.font_color_button)
self.form_box_child_1.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
self.form_box.addRow(self.font_color_label, self.form_box_child_1)
# Selection Color
self.sel_color_label = QtWidgets.QLabel('%s:' % _('Selection Color'))
self.sel_color_label.setToolTip(
_("Set the selection color when doing text selection.")
)
self.sel_color_entry = FCEntry()
self.sel_color_button = QtWidgets.QPushButton()
self.sel_color_button.setFixedSize(15, 15)
self.form_box_child_2 = QtWidgets.QHBoxLayout()
self.form_box_child_2.addWidget(self.sel_color_entry)
self.form_box_child_2.addWidget(self.sel_color_button)
self.form_box_child_2.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
self.form_box.addRow(self.sel_color_label, self.form_box_child_2)
# Tab size
self.tab_size_label = QtWidgets.QLabel('%s:' % _('Tab Size'))
self.tab_size_label.setToolTip(
_("Set the tab size. In pixels. Default value is 80 pixels.")
)
self.tab_size_spinner = FCSpinner()
self.tab_size_spinner.set_range(0, 1000)
self.form_box.addRow(self.tab_size_label, self.tab_size_spinner)
self.custom_box.addStretch()

BIN
share/align_center32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 212 B

BIN
share/align_justify32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 B

BIN
share/align_left32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

BIN
share/align_right32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

BIN
share/underline32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 B