| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #from __future__ import unicode_literals
- # -*- coding: utf-8 -*-
- """controle l'acces aux ressources variables (sons, images, sauvegardes)"""
- import os
- from PyQt4.QtGui import QPixmap
- #le repertoire de l'application
- ppal = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir))
- def repApp():
- return ppal
- def repRessources():
- return ["ressources\\commun", \
- "ressources\\dd35", \
- "parties\\Partie1\\ressources"]
- class Ressource(object):
- """classe de base des ressources utilisees"""
- def __init__(self, cheminR):
- self._cheminR = cheminR
- def chemin(self):
- """renvoie le chemin absolu vers le fichier"""
- return os.path.join(repApp(), self._cheminR)
- def nom(self):
- #on vire l'extension
- nom = ""
- for car in reversed(self._cheminR):
- if car in ["\\", "/"]:
- break
- else:
- nom = car + nom
- nom = os.path.splitext(nom)[0]
- return nom
- def repR(self):
- """renvoie le repertoire, presente de maniere relative"""
- return os.path.dirname(self._cheminR)
-
- def extension(self):
- return os.path.splitext(self._cheminR)[1]
- def definition(self):
- return self._cheminR
-
- def existe(self):
- return os.path.isfile(self.chemin())
- def estValide(self):
- return self.existe()
- class Image(Ressource):
- """classe de base des ressources utilisees"""
- def __init__(self, cheminR):
- super(Image, self).__init__(cheminR)
- def pix(self, l = 0, h = 0):
- pix = QPixmap(self.chemin())
- if not pix.isNull():
- if l > 0 and h > 0:
- pix.scaled(l, h)
- elif l > 0 and h == 0:
- pix.scaledToWidth(l)
- elif l == 0 and h > 0:
- pix.scaledToHeigth(l)
- return pix
- def estValide(self):
- return self.existe() and \
- self.extension() in [".png", ".jpg", ".gif"]
- r = Image("ressources\\commun\\orc.png")
- print r.repR()
|