def OnAdd(self, event): dialog = wx.TextEntryDialog(self, "Enter Template Name", "Template Entry Dialog", style=wx.OK | wx.CANCEL) if dialog.ShowModal() == wx.ID_OK: value = dialog.GetValue() if value != "": if not self.templates.contains(value): template = Template() template.set_name(value) self.templates.add(template) self.templates_list.Set(self.templates.names()) self.removeButton.Disable() self.template = None self.in_use = False self.addFieldButton.Disable() self.editFieldButton.Disable() self.removeFieldButton.Disable() self.moveUp.Disable() self.moveDown.Disable() self.repoman.RepositoryModified() self.statusbar.SetStatusText("") self.ConfigureGrid() else: dialog = wx.MessageDialog(None, 'Template "' + value + '" already exists!', "Duplicate Template", wx.OK | wx.ICON_INFORMATION) dialog.ShowModal() else: dialog = wx.MessageDialog(None, 'Template name not specified!', "Illegal Template Name", wx.OK | wx.ICON_INFORMATION) dialog.ShowModal() dialog.Destroy()
def load(self, path): templates_path = os.path.join(path, 'templates.txt') templates_file = open(templates_path, "U") lines = templates_file.readlines() templates_file.close() lines = [line.strip() for line in lines] lines = [line for line in lines if line != ''] while len(lines) > 0: try: begin_index = lines.index('BEGIN TEMPLATE') end_index = lines.index('END TEMPLATE') template = Template() template.load(lines[begin_index+1:end_index]) self.add(template) del lines[begin_index:end_index+1] except: pass