Exemple #1
0
    def __init__(self, path, maj=False, data=None):
        """initialisation d'un générateur odt pour les tuteurs.
        
        En haut de chaque page A5 en sortie, il créée un tableau

        +----------------+-----------+--------+
        |  Responsable   | Élève     | Classe |
        +================+===========+========+
        |  nom resp      | nom eleve | cl     |
        +----------------+-----------+--------+

        :param str path: chemin vers le fichier des csv tuteurs
        :param boolean maj:  mode màj ou complet
        :param dict data: si maj=True, il doit contenir le dictionnaire des pp
            et tuteurs

        """
        self.nom = basename(path)[:-4] #nom du fichier sans extension
        base = dirname(path)
        #fallacieux en cas de màj.
        # .. todo:: vérifier utilité et effacer
        self.classe = ((self.nom).split('Tuteur_'))[-1] #vraiment lié au nom de fichier
        self.document = OpenDocumentText()
        self.defineStyles()
        # def du header complet
        head_style = getattr(self, "Header", None)
        p = P(stylename=head_style)
        mp = MasterPage(name="Standard", pagelayoutname="Mpm1")
        h = Header()
        h.addElement(p)
        mp.addElement(h)
        self.document.masterstyles.addElement(mp)
        
        #import des textes de la page odt tuteur
        try:
            from yaml import CLoader as Loader
        except ImportError:
            from yaml import Loader
        home = expanduser("~/.refnumtool.d")
        with open(join(home,"text_extract_tuteur.yaml")) as file:
            self.msg = load(file, Loader=Loader)

        if not(maj):
            file = open(path, "r", encoding="utf8")
            dialect=csv.Sniffer().sniff(file.readline())
            file.seek(0) # se remettre en début de fichier
            reader = csv.DictReader(file, dialect=dialect)
        
            for d in reader:
                self.make_parent_id(d)
            file.close()
            self.save(join(base, "ENT_id_Tuteur_"+self.classe+".odt")) 
        else: # cas d'une màj
            #for pp in data.values(): # superflu, génération par classe pour les tuteurs
            if "Tuteur" in data:  # test superflu en principe
                for d in data["Tuteur"]:
                    self.make_parent_id(d)
            self.save(join(base, "ENT_id_Tuteur_"+data["elycee"]+"_"+time.strftime("%d%m%Y")+".odt")) 
Exemple #2
0
 def addHeaderFooter(self,header=None,footer=None):
     if header or footer:
         mp = MasterPage(name="Standard", pagelayoutname=self.plheaderstyle)
         self.textdoc.masterstyles.addElement(mp)
         if header:
             h = Header()
             hp = P(text=header)#,stylename=self.headerstyle)
             h.addElement(hp)
             mp.addElement(h)
         if footer:
             f = Footer()
             fp = P(text=footer,stylename=self.footercenterstyle)
             f.addElement(fp)
             mp.addElement(f)
Exemple #3
0
 def __init__(self):
     self.textDoc = OpenDocumentText()
     self.h = Header()
     self.f = Footer()
     self.s = self.textDoc.styles
     self.pl = PageLayout(name="pagelayout")
     #margenes para la pagina (PageLayout)
     self.pl.addElement(PageLayoutProperties(margintop="1cm"))
     self.textDoc.automaticstyles.addElement(self.pl)
     self.mp = MasterPage(name="Standard", pagelayoutname=self.pl)
     self.textDoc.masterstyles.addElement(self.mp)
     self.estilos = {}
     self.ConfigurarEstilos()
Exemple #4
0
 def addImageHeaderFooter(self,header=None,footer=None):
     if header or footer:
         mp = MasterPage(name="Standard", pagelayoutname=self.pliheaderstyle)
         self.textdoc.masterstyles.addElement(mp)
         if header:
             h = Header()
             p = P()
             href = self.textdoc.addPicture(header)
             f = Frame(name="membrete", anchortype="paragraph", width="17cm", height="1.5cm", zindex="0")
             p.addElement(f)
             img = Image(href=href, type="simple", show="embed", actuate="onLoad")
             f.addElement(img)
             h.addElement(p)
             
             mp.addElement(h)
         if footer:
             fo = Footer()
             pn = PageNumber()
             fp = P(text=footer,stylename=self.footercenterstyle)#FIXME: Pagen number shoulb be better
             fp.addElement(pn)
             fo.addElement(fp)
             mp.addElement(fo)
Exemple #5
0
# This is free software.  You may redistribute it under the terms
# of the Apache license and the GNU General Public License Version
# 2 or at your option any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
#
# Contributor(s):
#

from odf.opendocument import OpenDocumentText
from odf.style import PageLayout, MasterPage, Header, Footer
from odf.text import P

textdoc = OpenDocumentText()
pl = PageLayout(name="pagelayout")
textdoc.automaticstyles.addElement(pl)
mp = MasterPage(name="Standard", pagelayoutname=pl)
textdoc.masterstyles.addElement(mp)
h = Header()
hp = P(text="header try")
h.addElement(hp)
mp.addElement(h)
textdoc.save("headers.odt")
Exemple #6
0
 def __init__(self, *datos):
     self.textDoc = OpenDocumentText()
     self.h = Header()
     self.f = Footer()
     self.s = self.textDoc.styles
     self.pl = PageLayout(name="pagelayout")
     #datos para la cabecera
     Autor = datos[0]
     Obra = datos[1]
     #margenes para la pagina (PageLayout)
     layoutPagina = datos[2]
     print("layoutPagina")
     print(layoutPagina)
     MRight = str(layoutPagina[0]) + "cm"
     print("MRight " + MRight)
     MLeft = str(layoutPagina[1]) + "cm"
     MTop = str(layoutPagina[2]) + "cm"
     MBottom = str(layoutPagina[3]) + "cm"
     PaginaInicial = layoutPagina[4]
     #anadimos los datos a la pagina
     self.pl.addElement(
         PageLayoutProperties(margintop=MTop,
                              marginbottom=MBottom,
                              marginleft=MRight,
                              marginright=MLeft))
     self.textDoc.automaticstyles.addElement(self.pl)
     self.mp = MasterPage(name="Standard", pagelayoutname=self.pl)
     self.textDoc.masterstyles.addElement(self.mp)
     #Cabecera estilos
     #Normal
     EstiloCabeceraNormal = "CabeceraNormal"
     estilo = Style(name=EstiloCabeceraNormal,
                    family="text",
                    parentstylename="Standard")
     estilo.addElement(
         TextProperties(fontweight="light",
                        fontfamily="helvetica",
                        fontsize="9pt"))
     self.s.addElement(estilo)
     #Negritas
     EstiloCabeceraNegritas = "CabeceraNegritas"
     estilo = Style(name=EstiloCabeceraNegritas,
                    family="text",
                    parentstylename=EstiloCabeceraNormal)
     estilo.addElement(TextProperties(fontweight="bold"))
     self.s.addElement(estilo)
     #Normal centrado
     EstiloCabeceraNormalCentrado = "CabeceraNormalCentrado"
     estilo = Style(name=EstiloCabeceraNormalCentrado,
                    family="paragraph",
                    parentstylename=EstiloCabeceraNormal)
     estilo.addElement(
         ParagraphProperties(textalign="center",
                             numberlines="true",
                             linenumber="0"))
     self.s.addElement(estilo)
     #linea horizontal fina
     linea_horizontal_fina = Style(name="Lineahorizontalfina",
                                   displayname="Horizontal Line Thin",
                                   family="paragraph")
     linea_horizontal_fina.addElement(ParagraphProperties(margintop="0cm", marginbottom="0cm", marginright="0cm", marginleft="0cm", \
     contextualspacing="false", borderlinewidthbottom="0cm 0.030cm 0.02cm", padding="0cm", borderleft="none", borderright="none", \
     bordertop="none", borderbottom="0.06pt double #3a3b3d", numberlines="false", linenumber="0", joinborder="false"))
     self.s.addElement(linea_horizontal_fina)
     #numeracion
     numeracion = "Numeracion"
     estilo = Style(name=numeracion, family="paragraph")
     #estilo.addElement(PageNumber(selectpage="current"))
     #Cabecera contenidos
     hp = P()
     texto_cabecera = Span(stylename=EstiloCabeceraNegritas,
                           text="Proyecto:\t")
     hp.addElement(texto_cabecera)
     texto_cabecera = Span(stylename=EstiloCabeceraNormal, text=Obra)
     hp.addElement(texto_cabecera)
     self.h.addElement(hp)
     hp = P()
     texto_cabecera = Span(stylename=EstiloCabeceraNegritas,
                           text="Autor:\t")
     hp.addElement(texto_cabecera)
     texto_cabecera = Span(stylename=EstiloCabeceraNormal, text=Autor)
     hp.addElement(texto_cabecera)
     self.h.addElement(hp)
     hp = P(stylename=linea_horizontal_fina)
     self.h.addElement(hp)
     self.mp.addElement(self.h)
     #Pie de pagina
     fp = P(stylename=EstiloCabeceraNormalCentrado)
     pagina = Span(stylename=EstiloCabeceraNormal, text="Página: ")
     fp.addElement(pagina)
     numero = PageNumber(selectpage="auto", text=4)
     fp.addElement(numero)
     self.f.addElement(fp)
     self.mp.addElement(self.f)