def __repr__(self): r = _Composition.__repr__(self)[:-2] if len(self) > 0: for z, fraction in self.items(): r += ', %s=%s' % (ep.get_symbol(z), fraction) return r + ')>'
def selectionSymbol(self): selection = self.selection() if self.isMultipleSelection(): return frozenset(map(get_symbol, selection)) else: if selection is None: return None else: return get_symbol(selection)
def selection(self): selection = None for widget in self._group.buttons(): if widget.isChecked(): selection = self._group.id(widget) if selection != None: return [selection, get_symbol(selection)] else: return None
def __init__(self, atomic_number, parent=None): QPushButton.__init__(self, parent) self._atomic_number = atomic_number self._symbol = get_symbol(atomic_number) self.setText(self._symbol) font = self.font() font.setWeight(QFont.Bold) self.setFont(font) self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding) self.setDefault(False) self.setAutoDefault(False)
def data(self, index, role): if not index.isValid() or \ not (0 <= index.row() < len(self.composition)): return None if role == Qt.TextAlignmentRole: return Qt.AlignCenter if role != Qt.DisplayRole: return None z, fraction = list(self.composition.items())[index.row()] column = index.column() if column == 0: if z is None: return 'none' else: return str(get_symbol(z)) elif column == 1: return str(fraction)
def testsymbol(self): self.assertEqual('H', get_symbol(1)) self.assertEqual('Uuo', get_symbol(118))
def setAtomicNumber(self, z): self.setText(get_symbol(z))
def get_symbol(self): """ Returns the symbol. """ return get_symbol(self.atomic_number)