Coverage for /builds/kinetik161/ase/ase/gui/clipboard.py: 100.00%
20 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-10 11:04 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-10 11:04 +0000
1from ase import Atoms
2from ase.io.jsonio import decode, encode
5class AtomsClipboard:
6 def __init__(self, tk):
7 self.tk = tk
9 def get_text(self) -> str:
10 return self.tk.clipboard_get()
12 def set_text(self, text: str) -> None:
13 self.tk.clipboard_clear()
14 self.tk.clipboard_append(text)
16 def get_atoms(self) -> Atoms:
17 text = self.get_text()
18 atoms = decode(text)
19 if not isinstance(atoms, Atoms):
20 typename = type(atoms).__name__
21 raise ValueError(f'Cannot convert {typename} to Atoms')
22 return atoms
24 def set_atoms(self, atoms: Atoms) -> None:
25 json_text = encode(atoms)
26 self.set_text(json_text)