856 """ |
856 """ |
857 Public method to write the templates data to an XML file (.e4c). |
857 Public method to write the templates data to an XML file (.e4c). |
858 |
858 |
859 @param filename name of a templates file to read (string) |
859 @param filename name of a templates file to read (string) |
860 """ |
860 """ |
861 try: |
861 if filename is None: |
862 if filename is None: |
862 filename = os.path.join(Utilities.getConfigDir(), "eric5templates.e4c") |
863 filename = os.path.join(Utilities.getConfigDir(), "eric5templates.e4c") |
863 f = QFile(filename) |
864 f = open(filename, "w", encoding = "utf-8") |
864 ok = f.open(QIODevice.WriteOnly) |
865 |
865 if not ok: |
866 TemplatesWriter(f, self).writeXML() |
|
867 |
|
868 f.close() |
|
869 except IOError: |
|
870 E5MessageBox.critical(self, |
866 E5MessageBox.critical(self, |
871 self.trUtf8("Save templates"), |
867 self.trUtf8("Save templates"), |
872 self.trUtf8("<p>The templates file <b>{0}</b> could not be written.</p>") |
868 self.trUtf8("<p>The templates file <b>{0}</b> could not be written.</p>") |
873 .format(filename)) |
869 .format(filename)) |
874 |
870 return |
|
871 |
|
872 TemplatesWriter(f, self).writeXML() |
|
873 f.close() |
|
874 |
875 def readTemplates(self, filename = None): |
875 def readTemplates(self, filename = None): |
876 """ |
876 """ |
877 Public method to read in the templates file (.e4c) |
877 Public method to read in the templates file (.e4c) |
878 |
878 |
879 @param filename name of a templates file to read (string) |
879 @param filename name of a templates file to read (string) |