- changes for the Document object

This commit is contained in:
Marius Stanciu 2019-10-03 17:15:21 +03:00
parent d7649d2118
commit 1d2c046ecc
5 changed files with 118 additions and 0 deletions

View File

@ -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)

View File

@ -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):
'<span style="color:red;"><b>Advanced</b></span>'
))
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

View File

@ -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

View File

@ -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)

View File

@ -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()