def new_record(self, event): """Insert new record. Get values by presenting an empty form""" # does user want to fill with template ? template_name = None # show template chooser only if there are some templates if len(self.tpl_files) > 0: template_chooser = TemplateChooser(None, self.project_dir, self.tpl_files) if template_chooser.ShowModal() == wx.ID_CANCEL: return elif template_chooser.ShowModal() == wx.ID_OK: template_name = template_chooser.chosentemplate template_chooser.Destroy() if template_name == None: form = Form(None, self.fields_file, 'Fill in the values') else: template_vals = yaml.load(open(template_name)) form = Form(None, self.fields_file, 'Fill in the values', template_vals) if form.ShowModal() == wx.ID_OK: form.get_values() # Initialise lock as open form.vals['LOCK_STATUS'] = 'unlocked' self.records.insert_record(form.vals) # recreate index #self.register.index_summary = self.records.create_index() self.register.refresh_records() form.Destroy()
def new_template(self, event): """Create a new template""" form = Form(None, self.fields_file, 'Fill in the values for template') if form.ShowModal() == wx.ID_OK: form.get_values() template_vals = form.vals form.Destroy() # get template name name_entry = wx.TextEntryDialog(None, 'Enter name for template') if name_entry.ShowModal() == wx.ID_OK: template_name = name_entry.GetValue() if not template_name.endswith('.tpl'): template_name += '.tpl' template_name = os.path.join(self.project_dir, template_name) else: return # write the template yaml.dump(template_vals, open(template_name, 'w'))