class ExplainView(QListView): """show a list explaining all score computations""" def __init__(self, game, parent=None): QListView.__init__(self, parent) self.game = None self.setWindowTitle(m18n('Explain Scores').replace('&', '') + ' - Kajongg') self.setGeometry(0, 0, 300, 400) self.model = QStringListModel() self.setModel(self.model) StateSaver(self) self.refresh(game) def refresh(self, game): """refresh for new values""" self.game = game lines = [] if self.game is None: lines.append(m18n('There is no active game')) else: i18nName = m18n(self.game.ruleset.name) lines.append(m18n('Ruleset: %1', i18nName)) lines.append('') for player in self.game.players: pLines = [] if player.hand and player.hand.tileNames: total = player.hand.total() if total: pLines = ['%s: %s' % (player.localName, total)] for line in player.hand.explain(): pLines.append('- ' + line) elif player.handTotal: pLines.append(m18n('Manual score for %1: %2 points', player.localName, player.handTotal)) if pLines: pLines.append('') lines.extend(pLines) if 'xxx'.join(lines) != 'xxx'.join(unicode(x) for x in self.model.stringList()): # QStringListModel does not optimize identical lists away, so we do self.model.setStringList(lines)