diff --git a/FlatCAMObj.py b/FlatCAMObj.py index e51ca928..6d549270 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -6546,6 +6546,8 @@ class FlatCAMScript(FlatCAMObj): for line in self.source_file.splitlines(): self.script_editor_tab.code_editor.append(line) + self.ser_attrs = ['options', 'kind', 'source_file'] + self.build_ui() def build_ui(self): @@ -6617,6 +6619,35 @@ class FlatCAMScript(FlatCAMObj): else: self.script_editor_tab.code_editor.completer_enable = False + 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]) + class FlatCAMDocument(FlatCAMObj): """ diff --git a/README.md b/README.md index bfc79fcb..a2231ed5 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,8 @@ CAD program, and create G-Code for Isolation routing. - reused the Multiprocessing Pool declared in the App for the ToolRulesCheck() class - adapted the Project context menu for the new types of FLatCAM objects - modified the setup_recent_files to accommodate the new FlatCAM objects -- made sure that when an FlatCAM script object is deleted, it's associated Tab is closed +- made sure that when an FlatCAMscript object is deleted, it's associated Tab is closed +- fixed the FlatCMAScript object saving when project is saved (loading a project with this script object is not working yet) 1.10.2019