def __init__(self, desktopFileName=None): if desktopFileName is None: desktopFileName = 'default' self.tileSize = None self.faceSize = None self.__renderer = None self.__shadowOffsets = None self.defineCatalog() self.path = locateTileset(desktopFileName + '.desktop') if self.path.isEmpty(): self.path = locateTileset('default.desktop') if self.path.isEmpty(): directories = '\n\n' +'\n'.join(str(x) for x in KGlobal.dirs().resourceDirs("kmahjonggtileset")) logException(TileException(m18n( \ 'cannot find any tileset in the following directories, is libkmahjongg installed?') + directories)) else: logWarning(m18n('cannot find tileset %1, using default', desktopFileName)) self.desktopFileName = 'default' else: self.desktopFileName = desktopFileName self.darkenerAlpha = 120 if self.desktopFileName == 'jade' else 50 tileconfig = KConfig(self.path, KConfig.SimpleConfig) group = KConfigGroup(tileconfig.group("KMahjonggTileset")) self.name = group.readEntry("Name", "unknown tileset").toString() # Returns translated data self.author = group.readEntry("Author", "unknown author").toString() self.description = group.readEntry("Description", "no description available").toString() self.authorEmail = group.readEntry("AuthorEmail", "no E-Mail address available").toString() #Version control tileversion, entryOK = group.readEntry("VersionFormat", QVariant(0)).toInt() #Format is increased when we have incompatible changes, meaning that # older clients are not able to use the remaining information safely if not entryOK or tileversion > TILESETVERSIONFORMAT: logException(TileException('tileversion file / program: %d/%d' % \ (tileversion, TILESETVERSIONFORMAT))) graphName = QString(group.readEntry("FileName")) self.__graphicspath = locateTileset(graphName) if self.__graphicspath.isEmpty(): logException(TileException('cannot find kmahjongglib/tilesets/%s for %s' % \ (graphName, self.desktopFileName ))) self.renderer() # now that we get the sizes from the svg, we need the renderer right away self.svgName = { 'wn': 'WIND_1', 'ws': 'WIND_2', 'we': 'WIND_3', 'ww': 'WIND_4', 'db': 'DRAGON_1', 'dg': 'DRAGON_2', 'dr': 'DRAGON_3'} for value in '123456789': self.svgName['s%s' % value] = 'ROD_%s' % value self.svgName['b%s' % value] = 'BAMBOO_%s' % value self.svgName['c%s' % value] = 'CHARACTER_%s' % value for idx, wind in enumerate('eswn'): self.svgName['f%s' % wind] = 'FLOWER_%d' % (idx + 1) self.svgName['y%s' % wind] = 'SEASON_%d' % (idx + 1)
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)))
def backgroundRowChanged(self): """user selected a new background, update our information about it and paint preview""" selBackground = self.backgroundList[ self.backgroundNameList.currentRow()] self.kcfg_backgroundName.setText(selBackground.desktopFileName) config = KConfig(selBackground.path) group = config.group("KMahjonggBackground") author = group.readEntry("Author") or m18n("unknown author") description = group.readEntry("Description") or "" authorEmail = group.readEntry( "AuthorEmail") or m18n( "no E-Mail address available") self.backgroundAuthor.setText(author) self.backgroundContact.setText(authorEmail) self.backgroundDescription.setText(description) selBackground.setPalette(self.backgroundPreview) self.backgroundPreview.setAutoFillBackground(True)
def __init__(self, desktopFileName=None): if desktopFileName is None: desktopFileName = 'default' self.tileSize = None self.faceSize = None self.__renderer = None self.__shadowOffsets = None self.defineCatalog() self.path = locateTileset(desktopFileName + '.desktop') if self.path.isEmpty(): self.path = locateTileset('default.desktop') if self.path.isEmpty(): self.__noTilesetFound() else: logWarning( m18n( 'cannot find tileset %1, using default', desktopFileName)) self.desktopFileName = 'default' else: self.desktopFileName = desktopFileName self.darkenerAlpha = 120 if self.desktopFileName == 'jade' else 50 tileconfig = KConfig(self.path, KConfig.SimpleConfig) group = tileconfig.group("KMahjonggTileset") self.name = group.readEntry("Name") or m18n("unknown tileset") self.author = group.readEntry("Author") or m18n("unknown author") self.description = group.readEntry( "Description") or m18n( "no description available") self.authorEmail = group.readEntry( "AuthorEmail") or m18n( "no E-Mail address available") # Version control tileversion = 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 tileversion > TILESETVERSIONFORMAT: logException(TileException('tileversion file / program: %d/%d' % (tileversion, TILESETVERSIONFORMAT))) graphName = group.readEntry("FileName") self.__graphicspath = locateTileset(graphName) if self.__graphicspath.isEmpty(): logException( TileException('cannot find kmahjongglib/tilesets/%s for %s' % (graphName, self.desktopFileName))) self.renderer() # now that we get the sizes from the svg, we need the # renderer right away self.svgName = { 'wn': North.svgName, 'ws': South.svgName, 'we': East.svgName, 'ww': West.svgName, 'db': 'DRAGON_1', 'dg': 'DRAGON_2', 'dr': 'DRAGON_3'} for value in '123456789': self.svgName['s%s' % value] = 'ROD_%s' % value self.svgName['b%s' % value] = 'BAMBOO_%s' % value self.svgName['c%s' % value] = 'CHARACTER_%s' % value for idx, wind in enumerate('eswn'): self.svgName['f%s' % wind] = 'FLOWER_%d' % (idx + 1) self.svgName['y%s' % wind] = 'SEASON_%d' % (idx + 1)
def konfigGroup(path, groupName): """returns access to a group of config options""" config = KConfig(path, KConfig.SimpleConfig) return config, KConfigGroup(config.group(groupName))