Exemplo n.º 1
0
def genererFicheValidation(nomFichier, projet):
    """
    """

    #
    # Styles
    #
    title_style = ParagraphStyle(
        name="TitleStyle",
        fontName="Helvetica",
        textColor=colors.red,
        fontSize=20,
        alignment=TA_LEFT,
    )

    normal_style = ParagraphStyle(
        name="NormalStyle",
        fontName="Helvetica",
        fontSize=10,
        leading=12,
        alignment=TA_LEFT,
    )

    entete_style = ParagraphStyle(
        name="EnteteStyle",
        fontName="Helvetica",
        textColor=colors.gray,
        fontSize=9,
        alignment=TA_LEFT,
    )

    # To make a SimpleDocTemplate, just supply a file name for your PDF, and the
    # page margins. You can optionally supply non-flowing elements such as headers
    # and footers. I will introduce that feature in a later demonstration.
    doc = SimpleDocTemplate(nomFichier,
                            pagesize=A4,
                            leftMargin=10 * mm,
                            rightMargin=10 * mm,
                            topMargin=10 * mm,
                            bottomMargin=10 * mm)

    story = []  # Fill this list with flowable objects

    ref = projet.GetReferentiel()
    prj = projet.GetProjetRef()
    #
    # En-tête
    #
    story.append(Paragraph(u"Fiche de validation du projet", title_style))
    story.append(Spacer(1, 5 * mm))

    if projet.GetTypeEnseignement() == 'SSI':
        en_tete = [
            u"Bulletin officiel n°39 du 23 octobre 2014",
            u"Annexe 4 à la note de service n° 2014-131 du 9-10-2014",
            u"Baccalauréat général, série S, sciences de l'ingénieur - Épreuve orale, projet interdisciplinaire"
        ]

    elif ref.Famille == 'STI':
        en_tete = [
            u"Bulletin officiel n°39 du 23 octobre 2014",
            u"Annexe 9 à la note de service n° 2014-132 du 13-10-2014",
            u"Baccalauréat technologique, série STI2D - Épreuve de projet en enseignement spécifique à la spécialité"
        ]

    for l in en_tete:
        story.append(Paragraph(l, entete_style))
        story.append(Spacer(1, 1 * mm))

    story.append(Spacer(1, 4 * mm))

    #
    # Première zone
    #
    NP = []
    for p in projet.equipe:
        np = p.GetNomPrenom()
        if p.referent:
            np = gras(np)
        if p.discipline != 'Tec':
            np = italic(np)
        NP.append(Paragraph(np, normal_style))

    data = [[[
        Paragraph(gras(u'Établissement : '), normal_style),
        Paragraph(projet.classe.etablissement, normal_style)
    ],
             [
                 Paragraph(
                     gras(u"Année scolaire : ") + getAnneeScolaireStr(),
                     normal_style),
                 Paragraph(
                     gras(u"Nombre d’élèves concernés : ") +
                     str(len(projet.eleves)), normal_style)
             ]],
            [
                Paragraph(
                    gras(u"Spécialité : ") + ref.Enseignement[0],
                    normal_style),
                Paragraph(
                    gras(u"Nombre de groupes d’élèves : ") +
                    str(projet.nbrParties), normal_style)
            ],
            [
                Paragraph(
                    gras(u"Noms et prénoms des enseignants responsables :"),
                    normal_style), NP
            ]]
    t = Table(data, style=[('VALIGN', (0, 0), (-1, -1), 'TOP')])

    story.append(t)

    story.append(Spacer(1, 5 * mm))

    styleSheet = getSampleStyleSheet()

    #
    # Deuxième zone (tableau)
    #
    #    print ref.attributs_prj
    # Colonne de gauche
    ppi = Paragraph(gras(u'Intitulé du projet'), normal_style)

    ppo = Paragraph(gras(u'Origine de la proposition'), normal_style)

    ppb = [
        Paragraph(gras(u'Problématique - Énoncé général du besoin'),
                  normal_style)
    ]
    ppb.append(splitParagraph(prj.attributs['PB'][1], entete_style))

    pco = [Paragraph(gras(u'Contraintes imposées au projet'), normal_style)]
    pco.append(splitParagraph(prj.attributs['CCF'][1], entete_style))

    ppig = Paragraph(
        gras(u'Intitulé des parties du projet confiées à chaque groupe'),
        normal_style)

    ppbg = Paragraph(
        gras(
            u'Énoncé du besoin pour la partie du projet confiée à chaque groupe'
        ), normal_style)

    ppr = [Paragraph(gras(u'Production finale attendue'), normal_style)]
    ppr.append(splitParagraph(prj.attributs['OBJ'][1], entete_style))

    # Colonne de droite
    contenu = [
        projet.intitule, projet.origine, projet.problematique,
        projet.contraintes, projet.intituleParties, projet.besoinParties,
        projet.production
    ]
    p = []
    tot = 0
    for c in contenu:
        t = ellipsizer(c, LONG_MAX_FICHE_VALID)
        tot += len(t)
        normal_style.fontSize = max(8, 11 - int(len(t) / 250))
        normal_style.leading = normal_style.fontSize * 1.2
        p.append(splitParagraph(t, normal_style))
        normal_style.fontSize = 10
        normal_style.leading = 12

    larg = max(50, min(150, 190 * tot / 800)) * mm

    data = [[ppi, p[0]], [ppo, p[1]], [ppb, p[2]], [pco, p[3]], [ppig, p[4]],
            [ppbg, p[5]], [ppr, p[6]]]

    t = Table(data,
              style=[('GRID', (0, 0), (-1, -1), 1, colors.black),
                     ('VALIGN', (0, 0), (-1, -1), 'TOP')],
              colWidths=[None, larg])

    story.append(t)

    #
    # Zone des signatures
    #
    story.append(Spacer(1, 5 * mm))
    V1 = [
        Paragraph(u"Visa du chef d’établissement", normal_style),
        Paragraph(u"(Nom, prénom, date et signature)", entete_style)
    ]
    V2 = [
        Paragraph(u"Visa du ou des IA-IPR", normal_style),
        Paragraph(u"(Noms, prénoms, qualités, dates et signatures)",
                  entete_style)
    ]
    data = [[V1, V2]]
    t = Table(data, style=[('VALIGN', (0, 0), (-1, -1), 'TOP')])
    story.append(t)

    try:
        doc.build(story)
    except doctemplate.LayoutError, err:
        print "Paragraphe trop grand"
        #        print err.message
        #        print type(err)
        #        print dir(err)
        return False
Exemplo n.º 2
0
def genererFicheValidation(nomFichier, projet):
    """
    """
    
    #
    # Styles
    #
    title_style = ParagraphStyle(name="TitleStyle",
                                 fontName="Helvetica",
                                 textColor = colors.red,
                                 fontSize=20,
                                 alignment=TA_LEFT,
                                 )
    
    normal_style = ParagraphStyle(name="NormalStyle",
                                 fontName="Helvetica",
                                 fontSize=10,
                                 leading = 12,
                                 alignment=TA_LEFT,
                                 )
    

    
    entete_style = ParagraphStyle(name="EnteteStyle",
                                 fontName="Helvetica",
                                 textColor = colors.gray,
                                 fontSize=9,
                                 alignment=TA_LEFT,
                                 )
    
    
    # To make a SimpleDocTemplate, just supply a file name for your PDF, and the
    # page margins. You can optionally supply non-flowing elements such as headers
    # and footers. I will introduce that feature in a later demonstration.
    doc = SimpleDocTemplate(nomFichier,
                            pagesize=A4,
                            leftMargin=10*mm,
                            rightMargin=10*mm,
                            topMargin=10*mm,
                            bottomMargin=10*mm)
    
    story = [] # Fill this list with flowable objects
    
    ref = projet.GetReferentiel()
    prj = projet.GetProjetRef()
    #
    # En-tête
    #
    story.append(Paragraph(u"Fiche de validation du projet",
                           title_style
                           ))
    story.append(Spacer(1, 5*mm))
    
    if projet.GetTypeEnseignement() == 'SSI':
        en_tete = [u"Bulletin officiel n°39 du 23 octobre 2014",
                   u"Annexe 4 à la note de service n° 2014-131 du 9-10-2014",
                   u"Baccalauréat général, série S, sciences de l'ingénieur - Épreuve orale, projet interdisciplinaire"]
        
    elif ref.Famille == 'STI':
        en_tete = [u"Bulletin officiel n°39 du 23 octobre 2014",
                   u"Annexe 9 à la note de service n° 2014-132 du 13-10-2014",
                   u"Baccalauréat technologique, série STI2D - Épreuve de projet en enseignement spécifique à la spécialité"]
        
    for l in en_tete:
        story.append(Paragraph(l, entete_style))
        story.append(Spacer(1, 1*mm))
    
    story.append(Spacer(1, 4*mm))
    
    
    #
    # Première zone
    #
    NP = []
    for p in projet.equipe:
        np = p.GetNomPrenom()
        if p.referent:
            np = gras(np)  
        if p.discipline != 'Tec':
            np = italic(np)
        NP.append(Paragraph(np, normal_style))
        
    data= [[[Paragraph(gras(u'Établissement : '), normal_style), Paragraph(projet.classe.etablissement, normal_style)], [Paragraph(gras(u"Année scolaire : ")+getAnneeScolaireStr(), normal_style),
                                                                                                                         Paragraph(gras(u"Nombre d’élèves concernés : ")+str(len(projet.eleves)), normal_style)]],
           [Paragraph(gras(u"Spécialité : ")+ ref.Enseignement[0], normal_style), Paragraph(gras(u"Nombre de groupes d’élèves : ")+str(projet.nbrParties), normal_style)],
           [Paragraph(gras(u"Noms et prénoms des enseignants responsables :"), normal_style), NP]]
    t = Table(data, style = [('VALIGN',      (0,0),(-1,-1),'TOP')])
    
    story.append(t)
    
    story.append(Spacer(1, 5*mm))
    
    styleSheet = getSampleStyleSheet()


    #
    # Deuxième zone (tableau)
    #
#    print ref.attributs_prj
    # Colonne de gauche
    ppi = Paragraph(gras(u'Intitulé du projet'),normal_style)
    
    ppo = Paragraph(gras(u'Origine de la proposition'),normal_style)
    
    ppb = [Paragraph(gras(u'Problématique - Énoncé général du besoin'),normal_style)]
    ppb.append(splitParagraph(prj.attributs['PB'][1], entete_style))

    pco = [Paragraph(gras(u'Contraintes imposées au projet'),normal_style)]
    pco.append(splitParagraph(prj.attributs['CCF'][1], entete_style))

    ppig = Paragraph(gras(u'Intitulé des parties du projet confiées à chaque groupe'),normal_style)
    
    ppbg = Paragraph(gras(u'Énoncé du besoin pour la partie du projet confiée à chaque groupe'),normal_style)
    
    ppr = [Paragraph(gras(u'Production finale attendue'),normal_style)]
    ppr.append(splitParagraph(prj.attributs['OBJ'][1], entete_style))
    
    
    # Colonne de droite
    contenu = [projet.intitule,
               projet.origine,
               projet.problematique,
               projet.contraintes,
               projet.intituleParties,
               projet.besoinParties,
               projet.production]
    p = []
    tot = 0
    for c in contenu:
        t = ellipsizer(c, LONG_MAX_FICHE_VALID)
        tot += len(t)
        normal_style.fontSize = max(8, 11 - int(len(t)/250))
        normal_style.leading = normal_style.fontSize * 1.2
        p.append(splitParagraph(t, normal_style))
        normal_style.fontSize = 10
        normal_style.leading = 12
    
    larg = max(50, min(150, 190*tot/800))*mm
    
    data= [[ppi, p[0]],
           [ppo, p[1]],
           [ppb, p[2]],
           [pco, p[3]],
           [ppig, p[4]],
           [ppbg, p[5]],
           [ppr, p[6]]]
           
    t=Table(data, style=[('GRID',        (0,0),(-1,-1),  1,colors.black),
                         ('VALIGN',      (0,0),(-1,-1), 'TOP')],
            colWidths = [None, larg])

    story.append(t)
    
    
    #
    # Zone des signatures
    #
    story.append(Spacer(1, 5*mm))
    V1 = [Paragraph(u"Visa du chef d’établissement", normal_style),
          Paragraph(u"(Nom, prénom, date et signature)", entete_style)]
    V2 = [Paragraph(u"Visa du ou des IA-IPR", normal_style),
          Paragraph(u"(Noms, prénoms, qualités, dates et signatures)", entete_style)]
    data= [[V1, V2]]
    t=Table(data,style=[('VALIGN',      (0,0),(-1,-1),'TOP')])
    story.append(t)
    
    try:
        doc.build(story)
    except doctemplate.LayoutError, err:
        print "Paragraphe trop grand"
#        print err.message
#        print type(err)
#        print dir(err)
        return False
Exemplo n.º 3
0
def Draw(ctx, prj, mouchard=False, pourDossierValidation=False, entete=False):
    """ Dessine une fiche de séquence de la séquence <prj>
        dans un contexte cairo <ctx>
    """

    #        print "Draw séquence"
    #    InitCurseur()

    #    tps = time.time()
    #
    # Options générales
    #
    options = ctx.get_font_options()
    options.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
    options.set_hint_style(cairo.HINT_STYLE_NONE)  #cairo.HINT_STYLE_FULL)#
    options.set_hint_metrics(cairo.HINT_METRICS_OFF)  #cairo.HINT_METRICS_ON)#
    ctx.set_font_options(options)

    DefinirZones(prj, ctx)

    #
    #    pour stocker des zones caractéristiques (à cliquer, ...)
    #
    prj.zones_sens = []
    prj.pt_caract = []

    #
    # Type d'enseignement
    #
    tailleTypeEns = taillePro[0] / 2
    t = prj.classe.referentiel.Enseignement[0]
    ctx.select_font_face(font_family, cairo.FONT_SLANT_NORMAL,
                         cairo.FONT_WEIGHT_BOLD)
    ctx.set_source_rgb(0.6, 0.6, 0.9)

    h = taillePos[1] * 0.8
    show_text_rect(ctx,
                   t, (posPro[0], posPos[1], tailleTypeEns, h),
                   va='c',
                   ha='g',
                   b=0,
                   orient='h',
                   fontsizeMinMax=(-1, -1),
                   fontsizePref=-1,
                   wrap=True,
                   couper=False,
                   coulBord=(0, 0, 0))

    t = prj.classe.referentiel.Enseignement[1]
    ctx.set_source_rgb(0.3, 0.3, 0.8)
    show_text_rect(ctx,
                   t,
                   (posPro[0], posPos[1] + h, tailleTypeEns, taillePos[1] - h),
                   va='c',
                   ha='g',
                   b=0,
                   orient='h',
                   fontsizeMinMax=(-1, -1),
                   fontsizePref=-1,
                   wrap=True,
                   couper=False)

    #
    # Position dans l'année
    #
    #    posPos[0] = posEqu[0] + tailleEqu[0] + ecartX + tailleTypeEns
    posPos[0] = posNom[0] + tailleNom[0] + ecartX + tailleTypeEns
    #    taillePos[0] =  0.72414 - posPos[0] - margeX
    taillePos[0] = taillePro[0] / 2
    ctx.set_line_width(0.0015 * COEF)
    r = (posPos[0], posPos[1], taillePos[0], taillePos[1])
    rects = DrawPeriodes(
        ctx,
        r,
        prj.position,
        prj.classe.referentiel.periodes,
        #                               [p.periode for p in prj.classe.referentiel.projets.values()],
        prj.classe.referentiel.projets,
        tailleTypeEns=tailleTypeEns)

    for i, re in enumerate(rects):
        prj.zones_sens.append(Zone([re], param="POS" + str(i)))
    prj.zones_sens.append(Zone([r], param="POS"))

    #
    # Etablissement
    #
    if prj.classe.etablissement != u"":
        t = prj.classe.etablissement + u" (" + prj.classe.ville + u")"
        ctx.select_font_face(font_family, cairo.FONT_SLANT_NORMAL,
                             cairo.FONT_WEIGHT_NORMAL)
        show_text_rect(ctx,
                       t, (posPos[0], posPos[1] + taillePos[1], taillePos[0],
                           posPro[1] - posPos[1] - taillePos[1]),
                       va='c',
                       ha='g',
                       b=0.2,
                       orient='h',
                       fontsizeMinMax=(-1, -1),
                       fontsizePref=-1,
                       wrap=True,
                       couper=False,
                       coulBord=(0, 0, 0))

    #
    # Image
    #
#    prj.support.rect = []
    prj.support.pts_caract = []
    bmp = prj.support.image
    if bmp != None:
        ctx.save()
        tfname = tempfile.mktemp()
        try:
            bmp.SaveFile(tfname, wx.BITMAP_TYPE_PNG)
            image = cairo.ImageSurface.create_from_png(tfname)
        finally:
            if os.path.exists(tfname):
                os.remove(tfname)

        w = image.get_width() * 1.1
        h = image.get_height() * 1.1

        s = min(tailleImg[0] / w, tailleImg[1] / h)
        ctx.translate(posImg[0], posImg[1])
        ctx.scale(s, s)
        ctx.set_source_surface(image, 0, 0)
        ctx.paint()
        ctx.restore()

        prj.zones_sens.append(Zone([posImg + tailleImg], obj=prj.support))
        prj.support.pts_caract.append(posImg)

    #
    #  Equipe
    #
    rectEqu = posEqu + tailleEqu
    prj.pt_caract.append(
        curve_rect_titre(ctx, u"Equipe pédagogique", rectEqu, BcoulEqu,
                         IcoulEqu, fontEqu))

    lstTexte = []
    g = None
    c = []
    for i, p in enumerate(prj.equipe):
        lstTexte.append(p.GetNomPrenom(disc=constantes.AFFICHER_DISC_FICHE))
        if p.referent:
            g = i
        c.append(constantes.COUL_DISCIPLINES[p.discipline])
    lstCodes = [u" \u25CF"] * len(lstTexte)

    if len(lstTexte) > 0:
        r = liste_code_texte(ctx,
                             lstCodes,
                             lstTexte,
                             posEqu[0],
                             posEqu[1],
                             tailleEqu[0],
                             tailleEqu[1] + 0.0001 * COEF,
                             0.1 * tailleEqu[1] + 0.0001 * COEF,
                             0.1,
                             gras=g,
                             lstCoul=c,
                             va='c')

    for i, p in enumerate(prj.equipe):
        prj.zones_sens.append(Zone([r[i]], obj=p))
    prj.zones_sens.append(Zone([rectEqu], param="EQU"))

    #
    #  Problématique
    #
    prj.pt_caract.append(posPro)
    rectPro = posPro + taillePro
    prj.pt_caract.append(
        curve_rect_titre(ctx, u"Problématique", rectPro, BcoulPro, IcoulPro,
                         fontPro))
    ctx.select_font_face(font_family, cairo.FONT_SLANT_NORMAL,
                         cairo.FONT_WEIGHT_NORMAL)
    show_text_rect(ctx,
                   constantes.ellipsizer(prj.problematique,
                                         constantes.LONG_MAX_PROBLEMATIQUE),
                   rectPro,
                   ha='g',
                   b=0.5,
                   fontsizeMinMax=(-1, 0.016 * COEF))
    prj.zones_sens.append(Zone([rectPro], param="PB"))

    #    print "     6 ", time.time() - tps

    #
    #  Projet
    #
    prj.pt_caract = []
    prj.pts_caract = []
    rectNom = posNom + tailleNom
    prj.pts_caract.append(
        curve_rect_titre(ctx, prj.GetCode(), rectNom, BcoulNom, IcoulNom,
                         fontNom))
    ctx.select_font_face(font_family, cairo.FONT_SLANT_NORMAL,
                         cairo.FONT_WEIGHT_NORMAL)
    show_text_rect(ctx,
                   prj.GetNom(),
                   rectNom,
                   ha='c',
                   b=0.2,
                   fontsizeMinMax=(-1, 0.016 * COEF))

    prj.zones_sens.append(Zone([rectNom], obj=prj))
    prj.pts_caract.append(posNom)

    #
    #  Support
    #
    prj.support.pt_caract = []
    rectSup = posSup + tailleSup
    prj.support.pts_caract.append(
        curve_rect_titre(ctx, prj.support.GetCode(), rectSup, BcoulSup,
                         IcoulSup, fontSup))
    ctx.select_font_face(font_family, cairo.FONT_SLANT_NORMAL,
                         cairo.FONT_WEIGHT_NORMAL)
    show_text_rect(ctx,
                   prj.support.GetNom(),
                   rectSup,
                   ha='c',
                   b=0.2,
                   fontsizeMinMax=(-1, 0.016 * COEF))

    prj.zones_sens.append(Zone([rectSup], obj=prj.support))
    prj.support.pts_caract.append(posSup)

    #
    #  Tableau des compétenecs
    #
    if not entete:
        competences = regrouperLst(prj, prj.GetCompetencesUtil())
        prj.pt_caract_comp = []

        if competences != []:

            ctx.set_line_width(0.001 * COEF)
            wc = tailleZComp[0] / len(competences)
            _x = posZComp[0]
            _y0, _y1 = posZElevesH[1], posZDeroul[1] + tailleZDeroul[1]

            for s in competences:
                #            s.rect=((_x, _y, wc, posZTaches[1] - posZComp[1]),)
                ctx.set_source_rgb(0, 0, 0)
                ctx.move_to(_x, _y0)  # + posZTaches[1] - posZComp[1])
                ctx.line_to(_x, _y1)
                ctx.stroke()
                ctx.set_source_rgba(0.5, 0.5, 0.5, 0.2)
                ctx.rectangle(_x, _y0, wc, _y1 - _y0)
                ctx.fill()
                _x += wc
            ctx.set_source_rgb(0, 0, 0)
            ctx.move_to(_x, _y0)  # + posZTaches[1] - posZComp[1])
            ctx.line_to(_x, _y1)
            ctx.stroke()

            ctx.select_font_face(font_family, cairo.FONT_SLANT_NORMAL,
                                 cairo.FONT_WEIGHT_NORMAL)
            ctx.set_source_rgb(0, 0, 0)
            ctx.set_line_width(0.001 * COEF)
            p = tableauV(ctx, [c[1:] for c in competences],
                         posZComp[0],
                         posZComp[1],
                         tailleZComp[0],
                         tailleZComp[1],
                         0,
                         nlignes=0,
                         va='c',
                         ha='g',
                         orient='v',
                         coul=BCoulCompS)

            prj.pt_caract_comp = getPts(p)

#    print "compétences", time.time() - tps

#
#  Tableau des élèves
#
#    tps = time.time()
    if not entete:
        ctx.select_font_face(font_family, cairo.FONT_SLANT_NORMAL,
                             cairo.FONT_WEIGHT_NORMAL)
        ctx.set_source_rgb(0, 0, 0)
        ctx.set_line_width(0.001 * COEF)
        l = []
        for i, e in enumerate(prj.eleves):
            e.pts_caract = []
            if pourDossierValidation:
                l.append(u"Elève " + str(i + 1))
            else:
                l.append(e.GetNomPrenom())

        #
        # Graduation
        #
        y = posZElevesH[1] + tailleZElevesH[1]
        w = tailleZElevesH[0]
        h = hEleves / 2
        for t, ha in [("0%", 'g'), ("50%", 'c'), ("100%", 'd')]:
            show_text_rect(ctx,
                           t, (posZElevesH[0], y, w, h),
                           ha=ha,
                           b=0.1,
                           fontsizeMinMax=(-1, 0.016 * COEF))

        prj.pt_caract_eleve = []
        if len(l) > 0:

            #
            # Barres d'évaluabilité
            #
            for i, e in enumerate(prj.eleves):
                ev = e.GetEvaluabilite(compil=True)[1]
                y = posZElevesH[1] + i * hEleves
                #            wr = tailleZElevesH[0]*r
                #            ws = tailleZElevesH[0]*s
                hb = hEleves / (len(prj.GetProjetRef().parties) + 1)
                #            y = posZElevesH[1] + (2*i*hb)+hb/2

                for j, part in enumerate(prj.GetProjetRef().parties.keys()):

                    barreH(ctx, posZElevesH[0], y + (j + 1) * hb,
                           tailleZElevesH[0], ev[part][0], ev[part][1], hb,
                           (1, 0, 0, 0.7), (0, 1, 0, 0.7), getCoulComp(part))

            rec = tableauH(ctx,
                           l,
                           posZElevesH[0],
                           posZElevesH[1],
                           tailleZElevesH[0],
                           0,
                           tailleZElevesH[1],
                           va='c',
                           ha='d',
                           orient='h',
                           coul=CoulAltern)

            prj.pt_caract_eleve = getPts(rec)

            #
            # Lignes horizontales
            #
            for i, e in enumerate(prj.eleves):
                prj.zones_sens.append(Zone([rec[i]], obj=e))
                Ic = CoulAltern[i][0]

                ctx.set_source_rgb(Ic[0], Ic[1], Ic[2])
                ctx.set_line_width(0.003 * COEF)
                ctx.move_to(posZElevesH[0] + tailleZElevesH[0], yEleves[i])
                ctx.line_to(posZComp[0] + tailleZComp[0], yEleves[i])
                ctx.stroke()

            #
            # Lignes verticales
            #
            for i, e in enumerate(prj.eleves):
                Ic = CoulAltern[i][0]

                ctx.set_source_rgb(Ic[0], Ic[1], Ic[2])
                ctx.set_line_width(0.003 * COEF)
                ctx.move_to(xEleves[i], yEleves[i])
                ctx.line_to(
                    xEleves[i], posZTaches[1] + tailleZTaches[1] + (i % 2) *
                    (ecartY / 2) + ecartY / 2)
                ctx.stroke()
                DrawCroisementsElevesCompetences(ctx, e, yEleves[i])

            #
            # Ombres des lignes verticales
            #
            e = 0.003 * COEF
            ctx.set_line_width(0.003 * COEF)
            for i in range(len(prj.eleves)):
                y = posZTaches[1] + tailleZTaches[1] + (i % 2) * (
                    ecartY / 2) + ecartY / 2
                ctx.set_source_rgb(1, 1, 1)
                ctx.move_to(xEleves[i] + e, yEleves[i] + e)
                ctx.line_to(xEleves[i] + e, y)
                ctx.move_to(xEleves[i] - e, yEleves[i] + e)
                ctx.line_to(xEleves[i] - e, y)
            ctx.stroke()

#    print "élèves", time.time() - tps

#
#  Tâches
#
    if not entete:
        #    tps = time.time()
        curve_rect_titre(
            ctx, u"Tâches à réaliser",
            (posZDeroul[0], posZDeroul[1], tailleZDeroul[0], tailleZDeroul[1]),
            BcoulZDeroul, IcoulZDeroul, fontZDeroul)

        y = posZTaches[1] - ecartTacheY

        # Les positions en Y haut et bas des phases
        yh_phase = {
            'Sup': [[], []],
            'Ana': [[], []],
            'Con': [[], []],
            'DCo': [[], []],
            'Rea': [[], []],
            'Val': [[], []],
            'XXX': [[], []]
        }

        phase = None
        y1 = y2 = y3 = 0  # juste pour éviter une erreur en cas d'echec d'ouverture.
        for t in prj.taches:
            if t.phase == "R1":
                y1 = y
            elif t.phase == "R2":
                y2 = y
            elif t.phase == "R3":
                y3 = y

            if phase != t.phase:
                y += ecartTacheY

            if t.phase != '':
                yb = DrawTacheRacine(ctx, t, y)
                if t.phase in ["Ana", "Con", "DCo", "Rea", "Val", 'XXX']:
                    yh_phase[t.phase][0].append(y)
                    yh_phase[t.phase][1].append(yb)
                y = yb

            if y3 == 0 and t == prj.taches[-1]:
                y3 = y

            phase = t.phase
    #    print "    ", time.time() - tps
    #
    # Les lignes horizontales en face des taches
    # et les croisements Tâche/Competences
    #
        x = posZTaches[0] + tailleZTaches[0]
        for t, y in yTaches:
            if not t.phase in ["R1", "R2", "R3", "S", "Rev"]:
                DrawLigne(ctx, x, y)
            if (t.phase in ["R1", "R2", "R3", "S"]
                    and t.DiffereSuivantEleve()) or t.estPredeterminee():
                dy = hRevue
                y = y - ((len(prj.eleves) - 1) * dy) / 2
                #            print "phase = ", t.phase
                h = 0.006 * COEF
                for eleve in prj.eleves:
                    DrawCroisementsCompetencesRevue(ctx, t, eleve, y, h)
                    y += dy
            else:
                DrawCroisementsCompetencesTaches(ctx, t, y)

        # Nom des phases
        for phase, yh in yh_phase.items():
            #        print phase, yh
            if len(yh[0]) > 0:
                yh[0] = min(yh[0])
                yh[1] = max(yh[1])
                ctx.set_source_rgb(BCoulTache[phase][0], BCoulTache[phase][1],
                                   BCoulTache[phase][2])
                ctx.select_font_face(font_family, cairo.FONT_SLANT_ITALIC,
                                     cairo.FONT_WEIGHT_NORMAL)
                if wPhases > yh[1] - yh[0]:
                    orient = "h"
                else:
                    orient = "v"
                try:
                    n = prj.GetProjetRef().phases[phase][1]
                except KeyError:
                    n = ""
                show_text_rect(ctx,
                               n, (posZDeroul[0] + ecartX / 6, yh[0], wPhases,
                                   yh[1] - yh[0]),
                               ha='c',
                               orient=orient,
                               b=0.1,
                               le=0.7,
                               couper=False)

    #            show_text_rect(ctx, constantes.NOM_PHASE_TACHE[prj.GetTypeEnseignement(True)][phase],
    #                           (posZDeroul[0] + ecartX/6, yh[0],
    #                            wPhases, yh[1]-yh[0]),
    #                           ha = 'c', orient = orient, b = 0,
    #                           couper = False)

    #    print "taches", time.time() - tps

    #
    # Durées élève entre revues (uniquement en période "terminale")
    #
    if not entete:
        #    tps = time.time()
        posEpreuve = prj.GetProjetRef().getPeriodeEval()
        if posEpreuve is not None and prj.position == posEpreuve:
            y0 = posZTaches[1]
            y4 = y1 + len(prj.eleves) * hRevue + 2 * ecartTacheY
            #        y4 = y1+2*ecartTacheY + 0.015
            #        y5 = y2+2*ecartTacheY + 0.015
            y5 = y2 + len(prj.eleves) * hRevue + 2 * ecartTacheY
            #            print y0, y1, y2, y3, y4, y5
            md1 = md2 = md3 = 0
            for i, e in enumerate(prj.eleves):
                md1 = max(e.GetDuree(phase="R1"), md1)
                md2 = max(e.GetDuree(phase="R2"), md2)
                md3 = max(e.GetDuree(phase="R3"), md3)

            for i, e in enumerate(prj.eleves):
                d1 = e.GetDuree(phase="R1")
                d2 = e.GetDuree(phase="R2")
                d3 = e.GetDuree(phase="R3")
                Ic = CoulAltern[i][0]
                ctx.set_source_rgb(Ic[0], Ic[1], Ic[2])
                ctx.set_line_width(0.005 * COEF)
                if md1 > 0:
                    ctx.move_to(xEleves[i], y0)
                    ctx.line_to(xEleves[i], y0 + (y1 - y0) * d1 / md1)
                    ctx.stroke()
                if md2 > 0:
                    ctx.move_to(xEleves[i], y4)
                    ctx.line_to(xEleves[i], y4 + (y2 - y4) * d2 / md2)
                    ctx.stroke()
                if md3 > 0:
                    ctx.move_to(xEleves[i], y5)
                    ctx.line_to(xEleves[i], y5 + (y3 - y5) * d3 / md3)
                    ctx.stroke()

#    print "durées", time.time() - tps

#
# Croisements élèves/tâches
#
    if not entete:
        #    tps = time.time()
        for t, y in yTaches:
            DrawCroisementsElevesTaches(ctx, t, y)

    #    print "CroisementsElevesTaches", time.time() - tps

    #
    # Durées du projet (durées élèves)
    #
    #    tps = time.time()
        for i, e in enumerate(prj.eleves):
            #        x = posZElevesV[0]+i*tailleZElevesV[0]/len(prj.eleves)-wEleves/2
            x = xEleves[i] - wEleves * 3 / 4
            y = posZTaches[1] + tailleZTaches[1] + (i % 2) * (ecartY /
                                                              2) + ecartY / 2
            d = e.GetDuree()
            dureeRef = prj.GetProjetRef().duree
            taux = abs((d - dureeRef) / dureeRef) * 100
            #        print "   duree", d, "/", dureeRef
            #        print "   taux", taux
            if taux < constantes.DELTA_DUREE:
                ctx.set_source_rgb(0.1, 1, 0.1)
            elif taux < constantes.DELTA_DUREE2:
                ctx.set_source_rgb(1, 0.6, 0.1)
            else:
                ctx.set_source_rgb(1, 0.1, 0.1)
            show_text_rect(ctx,
                           getHoraireTxt(d),
                           (x, y, wEleves * 3 / 2, ecartY / 2),
                           ha='c',
                           b=0)

#    print "dureeProjet", time.time() - tps
#
# Informations
#
    if not entete:
        info(ctx, margeX, margeY)
Exemplo n.º 4
0
def Draw(ctx, prg, mouchard=False):
    """ Dessine une fiche de progression <prg>
        dans un contexte cairo <ctx>
    """

    #        print "Draw progression"
    #    InitCurseur()

    #    tps = time.time()
    #
    # Options générales
    #
    options = ctx.get_font_options()
    options.set_antialias(cairo.ANTIALIAS_SUBPIXEL)
    options.set_hint_style(cairo.HINT_STYLE_NONE)  #cairo.HINT_STYLE_FULL)#
    options.set_hint_metrics(cairo.HINT_METRICS_OFF)  #cairo.HINT_METRICS_ON)#
    ctx.set_font_options(options)

    DefinirZones(prg, ctx)
    #    DefinirCouleurs(prg.GetNbrPeriodes())
    #    print "DefinirCouleurs", IcoulPos

    #
    #    pour stocker des zones caractéristiques (à cliquer, ...)
    #
    prg.zones_sens = []
    prg.pt_caract = []
    #    prg.rect = []
    #    prg.rectComp = {}

    #
    # variables locales
    #
    ref = prg.classe.referentiel
    classe = prg.classe

    #
    # Type d'enseignement
    #
    tailleTypeEns = taillePro[0] / 2
    t = ref.Enseignement[0]
    ctx.select_font_face(font_family, cairo.FONT_SLANT_NORMAL,
                         cairo.FONT_WEIGHT_BOLD)
    ctx.set_source_rgb(0.6, 0.6, 0.9)

    h = taillePos[1] * 0.8
    show_text_rect(ctx,
                   t, (posPro[0], posPos[1], tailleTypeEns, h),
                   va='c',
                   ha='g',
                   b=0,
                   orient='h',
                   fontsizeMinMax=(-1, -1),
                   fontsizePref=-1,
                   wrap=True,
                   couper=False,
                   coulBord=(0, 0, 0))

    t = ref.Enseignement[1]
    ctx.set_source_rgb(0.3, 0.3, 0.8)
    show_text_rect(ctx,
                   t,
                   (posPro[0], posPos[1] + h, tailleTypeEns, taillePos[1] - h),
                   va='c',
                   ha='g',
                   b=0,
                   orient='h',
                   fontsizeMinMax=(-1, -1),
                   fontsizePref=-1,
                   wrap=True,
                   couper=False)

    #
    # Positions dans l'année
    #
    posPos[0] = posNom[0] + tailleNom[0] + ecartX + tailleTypeEns

    taillePos[0] = taillePro[0] / 2
    ctx.set_line_width(0.0015 * COEF)
    r = (posPos[0], posPos[1], taillePos[0], taillePos[1])
    rects = DrawPeriodes(ctx,
                         r,
                         prg.GetPositions(),
                         ref.periodes,
                         tailleTypeEns=tailleTypeEns)
    #    prg.rect.append(posPos+taillePos)

    for i, re in enumerate(rects):
        prg.zones_sens.append(Zone([re], param="POS" + str(i)))
    prg.zones_sens.append(Zone([r], param="POS"))

    #
    # Etablissement
    #
    if classe.etablissement != u"":
        t = classe.etablissement + u" (" + classe.ville + u")"
        ctx.select_font_face(font_family, cairo.FONT_SLANT_NORMAL,
                             cairo.FONT_WEIGHT_NORMAL)
        show_text_rect(ctx,
                       t, (posPos[0], posPos[1] + taillePos[1], taillePos[0],
                           posPro[1] - posPos[1] - taillePos[1]),
                       va='c',
                       ha='g',
                       b=0.2,
                       orient='h',
                       fontsizeMinMax=(-1, -1),
                       fontsizePref=-1,
                       wrap=True,
                       couper=False,
                       coulBord=(0, 0, 0))

    #
    # Image
    #
    bmp = prg.image
    if bmp != None:
        ctx.save()
        tfname = tempfile.mktemp()
        try:
            bmp.SaveFile(tfname, wx.BITMAP_TYPE_PNG)
            image = cairo.ImageSurface.create_from_png(tfname)
        finally:
            if os.path.exists(tfname):
                os.remove(tfname)

        w = image.get_width() * 1.1
        h = image.get_height() * 1.1

        s = min(tailleImg[0] / w, tailleImg[1] / h)
        dx = (tailleImg[0] - s * image.get_width()) / 2
        dy = (tailleImg[1] - s * image.get_height()) / 2
        ctx.translate(posImg[0] + dx, posImg[1] + dy)
        ctx.scale(s, s)
        ctx.set_source_surface(image, 0, 0)
        ctx.paint()
        ctx.restore()

    #
    #  Equipe
    #
    rectEqu = posEqu + tailleEqu
    prg.pt_caract.append(
        curve_rect_titre(ctx, u"Equipe pédagogique", rectEqu, BcoulEqu,
                         IcoulEqu, fontEqu))

    lstTexte = []
    g = None
    c = []
    for i, p in enumerate(prg.equipe):
        lstTexte.append(p.GetNomPrenom(disc=constantes.AFFICHER_DISC_FICHE))
        if p.referent:
            g = i
        c.append(constantes.COUL_DISCIPLINES[p.discipline])
    lstCodes = [u" \u25CF"] * len(lstTexte)

    if len(lstTexte) > 0:
        r = liste_code_texte(ctx,
                             lstCodes,
                             lstTexte,
                             posEqu[0],
                             posEqu[1],
                             tailleEqu[0],
                             tailleEqu[1] + 0.0001 * COEF,
                             0.1 * tailleEqu[1] + 0.0001 * COEF,
                             0.1,
                             gras=g,
                             lstCoul=c,
                             va='c')

    for i, p in enumerate(prg.equipe):
        prg.zones_sens.append(Zone([r[i]], obj=p))
    prg.zones_sens.append(Zone([rectEqu], param="EQU"))
    #        p.rect = [r[i]]
    #        prj.pts_caract.append(getPts(r))

    #
    #  Calendrier
    #
    #    prg.pt_caract.append(posPro)
    rectPro = posPro + taillePro
    prg.pt_caract.append(
        curve_rect_titre(ctx, u"Calendrier", rectPro, BcoulPro, IcoulPro,
                         fontPro))
    ctx.select_font_face(font_family, cairo.FONT_SLANT_NORMAL,
                         cairo.FONT_WEIGHT_NORMAL)
    show_text_rect(ctx,
                   constantes.ellipsizer(u"",
                                         constantes.LONG_MAX_PROBLEMATIQUE),
                   rectPro,
                   ha='g',
                   b=0.5,
                   fontsizeMinMax=(-1, 0.016 * COEF))
    DrawCalendrier(ctx, rectPro, prg.calendrier)
    #    prg.rect.append(rectPro)
    prg.zones_sens.append(Zone([rectPro], param="CAL"))

    #
    #  Années
    #
    #    prg.pt_caract = []
    #    prg.pts_caract = []
    rectNom = posNom + tailleNom
    prg.pt_caract.append(
        curve_rect_titre(ctx, u"Progression pédagogique", rectNom, BcoulNom,
                         IcoulNom, fontNom))
    ctx.select_font_face(font_family, cairo.FONT_SLANT_NORMAL,
                         cairo.FONT_WEIGHT_NORMAL)
    show_text_rect(ctx,
                   u"Années scolaires " + prg.GetAnnees(),
                   rectNom,
                   ha='c',
                   b=0.2,
                   fontsizeMinMax=(-1, 0.016 * COEF))

    prg.zones_sens.append(Zone([rectNom], param="ANN"))
    #    prg.pt_caract.append(posNom)

    #
    #  Tableau des compétenecs
    #
    competences = ref._listesCompetences_simple["S"]

    ctx.set_line_width(0.001 * COEF)
    _x = _x0 = posZComp[0]
    _y0, _y1 = posZElevesH[1] - ecartY / 2, posZDeroul[1] + tailleZDeroul[1]

    lcomp = []

    #    print "competences", competences
    for i, g1 in enumerate(competences):
        k1, h1, l1 = g1
        dx = wColComp / 3
        if len(l1) == 0:
            l1 = [[k1, h1]]
            dx = 0

        coul = list(ICoulComp[i][:3]) + [0.2]
        for k2, h2 in l1:
            #
            # Lignes verticales et rectangles clairs
            #
            rect = (_x, _y0, wColComp, _y1 - _y0)
            ctx.set_source_rgb(0, 0, 0)
            ctx.move_to(_x, _y0)
            ctx.line_to(_x, _y1)
            ctx.stroke()
            ctx.set_source_rgba(*coul)
            ctx.rectangle(*rect[:4])
            ctx.fill()

            #            prg.zones_sens.append(Zone([rect], param = k2))
            #            prg.rectComp[k2] = [rect]
            #            prg.pts_caract.append((_x,_y0))

            _x += wColComp

        # Dernière ligne
        ctx.set_source_rgb(0, 0, 0)
        ctx.move_to(_x, _y0)
        ctx.line_to(_x, _y1)
        ctx.stroke()

        ctx.select_font_face(font_family, cairo.FONT_SLANT_NORMAL,
                             cairo.FONT_WEIGHT_NORMAL)
        ctx.set_source_rgb(0, 0, 0)
        ctx.set_line_width(0.001 * COEF)

        #        # Titre famille de compétences
        #        ht = tailleZComp[1] / 4
        #        show_text_rect(ctx, k1, (_x0, posZComp[1], _x-_x0, ht), va = 'c', ha = 'c', b = 0.3, orient = 'h')

        l = [k2[0] for k2 in l1]
        rects = tableauV(ctx,
                         l,
                         _x0,
                         posZComp[1],
                         _x - _x0,
                         tailleZComp[1],
                         0,
                         nlignes=0,
                         va='c',
                         ha='g',
                         orient='v',
                         coul=ICoulComp[i],
                         b=0.3)

        for i, r in enumerate(rects):
            prg.zones_sens.append(Zone([r], param="CMP" + l[i]))

        lcomp.extend(l)

        #        prg.pt_caract_comp.extend(getPts(p))

        _x += dx
        _x0 = _x

    #
    #  Tableau des CI/Thèmes ?
    #
    if len(ref.CentresInterets) > 0:
        rectCI = (posZElevesH[0], posZElevesH[1], tailleZElevesH[0],
                  tailleZElevesH[1])
        curve_rect_titre(ctx, ref.nomCI, rectCI, BcoulCI, IcoulCI, fontCI)

        ctx.select_font_face(font_family, cairo.FONT_SLANT_NORMAL,
                             cairo.FONT_WEIGHT_NORMAL)
        ctx.set_source_rgb(0, 0, 0)
        ctx.set_line_width(0.0005 * COEF)
        l = []
        for i, e in enumerate(ref.CentresInterets):
            #        e.pts_caract = []
            l.append(e)

        #
        # Croisements divers
        #
        x, y = posZElevesH[0] + ecartX / 2, posZElevesH[1] + ecartY / 2
        w, h = tailleZElevesH[0] - ecartX, tailleZElevesH[1] - ecartY

        #    prg.pt_caract_eleve = []
        if len(l) > 0:
            rec = tableauH(ctx,
                           l,
                           x,
                           y,
                           w,
                           0,
                           h,
                           va='c',
                           ha='d',
                           orient='h',
                           coul=CoulAltern,
                           tailleFixe=True)

            #        prj.pt_caract_eleve = getPts(rec)

            #
            # Lignes horizontales
            #
            for i, e in enumerate(ref.CentresInterets):
                prg.zones_sens.append(Zone([rec[i]], param="CI" + str(i)))

                Ic = CoulAltern[i][0]

                ctx.set_source_rgb(Ic[0], Ic[1], Ic[2])
                ctx.set_line_width(0.003 * COEF)
                ctx.move_to(posZElevesH[0] + tailleZElevesH[0] - ecartX / 2,
                            yEleves[i] + ecartY / 2)
                ctx.line_to(posZComp[0] + tailleZComp[0],
                            yEleves[i] + ecartY / 2)
                ctx.stroke()

            #
            # Lignes verticales
            #
            for i, e in enumerate(ref.CentresInterets):
                Ic = CoulAltern[i][0]

                ctx.set_source_rgb(Ic[0], Ic[1], Ic[2])
                ctx.set_line_width(0.003 * COEF)
                ctx.move_to(xEleves[i], yEleves[i] + ecartY / 2)
                ctx.line_to(
                    xEleves[i], posZTaches[1] + tailleZTaches[1] + (i % 2) *
                    (ecartY / 2) + ecartY / 2)
                ctx.stroke()
    #            DrawCroisementsElevesCompetences(ctx, prg, e, yEleves[i])

    #
    # Ombres des lignes verticales
    #
            e = 0.003 * COEF
            ctx.set_line_width(0.003 * COEF)
            for i in range(len(ref.CentresInterets)):
                y = posZTaches[1] + tailleZTaches[1] + (i % 2) * (
                    ecartY / 2) + ecartY / 2
                ctx.set_source_rgb(1, 1, 1)
                ctx.move_to(xEleves[i] + e, yEleves[i] + e + ecartY / 2)
                ctx.line_to(xEleves[i] + e, y)
                ctx.move_to(xEleves[i] - e, yEleves[i] + e + ecartY / 2)
                ctx.line_to(xEleves[i] - e, y)
            ctx.stroke()

    #
    #  Séquences
    #
    curve_rect_titre(
        ctx, u"Séquences",
        (posZDeroul[0], posZDeroul[1], tailleZDeroul[0], tailleZDeroul[1]),
        BcoulZDeroul, IcoulZDeroul, fontZDeroul)

    y = posZTaches[1] - ecartTacheY

    # Les positions en Y haut et bas des périodes
    yh_phase = {c: [[], []] for c in range(prg.GetNbrPeriodes())}

    position = None
    for t in prg.sequences_projets:
        pos = t.GetPosition()

        if position != pos:
            y += ecartTacheY

        yb = DrawSequenceProjet(ctx, prg, t, y)
        yh_phase[pos][0].append(y)
        yh_phase[pos][1].append(yb)
        y = yb

        position = pos

    #
    # Les lignes horizontales en face des sequences
    # et les croisements Séquences/Competences
    #
    x = posZTaches[0] + tailleZTaches[0]
    for doc, y in yTaches:
        DrawLigne(ctx, x, y)
        DrawCroisementsCompetencesTaches(ctx, prg, doc, lcomp, y)
        if hasattr(doc, 'CI'):
            DrawCroisementsCISeq(ctx, prg, doc, y)

    # Nom des périodes
#    print "yh_phase", yh_phase

    fontsize = wPhases

    for i, (phase, yh) in enumerate(yh_phase.items()):
        if len(yh[0]) > 0:

            _y = min(yh[0])
            yh[1] = max(yh[1])
            y = _y
            h = yh[1] - _y

            c = BcoulPos[phase]
            ctx.set_source_rgb(c[0], c[1], c[2])
            ctx.select_font_face(font_family, cairo.FONT_SLANT_ITALIC,
                                 cairo.FONT_WEIGHT_NORMAL)

            show_text_rect(ctx,
                           str(phase + 1),
                           (posZDeroul[0] + ecartX / 6, y, wPhases, h),
                           fontsizeMinMax=(fontsize, fontsize),
                           ha='c',
                           orient="h",
                           b=0.1,
                           le=0.7,
                           couper=False)

    #
    # Informations
    #
    info(ctx, margeX, margeY)