Esempio n. 1
0
 def setData(self, index: QModelIndex, value: Any, role: int = None) -> bool:
     row, col = index.row(), index.column()
     previous = self._original[row][col]
     if not index:
         return False
     if index.isValid() and role == Qt.EditRole and value != previous:
         self._data[row][col] = value
         self.modified.append({'row': row, 'column': col, 'previous': previous})
         self.modelChanged.emit(row, col, utf8_to_str(value), self._header)
         return True
     return False
Esempio n. 2
0
 def set_pair_delimited(self, key: str, txt: str):
     """
     Converts special characters to their markup counterparts.
     """
     txt = utf8_to_str(txt)
     try:
         # bad hack to get the numbered values correct
         float(txt)
         self.block.set_pair(key, txt)
     except (TypeError, ValueError):
         # prevent _key '?' in cif:
         if txt == '?':
             self.block.set_pair(key, txt)
         else:
             self.block.set_pair(key, quote(txt))
Esempio n. 3
0
 def export_property_template(self, filename: str = '') -> None:
     """
     Exports the currently selected property entry to a file.
     """
     selected_row_text = self.app.ui.PropertiesTemplatesListWidget.currentIndex(
     ).data()
     if not selected_row_text:
         return
     prop_data = self.settings.load_settings_list('property',
                                                  selected_row_text)
     table_data = []
     cif_key = ''
     if prop_data:
         cif_key = prop_data[0]
         with suppress(Exception):
             table_data = prop_data[1]
     if not cif_key:
         return
     doc = cif.Document()
     blockname = '__'.join(selected_row_text.split())
     block = doc.add_new_block(blockname)
     try:
         loop = block.init_loop(cif_key, [''])
     except RuntimeError:
         # Not a valid loop key
         show_general_warning(
             '"{}" is not a valid cif keyword.'.format(cif_key))
         return
     for value in table_data:
         if value:
             loop.add_row([cif.quote(utf8_to_str(value))])
     if not filename:
         filename = cif_file_save_dialog(
             blockname.replace('__', '_') + '.cif')
     if not filename.strip():
         return
     try:
         doc.write_file(filename, style=cif.Style.Indent35)
         # 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()))
Esempio n. 4
0
 def get_author_info(self) -> Dict[str, Union[str, bool, None]]:
     name = quote(utf8_to_str(self.ui.FullNameLineEdit.text()))
     address = quote(utf8_to_str(self.ui.AddressTextedit.toPlainText()))
     email = quote(utf8_to_str(self.ui.EMailLineEdit.text()))
     footnote = quote(utf8_to_str(self.ui.FootNoteLineEdit.text()))
     orcid = quote(utf8_to_str(self.ui.ORCIDLineEdit.text()))
     phone = quote(utf8_to_str(self.ui.PhoneLineEdit.text()))
     contact: bool = self.ui.ContactAuthorCheckBox.isChecked()
     return {
         'address': address,
         'footnote': footnote,
         'email': email,
         'name': name,
         'orcid': orcid,
         'phone': phone,
         'contact': contact
     }
Esempio n. 5
0
 def test_encode_and_decode_utf8(self):
     # Test for quote and immediate decode to utf-8 again:
     self.assertEqual(self.txt,
                      retranslate_delimiter(utf8_to_str(self.txt)))
Esempio n. 6
0
 def test_encode_heavy_utf8(self):
     # Test for the quoted string
     self.assertEqual(self.quoted, utf8_to_str(self.txt))
Esempio n. 7
0
 def test_delimit_ut8_to_cif_str(self):
     s = utf8_to_str('100 °C')
     self.assertEqual(r'100 \%C', s)