framePj.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #from __future__ import unicode_literals
  2. # -*- coding: utf-8 -*-
  3. """Panneau d'affichage des PJ dans l'onglet groupe
  4. """
  5. import sys
  6. from PyQt4.QtCore import SIGNAL, Qt
  7. from PyQt4.QtGui import QFrame, QPushButton, QApplication
  8. from EcranEditionMateriel import EcranEditionMateriel
  9. from ui.ecran_panneauPj import Ui_pj_panneau
  10. class FramePj(QFrame):
  11. """Panneau d'affichage du Pj
  12. a inserer dans le layout de l'onglet groupe
  13. de l'ecran principal"""
  14. def __init__(self, idPj, parent=None):
  15. super (FramePj, self).__init__(parent)
  16. self.idPj = idPj
  17. self._pj = None
  18. self.enCreation = False
  19. self.createWidgets()
  20. def createWidgets(self):
  21. """construction de l'interface"""
  22. self.ui = Ui_pj_panneau()
  23. self.ui.setupUi(self)
  24. self.setEnabled(False)
  25. self.setMouseTracking(True)
  26. for i in range(0, 6):
  27. bouton = self.findChild(QPushButton, "pj_afficher_{}".format(i))
  28. self.connect(bouton, SIGNAL("clicked()"), self.afficherFiche)
  29. def signalerModif(self):
  30. """on signale a la fenetre principale que le personnage a ete modifie"""
  31. self.emit(SIGNAL("pjModifie(int)"), self.idPj)
  32. def pj(self):
  33. """retourne le pj represente"""
  34. return self._pj
  35. def chargerPj(self, pj = None):
  36. """met a jour le contenu avec les donnees du pj en param"""
  37. if pj != None:
  38. self.ui.pj_image.chargerImage(pj.logo)
  39. self.ui.pj_nom.majTexte(pj.nom())
  40. for i in range(0, 6):
  41. bouton = self.findChild(QPushButton, "pj_afficher_{}".format(i))
  42. bouton.setEnabled(True)
  43. self._pj = pj
  44. self.majApparence()
  45. def reinitialiser(self):
  46. self.ui.pj_image.majImage("")
  47. self.ui.pj_nom.majTexte("(Nouveau personnage...)")
  48. for i in range(0, 6):
  49. bouton = self.findChild(QPushButton, "pj_afficher_{}".format(i))
  50. bouton.setEnabled(False)
  51. def afficherFiche(self):
  52. """affiche la fiche de perso a la page demandee"""
  53. emetteur = self.sender().objectName()
  54. page = int(str(emetteur)[-1:])
  55. fen = EcranEditionMateriel(self._pj)
  56. fen.afficher(page)
  57. fen.exec_()
  58. self._pj = fen.mat()
  59. del fen
  60. self.ui.pj_image.chargerImage(self._pj.logo)
  61. self.ui.pj_nom.majTexte(self._pj.nom())
  62. self.majApparence()
  63. self.signalerModif()
  64. def majApparence(self):
  65. """affiche le fond de la couleur du pion, et epaissit la bordure au survol"""
  66. # "QFrame {background-color: " + self._pj.couleur.lighter(150).name() + ";" \
  67. # self.setStyleSheet("QFrame {background-color: rgb(249,249,249);" \
  68. # "border: 2px solid " + self._pj.couleur.lighter(110).name() + ";" \
  69. # "border-radius: 5px;}" \
  70. # "QLabel {border-width: 0px;}")
  71. couleur = self._pj.couleur
  72. while couleur.lightness() < 240:
  73. couleur = couleur.lighter(110)
  74. r, g, b, alpha = couleur.getRgb()
  75. rgb = "{}, {}, {}".format(r, g, b)
  76. self.setStyleSheet("QFrame {background-color: rgb("+rgb+");}")
  77. def enterEvent(self, event):
  78. self.setEnabled(True)
  79. def leaveEvent(self, event):
  80. self.setEnabled(False)
  81. if __name__ == "__main__":
  82. app = QApplication(sys.argv)
  83. ecran = FramePj(0)
  84. ecran.show()
  85. r = app.exec_()
  86. exit(r)