From fb0edc6c18c26ed6a30264ae418630c5023270eb Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Thu, 3 Oct 2019 21:44:37 +0300 Subject: [PATCH] - added more editing features in the Selected Tab for the FlatCAMDocument object --- FlatCAMApp.py | 7 +- FlatCAMObj.py | 144 ++++++++++++++++++++++++++++- ObjectCollection.py | 2 +- README.md | 3 +- flatcamEditors/FlatCAMGeoEditor.py | 6 +- flatcamGUI/FlatCAMGUI.py | 4 + flatcamGUI/GUIElements.py | 2 +- flatcamGUI/ObjectUI.py | 142 ++++++++++++++++++++++++++-- share/align_center32.png | Bin 0 -> 212 bytes share/align_justify32.png | Bin 0 -> 167 bytes share/align_left32.png | Bin 0 -> 201 bytes share/align_right32.png | Bin 0 -> 190 bytes share/underline32.png | Bin 0 -> 354 bytes 13 files changed, 296 insertions(+), 14 deletions(-) create mode 100644 share/align_center32.png create mode 100644 share/align_justify32.png create mode 100644 share/align_left32.png create mode 100644 share/align_right32.png create mode 100644 share/underline32.png diff --git a/FlatCAMApp.py b/FlatCAMApp.py index aa0f9d05..7d7087d4 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -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: {name}').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) diff --git a/FlatCAMObj.py b/FlatCAMObj.py index 229be60a..429216b1 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -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. diff --git a/ObjectCollection.py b/ObjectCollection.py index 33eccd38..6f838cee 100644 --- a/ObjectCollection.py +++ b/ObjectCollection.py @@ -762,7 +762,7 @@ class ObjectCollection(QtCore.QAbstractItemModel): color='orange', name=str(obj.options['name']))) elif obj.kind == 'document': self.app.inform.emit(_('[selected]{name} 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('') diff --git a/README.md b/README.md index 1ab515f4..82a0abec 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/flatcamEditors/FlatCAMGeoEditor.py b/flatcamEditors/FlatCAMGeoEditor.py index 58373185..1cb1d797 100644 --- a/flatcamEditors/FlatCAMGeoEditor.py +++ b/flatcamEditors/FlatCAMGeoEditor.py @@ -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() diff --git a/flatcamGUI/FlatCAMGUI.py b/flatcamGUI/FlatCAMGUI.py index 192aec51..9b5dbc78 100644 --- a/flatcamGUI/FlatCAMGUI.py +++ b/flatcamGUI/FlatCAMGUI.py @@ -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() diff --git a/flatcamGUI/GUIElements.py b/flatcamGUI/GUIElements.py index ba116ada..1b40d340 100644 --- a/flatcamGUI/GUIElements.py +++ b/flatcamGUI/GUIElements.py @@ -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() diff --git a/flatcamGUI/ObjectUI.py b/flatcamGUI/ObjectUI.py index d28aae6c..f963b6ae 100644 --- a/flatcamGUI/ObjectUI.py +++ b/flatcamGUI/ObjectUI.py @@ -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() diff --git a/share/align_center32.png b/share/align_center32.png new file mode 100644 index 0000000000000000000000000000000000000000..6f9470dbd7942db75131439ab2397f2ae2693625 GIT binary patch literal 212 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7l!{JxM1({$v}}#PZ!6K zh}O5$4Y?W&1X!M{JYfD}Zg=$3{TJ4M=7z0Yvt`5Nh6D?<1hz{uin|kcayRZzKCs5D zK#P|pAzW(3iH$C6S>4q4idx(=`+8^Y!;Qa|M@%kXSQ8{Dal!KC+m7dcl@bOkcs-0Y z7jZ8U4C#__`CrBDv`DP+q^G{s+~}WujI(bw{7K%V!5gA?z}4#Y%WDB`Ku0lny85}S Ib4q9e0Ms5)?f?J) literal 0 HcmV?d00001 diff --git a/share/align_justify32.png b/share/align_justify32.png new file mode 100644 index 0000000000000000000000000000000000000000..3e4b44fc294cfcb29d595621fa8b360afbcb0664 GIT binary patch literal 167 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7l!{JxM1({$v}}9PZ!6K zh}O5$9eEEJ@EnL|JTyR-M72)x}SH^avD*3kx6U4^qv{yvRcSP$ll1*SCG^f8~vD?l@L9w;+2D~c0iUqv`FTn*1 z1;N(N$_2IY2eGiwA_0?OcV{+<=t5qY;!D0Wb0!nW2`zt2CvtxegF=0V&xmFThlTnM z*YjJ;7~-oidI_5KKr@`x+^y=YDOv-qf!084VBrj`G}M!9;5De%66OqhUg{Va2lZBh zf$gBaPtZ(dSNY3!Zno(zMuBFhj)4xYf(cJdK8hYrgWgM#%n=JDWT9lF{BnKZ!p{+H zU?0ncp7;FPO~M*c4)CbFyIJEQ*EC8W$Ff~dTX>A4yf=xIBbdYho3i)?&$yN4zr`Z< z1o~L5xyBows*1x@TxI<4R6OsGNfm1Sn6&&l-$lz)@!sQgP5=M^07*qoM6N<$f`JpB A%>V!Z literal 0 HcmV?d00001