Пример #1
0
    def Draw(self, grid, dc, rect, col):
        # Couleur de fond
        if self.couleurFond != None:
            dc.SetBrush(wx.Brush(self.couleurFond))
            dc.SetPen(wx.TRANSPARENT_PEN)
            if 'phoenix' in wx.PlatformInfo:
                dc.DrawRectangle(rect)
            else:
                dc.DrawRectangleRect(rect)

        # Label
        dc.SetFont(
            wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,
                    wx.FONTWEIGHT_BOLD))
        hAlign, vAlign = grid.GetColLabelAlignment()
        texte = grid.GetColLabelValue(col)
        texte = wordwrap.wordwrap(texte, rect.width, dc)
        self.DrawBorder(grid, dc, rect)
        largTexte, hautTexte = dc.GetTextExtent(texte)
        x = rect.width / 2.0 - largTexte / 2.0 + rect.x
        dc.DrawText(texte, x, 2)

        # Graduations
        dc.SetPen(wx.Pen("black"))
        dc.SetTextForeground("black")
        dc.SetFont(wx.Font(7, wx.SWISS, wx.NORMAL, wx.NORMAL))

        h = datetime.timedelta(minutes=0)
        for x in range(0, 96):
            htime = UTILS_Dates.DeltaEnTime(h)
            if htime >= self.heure_min and htime <= self.heure_max:
                x = self.HeureEnPos(h,
                                    rect) + PADDING_MULTIHORAIRES["horizontal"]
                posY = rect.height - 17
                hautTraitHeures = 4
                if htime.minute == 0:
                    hauteurTrait = hautTraitHeures
                    texte = "%dh" % htime.hour
                    largTexte, hautTexte = dc.GetTextExtent(texte)
                    dc.DrawText(texte, x - (largTexte / 2) + rect.x, posY + 2)
                elif htime.minute in (15, 45):
                    hauteurTrait = 1
                elif htime.minute == 30:
                    hauteurTrait = 2.5
                dc.DrawLine(x + rect.x,
                            posY + hautTexte + hautTraitHeures - hauteurTrait,
                            x + rect.x, posY + hautTexte + hautTraitHeures)

            h += datetime.timedelta(minutes=15)
Пример #2
0
    def Draw(self, grid, attr, dc, rect, row, col, isSelected):
        # Préparation du buffer Image
        dcGrid = dc
        if 'phoenix' in wx.PlatformInfo:
            bmp = wx.Bitmap(rect.GetWidth(), rect.GetHeight())
        else:
            bmp = wx.EmptyBitmap(rect.GetWidth(), rect.GetHeight())
        image = wx.MemoryDC()
        image.SelectObject(bmp)
        gc = wx.GraphicsContext.Create(image)
        gc.PushState()

        rectCase = wx.Rect(0, 0, rect.GetWidth(), rect.GetHeight())
        x, y, largeur, hauteur = rectCase.x, rectCase.y, rectCase.width, rectCase.height

        # Dessin du fond
        if self.case.ouvert == True:
            self.couleurFond = wx.Colour(255, 255, 255)
        else:
            self.couleurFond = CTRL_Grille.COULEUR_FERME
        gc.SetBrush(wx.Brush(self.couleurFond, wx.SOLID))
        gc.SetPen(wx.TRANSPARENT_PEN)
        gc.DrawRectangle(x, y, largeur, hauteur)

        if self.case.ouvert == True:
            # Dessin de la bordure 3D pour faire effet Case grid
            self.DrawBorder(grid, gc, rectCase)

            # Dessin du remplissage
            dictInfosPlaces = self.case.GetInfosPlaces()
            if dictInfosPlaces != None:
                for IDunite_remplissage, valeurs in dictInfosPlaces.iteritems(
                ):

                    heure_min = UTILS_Dates.HeureStrEnTime(
                        grid.dictRemplissage[IDunite_remplissage]["heure_min"])
                    if heure_min < self.case.heure_min:
                        heure_min = self.case.heure_min
                    heure_max = UTILS_Dates.HeureStrEnTime(
                        grid.dictRemplissage[IDunite_remplissage]["heure_max"])
                    if heure_max > self.case.heure_max:
                        heure_max = self.case.heure_max

                    nbrePlacesRestantes = valeurs["nbrePlacesRestantes"]
                    nbrePlacesInitial = valeurs["nbrePlacesInitial"]
                    nbrePlacesPrises = valeurs["nbrePlacesPrises"]
                    seuil_alerte = valeurs["seuil_alerte"]
                    nbreAttente = valeurs["nbreAttente"]

                    couleur = None
                    if nbrePlacesRestantes > seuil_alerte:
                        couleur = CTRL_Grille.COULEUR_DISPONIBLE
                    if nbrePlacesRestantes > 0 and nbrePlacesRestantes <= seuil_alerte:
                        couleur = CTRL_Grille.COULEUR_ALERTE
                    if nbrePlacesRestantes <= 0:
                        couleur = CTRL_Grille.COULEUR_COMPLET

                    if nbrePlacesInitial > 0 and couleur != None:
                        gc.SetBrush(wx.Brush(couleur, wx.SOLID))
                        gc.SetPen(wx.TRANSPARENT_PEN)
                        posG = self.case.HeureEnPos(heure_min)
                        posD = self.case.HeureEnPos(heure_max) - posG
                        gc.DrawRectangle(
                            posG + PADDING_MULTIHORAIRES["horizontal"], 1,
                            posD, rectCase.height - 2)

            # Dessin des graduations
            gc.SetPen(wx.Pen((230, 230, 230), 1, wx.SOLID))
            # graduationStep = 25
            # listeGraduations = range(UTILS_Dates.HeuresEnDecimal(self.case.heure_min), UTILS_Dates.HeuresEnDecimal(self.case.heure_max)+graduationStep, graduationStep)
            # nbreGraduations = len(listeGraduations)
            # if nbreGraduations <= 1 :
            #     nbreGraduations = 2
            # step = 1.0 * (rect.width - PADDING_MULTIHORAIRES["horizontal"] * 2) / (nbreGraduations - 1)
            # if step > 3.0 :
            #     x = PADDING_MULTIHORAIRES["horizontal"]
            #     for temp in listeGraduations :
            #         gc.StrokeLine(x, 1, x, rect.height-2)
            #         x += step

            h = datetime.timedelta(minutes=0)
            for x in range(0, 96):
                htime = UTILS_Dates.DeltaEnTime(h)
                if htime >= self.case.heure_min and htime <= self.case.heure_max:
                    x = self.case.HeureEnPos(
                        h) + PADDING_MULTIHORAIRES["horizontal"]
                    gc.StrokeLine(x, 1, x, rect.height - 2)
                h += datetime.timedelta(minutes=15)

        # Dessin des barres
        for barre in self.case.listeBarres:
            conso = barre.conso

            # Calcul des coordonnées de la barre
            barre.UpdateRect()
            rectBarre = barre.GetRect("case")

            # get Couleur barre
            couleurBarre = self.GetCouleurBarre(conso)

            # Dessin du cadre
            if 'phoenix' in wx.PlatformInfo:
                gc.SetFont(attr.GetFont(), wx.Colour(0, 0, 0))
            else:
                gc.SetFont(attr.GetFont())
            gc.SetBrush(
                wx.Brush((couleurBarre.Red(), couleurBarre.Green(),
                          couleurBarre.Blue(), 180),
                         wx.SOLID))  # 128 = demi-transparence

            couleurTexte = UTILS_Couleurs.ModifierLuminosite(couleurBarre, -50)
            couleur = (couleurTexte[0], couleurTexte[1], couleurTexte[2], 255)
            if barre.readOnly == True:
                gc.SetPen(wx.TRANSPARENT_PEN)
            else:
                gc.SetPen(wx.Pen(couleur, 1,
                                 wx.SOLID))  # 128 = demi-transparence
            gc.DrawRoundedRectangle(rectBarre.x, rectBarre.y, rectBarre.width,
                                    rectBarre.height, 5)

            # Dessin des horaires
            heure_debut_x, heure_debut_y, heure_debut_largeur, heure_debut_hauteur = self.DrawTexte(
                gc,
                rectBarre,
                barre.heure_debut.strftime("%Hh%M"),
                couleur=couleurTexte,
                position="gauche")
            heure_fin_x, heure_fin_y, heure_fin_largeur, heure_fin_hauteur = self.DrawTexte(
                gc,
                rectBarre,
                barre.heure_fin.strftime("%Hh%M"),
                couleur=couleurTexte,
                position="droite")

            # Dessin du cadenas VERROUILLAGE
            if conso.verrouillage == 1:
                imageTemp = wx.Bitmap(
                    Chemins.GetStaticPath("Images/Special/Cadenas_ferme.png"),
                    wx.BITMAP_TYPE_ANY)
                largeurBmp, hauteurBmp = imageTemp.GetSize()
                gc.DrawBitmap(imageTemp, 2, rect.height - 10, largeurBmp,
                              hauteurBmp)

            # Dessin de l'image FORFAIT CREDIT
            if conso.etat in (
                    "reservation", "present", "absenti", "absentj"
            ) and conso.IDprestation in grid.dictForfaits.keys():
                couleurForfait = grid.dictForfaits[
                    conso.IDprestation]["couleur"]
                gc.SetBrush(wx.Brush(couleurForfait, wx.SOLID))
                gc.SetPen(wx.TRANSPARENT_PEN)
                path = gc.CreatePath()
                path.AddLineToPoint(8, 0)
                path.AddLineToPoint(1, 8)
                path.AddLineToPoint(1, 0)
                gc.DrawPath(path)

            # Dessin des images
            listeImages = []

            # Dessin de l'image PRESENT (Coche verte)
            if conso.etat == "present":
                listeImages.append(
                    wx.Bitmap(Chemins.GetStaticPath("Images/16x16/Ok5.png"),
                              wx.BITMAP_TYPE_ANY))

            # Dessin de l'image ABSENT JUSTIFIEE (Croix rouge)
            if conso.etat == "absentj":
                listeImages.append(
                    wx.Bitmap(
                        Chemins.GetStaticPath("Images/16x16/absentj.png"),
                        wx.BITMAP_TYPE_ANY))

            # Dessin de l'image ABSENT INJUSTIFIEE (Croix rouge)
            if conso.etat == "absenti":
                listeImages.append(
                    wx.Bitmap(
                        Chemins.GetStaticPath("Images/16x16/absenti.png"),
                        wx.BITMAP_TYPE_ANY))

            # Dessin de l'image SANS PRESTATION (Alerte)
            if conso.etat in (
                    "reservation", "present", "absenti", "absentj"
            ) and conso.IDprestation == None and grid.afficheSansPrestation == True:
                listeImages.append(
                    wx.Bitmap(
                        Chemins.GetStaticPath("Images/16x16/Gratuit.png"),
                        wx.BITMAP_TYPE_ANY))

            paddingImage = 3
            if heure_fin_x == 0:
                heure_fin_x = rectBarre.x + rectBarre.width
            xImage = heure_fin_x - paddingImage  # heure_debut_x + heure_debut_largeur + paddingImage
            if rectBarre.width > len(listeImages) * 19:
                for imageTemp in listeImages:
                    largeurBmp, hauteurBmp = imageTemp.GetSize()
                    gc.DrawBitmap(imageTemp, xImage - largeurBmp,
                                  rectBarre.y + 1, largeurBmp, hauteurBmp)
                    xImage -= largeurBmp + paddingImage

            # Ecrit le nom du groupe
            if CTRL_Grille.AFFICHE_NOM_GROUPE == True and rectBarre.height > 22:
                if conso.IDgroupe != None and conso.IDgroupe != 0 and conso.etat in (
                        "reservation", "present", "absenti", "absentj",
                        "attente", "refus"):
                    couleurTexteGroupe = UTILS_Couleurs.ModifierLuminosite(
                        couleurBarre, -30)
                    gc.SetFont(
                        wx.Font(6, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,
                                wx.FONTWEIGHT_NORMAL, False, 'Arial'),
                        couleurTexteGroupe)
                    nomGroupe = grid.dictGroupes[conso.IDgroupe]["nom"]
                    largeurNomGroupe, hauteurNomGroupe = gc.GetTextExtent(
                        nomGroupe)
                    nbreGroupesActivite = grid.dictGroupes[
                        conso.IDgroupe]["nbreGroupesActivite"]
                    if rectBarre.width > largeurNomGroupe and nbreGroupesActivite > 1:
                        gc.DrawText(nomGroupe, rectBarre.x + 4,
                                    rectBarre.y + rectBarre.height - 10)

            # Ecrit les étiquettes
            nbreEtiquettes = len(conso.etiquettes)
            if conso.etat != None and nbreEtiquettes > 0:
                index = 0
                for IDetiquette in conso.etiquettes:
                    if grid.dictEtiquettes.has_key(IDetiquette):
                        dictEtiquette = grid.dictEtiquettes[IDetiquette]
                        # Dessine l'étiquette
                        gc.SetBrush(
                            wx.Brush(dictEtiquette["couleur"], wx.SOLID))
                        gc.SetPen(wx.TRANSPARENT_PEN)
                        gc.DrawEllipse(rectBarre.x + rectBarre.width - 7 -
                                       (5 * index),
                                       rectBarre.y + rectBarre.height - 7, 4,
                                       4)  # En haut à droite
                        index += 1

        # Dessin du cadenas VERROUILLAGE
        if self.case.verrouillage == 1:
            gc.SetBrush(wx.Brush((100, 100, 100), wx.SOLID))
            gc.SetPen(wx.TRANSPARENT_PEN)
            gc.DrawRectangle(*rectCase)
            tailleImage = 8
            paddingImage = 3
            bmp = wx.Bitmap(
                Chemins.GetStaticPath("Images/Special/Cadenas_ferme.png"),
                wx.BITMAP_TYPE_ANY)
            largeurBmp, hauteurBmp = bmp.GetSize()
            gc.DrawBitmap(bmp, rectCase[0] + tailleImage - paddingImage,
                          rectCase[1] + paddingImage, largeurBmp, hauteurBmp)

        gc.PopState()

        # Envoi du buffer au DC
        dcGrid.Blit(rect.x, rect.y, rect.GetWidth(), rect.GetHeight(), image,
                    0, 0)