def set_state(self, state): """ Set the state of the square. Values must correspond to a value from `Minesweeper.state`. Numbers should be encoded as strings, so that state can be passed on to Qt's C++ backend as a QString. """ if state == 'None': self._pixmap = QPixmapCache.find_or_get(':closed.png') elif state == '?': self._pixmap = QPixmapCache.find_or_get(':question_mark.png') else: self._pixmap = QPixmapCache.find_or_get(':{}.png'.format(state)) if self._pixmap.isNull(): raise ValueError( 'The given state ({}) does not exist.'.format(state))
def set_value(self, value): """ Set the value of the display. The display can show any positive value up to 999. Does not work with negative values. """ value = int(max(min(value, 999), 0)) digits = [value // 100, (value % 100) // 10, value % 10] for digit, label in zip(digits, self.labels): label.setPixmap( QPixmapCache.find_or_get(':ssd{}.png'.format(digit))) label.update() self.update( ) # A lot of updates and more so Qt updates the damn Pixmap. QCoreApplication.processEvents()