Ejemplo n.º 1
0
    def do_print(self, evt):
        # genero el renderizador con propiedades del PDF
        paper_size = self.paper_size or DEFAULT_PAPER_SIZE
        orientation = self.paper_orientation or DEFAULT_PAPER_ORIENTATION

        t = Template(
            format=paper_size,
            orientation=orientation,
            elements=[e.as_dict() for e in self.elements if not e.static])
        t.add_page()
        if not t['logo'] or not os.path.exists(t['logo']):
            # put a default logo so it doesn't throw an exception
            logo = os.path.join(os.path.dirname(__file__), 'tutorial',
                                'logo.png')
            t.set('logo', logo)
        try:
            t.render(self.filename + ".pdf")
        except:
            if DEBUG and False:
                import pdb
                pdb.pm()
            else:
                raise
        if sys.platform.startswith("linux"):
            os.system('xdg-open "%s.pdf"' % self.filename)
        else:
            os.startfile(self.filename + ".pdf")
Ejemplo n.º 2
0
 def do_print(self, evt):
     # genero el renderizador con propiedades del PDF
     t = Template(elements=[e.as_dict() for e in self.elements if not e.static])
     t.add_page()
     if not t['logo'] or not os.path.exists(t['logo']):
         # put a default logo so it doesn't trow an exception
         logo = os.path.join(os.path.dirname(__file__), 'tutorial','logo.png')
         t.set('logo', logo)
     try:
         t.render(self.filename +".pdf")
     except:
         if DEBUG and False:
             import pdb;
             pdb.pm()
         else:
             raise
     if sys.platform=="linux2":
         os.system("evince ""%s""" % self.filename +".pdf")
     else:
         os.startfile(self.filename +".pdf")
Ejemplo n.º 3
0
 def do_print(self, evt):
     # genero el renderizador con propiedades del PDF
     t = Template(
         elements=[e.as_dict() for e in self.elements if not e.static])
     t.add_page()
     if not t['logo'] or not os.path.exists(t['logo']):
         # put a default logo so it doesn't trow an exception
         logo = os.path.join(os.path.dirname(__file__), 'tutorial',
                             'logo.png')
         t.set('logo', logo)
     try:
         t.render(self.filename + ".pdf")
     except:
         if DEBUG and False:
             import pdb
             pdb.pm()
         else:
             raise
     if sys.platform == "linux2":
         os.system("evince " "%s" "" % self.filename + ".pdf")
     else:
         os.startfile(self.filename + ".pdf")
Ejemplo n.º 4
0
 def do_print(self, evt):
     # genero el renderizador con propiedades del PDF
     paper_size = self.paper_size or DEFAULT_PAPER_SIZE
     orientation = self.paper_orientation or DEFAULT_PAPER_ORIENTATION
     
     t = Template(format=paper_size, orientation=orientation, elements=[e.as_dict() for e in self.elements if not e.static])
     t.add_page()
     if not t['logo'] or not os.path.exists(t['logo']):
         # put a default logo so it doesn't throw an exception
         logo = os.path.join(os.path.dirname(__file__), 'tutorial','logo.png')
         t.set('logo', logo)
     try:
         t.render(self.filename +".pdf")
     except:
         if DEBUG and False:
             import pdb;
             pdb.pm()
         else:
             raise
     if sys.platform.startswith("linux"):
         os.system('xdg-open "%s.pdf"' % self.filename)
     else:
         os.startfile(self.filename +".pdf")
Ejemplo n.º 5
0
def test_template_badinput():
    """Testing Template() with non-conforming definitions."""
    for arg in (
            "format",
            "orientation",
            "unit",
            "title",
            "author",
            "subject",
            "creator",
            "keywords",
    ):
        with raises(TypeError):
            Template(**{arg: 7})  # numeric instead of str
    elements = [{}]
    with raises(KeyError):
        tmpl = Template(elements=elements)
    elements = [{"name": "n", "type": "X"}]
    with raises(KeyError):
        tmpl = Template(elements=elements)
        tmpl.render()
    elements = [  # missing mandatory x2
        {
            "name": "n",
            "type": "T",
            "x1": 0,
            "y1": 0,
            "y2": 0,
            "text": "Hello!",
        }
    ]
    with raises(KeyError):
        tmpl = Template(elements=elements)
        tmpl["n"] = "hello"
        tmpl.render()
    elements = [  # malformed y2
        {
            "name": "n",
            "type": "T",
            "x1": 0,
            "y1": 0,
            "x2": 0,
            "y2": "x",
            "text": "Hello!",
        }
    ]
    with raises(TypeError):
        tmpl = Template(elements=elements)
        tmpl["n"] = "hello"
        tmpl.render()
    tmpl = Template()
    with raises(FPDFException):
        tmpl.parse_csv(HERE / "mandmissing.csv", delimiter=";")
    with raises(ValueError):
        tmpl.parse_csv(HERE / "badint.csv", delimiter=";")
    with raises(ValueError):
        tmpl.parse_csv(HERE / "badfloat.csv", delimiter=";")
    with raises(KeyError):
        tmpl.parse_csv(HERE / "badtype.csv", delimiter=";")
        tmpl.render()
    with warns(DeprecationWarning):
        Template(infile="whatever")
    with raises(AttributeError):
        with warns(DeprecationWarning):
            tmpl = Template()
            tmpl.render(dest="whatever")