Templates/TemplateViewer.py

branch
Py2 comp.
changeset 3060
5883ce99ee12
parent 3058
0a02c433f52d
parent 3039
8dd0165d805d
child 3145
a9de05d4a22f
equal deleted inserted replaced
3058:0a02c433f52d 3060:5883ce99ee12
98 QApplication.translate("TemplateGroup", "Add Template"), 98 QApplication.translate("TemplateGroup", "Add Template"),
99 QApplication.translate( 99 QApplication.translate(
100 "TemplateGroup", 100 "TemplateGroup",
101 """<p>The group <b>{0}</b> already contains a""" 101 """<p>The group <b>{0}</b> already contains a"""
102 """ template named <b>{1}</b>.</p>""") 102 """ template named <b>{1}</b>.</p>""")
103 .format(self.name, name)) 103 .format(self.name, name))
104 return 104 return
105 105
106 self.entries[name] = TemplateEntry(self, name, description, template) 106 self.entries[name] = TemplateEntry(self, name, description, template)
107 107
108 if Preferences.getTemplates("AutoOpenGroups") and \ 108 if Preferences.getTemplates("AutoOpenGroups") and \
524 """ 524 """
525 itm = self.currentItem() 525 itm = self.currentItem()
526 res = E5MessageBox.yesNo( 526 res = E5MessageBox.yesNo(
527 self, 527 self,
528 self.trUtf8("Remove Template"), 528 self.trUtf8("Remove Template"),
529 self.trUtf8("""<p>Do you really want to remove <b>{0}</b>?</p>""")\ 529 self.trUtf8("""<p>Do you really want to remove <b>{0}</b>?</p>""")
530 .format(itm.getName())) 530 .format(itm.getName()))
531 if not res: 531 if not res:
532 return 532 return
533 533
534 if isinstance(itm, TemplateGroup): 534 if isinstance(itm, TemplateGroup):
535 self.removeGroup(itm) 535 self.removeGroup(itm)
643 dir_name, file_name = os.path.split(path_name) 643 dir_name, file_name = os.path.split(path_name)
644 base_name, ext = os.path.splitext(file_name) 644 base_name, ext = os.path.splitext(file_name)
645 if ext: 645 if ext:
646 ext = ext[1:] 646 ext = ext[1:]
647 varValues.update({ 647 varValues.update({
648 keyfmt.format('path_name'): path_name, 648 keyfmt.format('path_name'): path_name,
649 keyfmt.format('dir_name'): dir_name, 649 keyfmt.format('dir_name'): dir_name,
650 keyfmt.format('file_name'): file_name, 650 keyfmt.format('file_name'): file_name,
651 keyfmt.format('base_name'): base_name, 651 keyfmt.format('base_name'): base_name,
652 keyfmt.format('ext'): ext 652 keyfmt.format('ext'): ext
653 }) 653 })
654 654
655 varValues[keyfmt.format('clipboard:ml')] = \ 655 varValues[keyfmt.format('clipboard:ml')] = \
656 QApplication.clipboard().text() 656 QApplication.clipboard().text()
657 varValues[keyfmt.format('clipboard')] = \ 657 varValues[keyfmt.format('clipboard')] = \
713 else: 713 else:
714 ok = True 714 ok = True
715 715
716 if ok: 716 if ok:
717 line = editor.text(editor.getCursorPosition()[0])\ 717 line = editor.text(editor.getCursorPosition()[0])\
718 .replace(os.linesep, "") 718 .replace(os.linesep, "")
719 indent = line.replace(line.lstrip(), "") 719 indent = line.replace(line.lstrip(), "")
720 txt, lines, count = itm.getExpandedText(varValues, indent) 720 txt, lines, count = itm.getExpandedText(varValues, indent)
721 # It should be done in this way to allow undo 721 # It should be done in this way to allow undo
722 editor.beginUndoAction() 722 editor.beginUndoAction()
723 if editor.hasSelectedText(): 723 if editor.hasSelectedText():
850 if newname in self.groups: 850 if newname in self.groups:
851 E5MessageBox.warning( 851 E5MessageBox.warning(
852 self, 852 self,
853 self.trUtf8("Edit Template Group"), 853 self.trUtf8("Edit Template Group"),
854 self.trUtf8("""<p>A template group with the name""" 854 self.trUtf8("""<p>A template group with the name"""
855 """ <b>{0}</b> already exists.</p>""")\ 855 """ <b>{0}</b> already exists.</p>""")
856 .format(newname)) 856 .format(newname))
857 return 857 return
858 858
859 self.groups[newname] = self.groups[oldname] 859 self.groups[newname] = self.groups[oldname]
860 del self.groups[oldname] 860 del self.groups[oldname]
861 self.groups[newname].setName(newname) 861 self.groups[newname].setName(newname)
946 self, 946 self,
947 self.trUtf8("Save templates"), 947 self.trUtf8("Save templates"),
948 self.trUtf8( 948 self.trUtf8(
949 "<p>The templates file <b>{0}</b> could not be" 949 "<p>The templates file <b>{0}</b> could not be"
950 " written.</p>") 950 " written.</p>")
951 .format(filename)) 951 .format(filename))
952 return False 952 return False
953 953
954 from E5XML.TemplatesWriter import TemplatesWriter 954 from E5XML.TemplatesWriter import TemplatesWriter
955 TemplatesWriter(f, self).writeXML() 955 TemplatesWriter(f, self).writeXML()
956 f.close() 956 f.close()
979 E5MessageBox.critical( 979 E5MessageBox.critical(
980 self, 980 self,
981 self.trUtf8("Read templates"), 981 self.trUtf8("Read templates"),
982 self.trUtf8( 982 self.trUtf8(
983 "<p>The templates file <b>{0}</b> could not be read.</p>") 983 "<p>The templates file <b>{0}</b> could not be read.</p>")
984 .format(filename)) 984 .format(filename))
985 985
986 def __configure(self): 986 def __configure(self):
987 """ 987 """
988 Private method to open the configuration dialog. 988 Private method to open the configuration dialog.
989 """ 989 """

eric ide

mercurial