コード例 #1
0
ファイル: scoringdialog.py プロジェクト: KDE/kajongg
 def __fillLastTileComboWith(self, lastTiles, winnerTiles):
     """fill last meld combo with prepared content"""
     self.comboTilePairs = lastTiles
     idx = self.cbLastTile.currentIndex()
     if idx < 0:
         idx = 0
     indexedTile = variantValue(self.cbLastTile.itemData(idx))
     restoredIdx = None
     self.cbLastTile.clear()
     if not winnerTiles:
         return
     pmSize = winnerTiles[0].board.tileset.faceSize
     pmSize = QSize(pmSize.width() * 0.5, pmSize.height() * 0.5)
     self.cbLastTile.setIconSize(pmSize)
     QPixmapCache.clear()
     self.__tilePixMaps = []
     shownTiles = set()
     for tile in winnerTiles:
         if tile.tile in lastTiles and tile.tile not in shownTiles:
             shownTiles.add(tile.tile)
             self.cbLastTile.addItem(QIcon(tile.pixmapFromSvg(pmSize, withBorders=False)), "", toQVariant(tile.tile))
             if indexedTile is tile.tile:
                 restoredIdx = self.cbLastTile.count() - 1
     if not restoredIdx and indexedTile:
         # try again, maybe the tile changed between concealed and exposed
         indexedTile = indexedTile.exposed
         for idx in range(self.cbLastTile.count()):
             if indexedTile is variantValue(self.cbLastTile.itemData(idx)).exposed:
                 restoredIdx = idx
                 break
     if not restoredIdx:
         restoredIdx = 0
     self.cbLastTile.setCurrentIndex(restoredIdx)
     self.prevLastTile = self.computeLastTile()
コード例 #2
0
ファイル: background.py プロジェクト: zero804/kajongg
 def pixmap(self, size):
     """returns a background pixmap or None for isPlain"""
     self.__pmap = QBrush()
     if not self.isPlain:
         width = size.width()
         height = size.height()
         if self.tiled:
             width = self.imageWidth
             height = self.imageHeight
         cachekey = '{name}W{width}H{height}'.format(name=self.name,
                                                     width=width,
                                                     height=height)
         self.__pmap = QPixmapCache.find(cachekey)
         if not self.__pmap:
             renderer = QSvgRenderer(self.graphicsPath)
             if not renderer.isValid():
                 logException(
                     i18n(
                         'file <filename>%1</filename> contains no valid SVG',
                         self.graphicsPath))
             self.__pmap = QPixmap(width, height)
             self.__pmap.fill(Qt.transparent)
             painter = QPainter(self.__pmap)
             renderer.render(painter)
             QPixmapCache.insert(cachekey, self.__pmap)
     return self.__pmap
コード例 #3
0
ファイル: background.py プロジェクト: KDE/kajongg
    def __init__(self, desktopFileName=None):
        if desktopFileName is None:
            desktopFileName = 'default'
        self.__svg = None
        self.__pmap = None
        QPixmapCache.setCacheLimit(20480)  # the chinese landscape needs much
        self.defineCatalog()
        self.desktopFileName = desktopFileName
        self.path = locatebackground(desktopFileName + '.desktop')
        if self.path.isEmpty():
            self.path = locatebackground('default.desktop')
            if self.path.isEmpty():
                directories = '\n\n' + \
                    '\n'.join(str(x)
                              for x in KGlobal.dirs().resourceDirs("kmahjonggbackground"))
                logException(BackgroundException(m18n(
                    'cannot find any background in the following directories, is libkmahjongg installed?')
                                                 + directories))
            else:
                logWarning(
                    m18n(
                        'cannot find background %1, using default',
                        desktopFileName))
                self.desktopFileName = 'default'
        config = KConfig(self.path)
        group = config.group("KMahjonggBackground")
        self.name = group.readEntry("Name") or m18n("unknown background")

        # Version control
        backgroundversion = int(group.readEntry("VersionFormat")) or 0
        # Format is increased when we have incompatible changes, meaning that
        # older clients are not able to use the remaining information safely
        if backgroundversion > BACKGROUNDVERSIONFORMAT:
            logException(BackgroundException('backgroundversion file / program: %d/%d' %
                                             (backgroundversion, BACKGROUNDVERSIONFORMAT)))

        self.tiled = group.readEntry('Tiled') == '1'
        if self.tiled:
            self.imageWidth, entryOk = group.readEntry('Width').toInt()
            if not entryOk:
                raise Exception('cannot scan Width from background file')
            self.imageHeight, entryOk = group.readEntry('Height').toInt()
            if not entryOk:
                raise Exception('cannot scan Height from background file')
        self.isPlain = bool(group.readEntry('Plain'))
        if not self.isPlain:
            graphName = QString(group.readEntry("FileName"))
            self.__graphicspath = locatebackground(graphName)
            if self.__graphicspath.isEmpty():
                logException(BackgroundException(
                    'cannot find kmahjongglib/backgrounds/%s for %s' %
                    (graphName, self.desktopFileName)))
コード例 #4
0
ファイル: background.py プロジェクト: KDE/kajongg
 def pixmap(self, size):
     """returns a background pixmap or None for isPlain"""
     self.__pmap = None
     if not self.isPlain:
         width = size.width()
         height = size.height()
         if self.tiled:
             width = self.imageWidth
             height = self.imageHeight
         cachekey = QString(u'{name}W{width}H{height}'.format(
             name=self.name, width=width, height=height))
         self.__pmap = QPixmapCache.find(cachekey)
         if not self.__pmap:
             renderer = QSvgRenderer(self.__graphicspath)
             if not renderer.isValid():
                 logException(BackgroundException(
                     m18n('file <filename>%1</filename> contains no valid SVG', self.__graphicspath)))
             self.__pmap = QPixmap(width, height)
             self.__pmap.fill(Qt.transparent)
             painter = QPainter(self.__pmap)
             renderer.render(painter)
             QPixmapCache.insert(cachekey, self.__pmap)
     return self.__pmap
コード例 #5
0
ファイル: background.py プロジェクト: zero804/kajongg
    def __init__(self, name):
        """continue __build"""
        super(Background, self).__init__(name)
        self.__svg = None
        self.__pmap = None
        self.graphicsPath = None
        QPixmapCache.setCacheLimit(20480)  # the chinese landscape needs much

        self.tiled = self.group.readEntry('Tiled') == '1'
        if self.tiled:
            try:
                self.imageWidth = self.group.readInteger('Width')
                self.imageHeight = self.group.readInteger('Height')
            except Exception as exc:
                logException(
                    exc)  # TODO: simplify if we switch to twisted logger
                raise
        self.isPlain = bool(self.group.readEntry('Plain'))
        if not self.isPlain:
            graphName = self.group.readEntry("FileName")
            self.graphicsPath = self.locate(graphName)
            if not self.graphicsPath:
                logException('cannot find kmahjongglib/backgrounds/%s for %s' %
                             (graphName, self.desktopFileName))
コード例 #6
0
ファイル: scoringdialog.py プロジェクト: zero804/kajongg
 def __fillLastTileComboWith(self, lastTiles, winnerTiles):
     """fill last meld combo with prepared content"""
     self.comboTilePairs = lastTiles
     idx = self.cbLastTile.currentIndex()
     if idx < 0:
         idx = 0
     indexedTile = self.cbLastTile.itemData(idx)
     restoredIdx = None
     self.cbLastTile.clear()
     if not winnerTiles:
         return
     pmSize = winnerTiles[0].board.tileset.faceSize
     pmSize = QSize(pmSize.width() * 0.5, pmSize.height() * 0.5)
     self.cbLastTile.setIconSize(pmSize)
     QPixmapCache.clear()
     self.__tilePixMaps = []
     shownTiles = set()
     for tile in winnerTiles:
         if tile.tile in lastTiles and tile.tile not in shownTiles:
             shownTiles.add(tile.tile)
             self.cbLastTile.addItem(
                 QIcon(tile.pixmapFromSvg(pmSize, withBorders=False)), '',
                 tile.tile)
             if indexedTile is tile.tile:
                 restoredIdx = self.cbLastTile.count() - 1
     if not restoredIdx and indexedTile:
         # try again, maybe the tile changed between concealed and exposed
         indexedTile = indexedTile.exposed
         for idx in range(self.cbLastTile.count()):
             if indexedTile is self.cbLastTile.itemData(idx).exposed:
                 restoredIdx = idx
                 break
     if not restoredIdx:
         restoredIdx = 0
     self.cbLastTile.setCurrentIndex(restoredIdx)
     self.prevLastTile = self.computeLastTile()