From 1d2c046ecc397f27c86d7600d95631d419123cad Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Thu, 3 Oct 2019 17:15:21 +0300 Subject: [PATCH] - changes for the Document object --- FlatCAMApp.py | 2 + FlatCAMObj.py | 90 ++++++++++++++++++++++++++++++++++++++++ README.md | 4 ++ flatcamGUI/FlatCAMGUI.py | 6 +++ flatcamGUI/ObjectUI.py | 16 +++++++ 5 files changed, 118 insertions(+) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index badff99a..aa0f9d05 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -1232,6 +1232,7 @@ class App(QtCore.QObject): "script_text": "", "script_plot": True, "script_source_file": "", + "document_autocompleter": False, "document_text": "", "document_plot": True, "document_source_file": "", @@ -1747,6 +1748,7 @@ class App(QtCore.QObject): self.ui.menufilenewgeo.triggered.connect(self.new_geometry_object) self.ui.menufilenewgrb.triggered.connect(self.new_gerber_object) self.ui.menufilenewexc.triggered.connect(self.new_excellon_object) + self.ui.menufilenewdoc.triggered.connect(self.new_document_object) self.ui.menufileopengerber.triggered.connect(self.on_fileopengerber) self.ui.menufileopenexcellon.triggered.connect(self.on_fileopenexcellon) diff --git a/FlatCAMObj.py b/FlatCAMObj.py index 2facfce6..229be60a 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -6676,6 +6676,15 @@ class FlatCAMDocument(FlatCAMObj): self.kind = "document" + self.units = '' + self.decimals = 4 + + self.ser_attrs = ['options', 'kind', 'source_file'] + self.source_file = '' + self.doc_code = '' + + self.document_editor_tab = None + def set_ui(self, ui): FlatCAMObj.set_ui(self, ui) FlatCAMApp.App.log.debug("FlatCAMDocument.set_ui()") @@ -6703,9 +6712,90 @@ class FlatCAMDocument(FlatCAMObj): 'Advanced' )) + self.document_editor_tab = TextEditor(app=self.app) + + # first clear previous text in text editor (if any) + self.document_editor_tab.code_editor.clear() + self.document_editor_tab.code_editor.setReadOnly(False) + + self.document_editor_tab.buttonRun.hide() + + self.ui.autocomplete_cb.set_value(self.app.defaults['document_autocompleter']) + self.on_autocomplete_changed(state=self.app.defaults['document_autocompleter']) + + flt = "FlatCAM Docs (*.FlatDoc);;All Files (*.*)" + 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.autocomplete_cb.stateChanged.connect(self.on_autocomplete_changed) + + self.ser_attrs = ['options', 'kind', 'source_file'] + + for line in self.source_file.splitlines(): + self.document_editor_tab.code_editor.append(line) + self.build_ui() def build_ui(self): FlatCAMObj.build_ui(self) + tab_here = False + + # try to not add too many times a tab that it is already installed + for idx in range(self.app.ui.plot_tab_area.count()): + if self.app.ui.plot_tab_area.widget(idx).objectName() == self.options['name']: + tab_here = True + break + + # add the tab if it is not already added + if tab_here is False: + self.app.ui.plot_tab_area.addTab(self.document_editor_tab, '%s' % _("Document Editor")) + self.document_editor_tab.setObjectName(self.options['name']) + + # Switch plot_area to CNCJob tab + self.app.ui.plot_tab_area.setCurrentWidget(self.document_editor_tab) + + def on_autocomplete_changed(self, state): + if state: + self.document_editor_tab.code_editor.completer_enable = True + else: + self.document_editor_tab.code_editor.completer_enable = False + + def on_text_changed(self): + self.source_file = self.document_editor_tab.code_editor.toHtml() + print(self.source_file) + + def to_dict(self): + """ + Returns a representation of the object as a dictionary. + Attributes to include are listed in ``self.ser_attrs``. + + :return: A dictionary-encoded copy of the object. + :rtype: dict + """ + d = {} + for attr in self.ser_attrs: + d[attr] = getattr(self, attr) + return d + + def from_dict(self, d): + """ + Sets object's attributes from a dictionary. + Attributes to include are listed in ``self.ser_attrs``. + This method will look only for only and all the + attributes in ``self.ser_attrs``. They must all + be present. Use only for deserializing saved + objects. + + :param d: Dictionary of attributes to set in the object. + :type d: dict + :return: None + """ + for attr in self.ser_attrs: + setattr(self, attr, d[attr]) # end of file diff --git a/README.md b/README.md index 312c579c..1ab515f4 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,10 @@ CAD program, and create G-Code for Isolation routing. ================================================= +3.10.2019 + +- + 2.10.2019 - fixed bug in Geometry Editor that did not allow the copy of geometric elements diff --git a/flatcamGUI/FlatCAMGUI.py b/flatcamGUI/FlatCAMGUI.py index 318e945f..192aec51 100644 --- a/flatcamGUI/FlatCAMGUI.py +++ b/flatcamGUI/FlatCAMGUI.py @@ -71,6 +71,12 @@ class FlatCAMGUI(QtWidgets.QMainWindow): self.menufilenewexc.setToolTip( _("Will create a new, empty Excellon Object.") ) + self.menufilenew.addSeparator() + + self.menufilenewdoc = self.menufilenew.addAction(QtGui.QIcon('share/notes16_1.png'), _('Document\tD')) + self.menufilenewdoc.setToolTip( + _("Will create a new, empty Document Object.") + ) self.menufile_open = self.menufile.addMenu(QtGui.QIcon('share/folder32_bis.png'), _('Open')) self.menufile_open.setToolTipsVisible(True) diff --git a/flatcamGUI/ObjectUI.py b/flatcamGUI/ObjectUI.py index 5448b42f..d28aae6c 100644 --- a/flatcamGUI/ObjectUI.py +++ b/flatcamGUI/ObjectUI.py @@ -1793,6 +1793,22 @@ class DocumentObjectUI(ObjectUI): self.name_hlay.addWidget(name_label) self.name_hlay.addWidget(self.name_entry) + h_lay = QtWidgets.QHBoxLayout() + h_lay.setAlignment(QtCore.Qt.AlignVCenter) + self.custom_box.addLayout(h_lay) + + self.autocomplete_cb = FCCheckBox("%s" % _("Auto Completer")) + self.autocomplete_cb.setToolTip( + _("This selects if the auto completer is enabled in the Document Editor.") + ) + self.autocomplete_cb.setStyleSheet( + """ + QCheckBox {font-weight: bold; color: black} + """ + ) + 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()