Templates/TemplateViewer.py

changeset 537
72b32daeb8d6
parent 536
6d8d39753c82
child 538
7f1a56e80124
equal deleted inserted replaced
536:6d8d39753c82 537:72b32daeb8d6
98 @param template template text of the entry (string) 98 @param template template text of the entry (string)
99 @param quiet flag indicating quiet operation (boolean) 99 @param quiet flag indicating quiet operation (boolean)
100 """ 100 """
101 if name in self.entries: 101 if name in self.entries:
102 if not quiet: 102 if not quiet:
103 QMessageBox.critical(None, 103 E5MessageBox.critical(None,
104 QApplication.translate("TemplateGroup", "Add Template"), 104 QApplication.translate("TemplateGroup", "Add Template"),
105 QApplication.translate("TemplateGroup", 105 QApplication.translate("TemplateGroup",
106 """<p>The group <b>{0}</b> already contains a""" 106 """<p>The group <b>{0}</b> already contains a"""
107 """ template named <b>{1}</b>.</p>""")\ 107 """ template named <b>{1}</b>.</p>""")\
108 .format(self.name, name)) 108 .format(self.name, name))
869 869
870 TemplatesWriter(f, self).writeXML() 870 TemplatesWriter(f, self).writeXML()
871 871
872 f.close() 872 f.close()
873 except IOError: 873 except IOError:
874 QMessageBox.critical(None, 874 E5MessageBox.critical(self,
875 self.trUtf8("Save templates"), 875 self.trUtf8("Save templates"),
876 self.trUtf8("<p>The templates file <b>{0}</b> could not be written.</p>") 876 self.trUtf8("<p>The templates file <b>{0}</b> could not be written.</p>")
877 .format(filename)) 877 .format(filename))
878 878
879 def readTemplates(self, filename = None): 879 def readTemplates(self, filename = None):
890 f = open(filename, "r", encoding = "utf-8") 890 f = open(filename, "r", encoding = "utf-8")
891 line = f.readline() 891 line = f.readline()
892 dtdLine = f.readline() 892 dtdLine = f.readline()
893 f.close() 893 f.close()
894 except IOError: 894 except IOError:
895 QMessageBox.critical(None, 895 E5MessageBox.critical(self,
896 self.trUtf8("Read templates"), 896 self.trUtf8("Read templates"),
897 self.trUtf8("<p>The templates file <b>{0}</b> could not be read.</p>") 897 self.trUtf8("<p>The templates file <b>{0}</b> could not be read.</p>")
898 .format(filename)) 898 .format(filename))
899 return 899 return
900 900
919 buf = io.StringIO(f.read()) 919 buf = io.StringIO(f.read())
920 parser.parse(buf) 920 parser.parse(buf)
921 finally: 921 finally:
922 f.close() 922 f.close()
923 except IOError: 923 except IOError:
924 QMessageBox.critical(None, 924 E5MessageBox.critical(self,
925 self.trUtf8("Read templates"), 925 self.trUtf8("Read templates"),
926 self.trUtf8("<p>The templates file <b>{0}</b> could not be read.</p>") 926 self.trUtf8("<p>The templates file <b>{0}</b> could not be read.</p>")
927 .format(filename)) 927 .format(filename))
928 return 928 return
929 except XMLFatalParseError: 929 except XMLFatalParseError:
930 pass 930 pass
931 931
932 eh.showParseMessages() 932 eh.showParseMessages()
933 else: 933 else:
934 QMessageBox.critical(None, 934 E5MessageBox.critical(self,
935 self.trUtf8("Read templates"), 935 self.trUtf8("Read templates"),
936 self.trUtf8("<p>The templates file <b>{0}</b> has an" 936 self.trUtf8("<p>The templates file <b>{0}</b> has an"
937 " unsupported format.</p>") 937 " unsupported format.</p>")
938 .format(filename)) 938 .format(filename))
939 939

eric ide

mercurial