Beispiel #1
0
    def do_print(self, evt):
        # Generate the pdf with the in_memory template
        paper_size = self.paper_size or Constants.DEFAULT_PAPER_SIZE
        orient = self.paper_orientation or Constants.DEFAULT_PAPER_ORIENTATION

        t = Template(
                format=paper_size,
                orientation=orient,
                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 Exception:
            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")