def export_equipment_template(self, filename: str = None) -> None: """ Exports the currently selected equipment entry to a file. In order to export, we have to run self.edit_equipment_template() first! """ selected_template, table_data = self.get_equipment_entry_data() if not selected_template: return blockname = '__'.join(selected_template.split()) if not filename: filename = cif_file_save_dialog( blockname.replace('__', '_') + '.cif') if not filename.strip(): return equipment_cif = CifContainer(filename, new_block=blockname) for key, value in table_data: equipment_cif[key] = value.strip('\n\r ') try: equipment_cif.save(filename) # Path(filename).write_text(doc.as_string(cif.Style.Indent35)) except PermissionError: if Path(filename).is_dir(): return show_general_warning('No permission to write file to {}'.format( Path(filename).resolve()))
def export_author_template(self, filename: str = None) -> None: """ Exports the currently selected author to a file. """ author = self.get_author_info() selected_template = self.ui.LoopTemplatesListWidget.currentIndex( ).data() if not selected_template: return blockname = '__'.join(selected_template.split()) if not filename: filename = cif_file_save_dialog( blockname.replace('__', '_') + '.cif') if not filename.strip(): return author_cif = CifContainer(filename, new_block=blockname) contact_author: bool = author.get('contact') loop = self.get_author_loop(contact_author) data = [ author.get('name'), author.get('address'), author.get('email'), author.get('phone'), author.get('orcid'), author.get('footnote') ] if contact_author: del data[-1] for key, value in zip(loop, data): author_cif.set_pair_delimited(key, as_string(value)) try: author_cif.save(filename) except PermissionError: if Path(filename).is_dir(): return show_general_warning('No permission to write file to {}'.format( Path(filename).resolve()))