Esempio n. 1
0
 def _lcg_presentation(self):
     presentation = lcg.Presentation()
     if self._vmargin == 0:
         presentation.separator_margin = lcg.UMm(0)
     else:
         presentation.separator_margin = lcg.UFont(0.2)
     return presentation
Esempio n. 2
0
 def _pdf(self):
     start_time = pytis.data.DateTime.now()
     T = pytis.data.DBTransactionDefault
     transaction = T(connection_data=config.dbconnection, isolation=T.REPEATABLE_READ)
     children = []
     if self._form is not None and self._row_template is not None:
         i = 1
         row_template = self._row_template
         for row in self._form.presented_rows():
             row_lcg_globals = self._LCGGlobals(self._resolver, self._form, self._form_bindings,
                                                self._codebooks, transaction, current_row=row,
                                                parameters=self._parameters)
             id_ = 'pytissubdoc%d' % (i,)
             row_template_lcg = row_template.lcg()
             parameters = self._template_parameters(row_template)
             document = lcg.ContentNode(id=id_, title=' ', # let's avoid printing the id
                                        content=row_template_lcg, globals=row_lcg_globals,
                                        **parameters)
             children.append(document)
             i += 1
     lcg_globals = self._LCGGlobals(self._resolver, self._form, self._form_bindings,
                                    self._codebooks, transaction, parameters=self._parameters)
     lcg_globals['app'] = self._application_variables
     body = self._body
     if not body:
         body = []
     elif not isinstance(body, (list, tuple,)):
         body = [body]
     children = ([document_.lcg_document(globals=lcg_globals) for document_ in body] +
                 children)
     lcg_content = lcg.ContentNode(id='__dummy', content=lcg.Content(), children=children,
                                   **self._body_parameters)
     presentation = lcg.Presentation()
     presentation.font_name = 'DejaVu'
     presentation.font_family = lcg.FontFamily.FIXED_WIDTH
     def margin(key):
         size = self._page_layout.get(key)
         if size is None:
             size = UMm(10)
         return size
     presentation.top_margin = margin(PAGE_TOP_MARGIN)
     presentation.bottom_margin = margin(PAGE_BOTTOM_MARGIN)
     presentation.left_margin = margin(PAGE_LEFT_MARGIN)
     presentation.right_margin = margin(PAGE_RIGHT_MARGIN)
     presentation.page_width = self._page_layout.get(PAGE_WIDTH)
     presentation.page_height = self._page_layout.get(PAGE_HEIGHT)
     presentation.landscape = self._page_layout.get(PAGE_LANDSCAPE_MODE)
     start_time_export = pytis.data.DateTime.now()
     exporter = lcg.pdf.PDFExporter(translations=self._translations)
     presentation_args = (self._style or [])
     presentation_set = lcg.PresentationSet(presentation_args)
     context = exporter.context(lcg_content, self._language, presentation=presentation_set)
     try:
         pdf = exporter.export(context, global_presentation=presentation)
     except lcg.SubstitutionIterator.IteratorError, e:
         message = _("Invalid use of iterator.\n"
                     "Maybe you refer to an non-existent or inaccessible object in the table?")
         message += "\n" + unicode(e)
         pytis.form.run_dialog(pytis.form.Error, message)
         return ''
Esempio n. 3
0
 def _lcg(self):
     if self._family == self.PROPORTIONAL:
         family = lcg.FontFamily.PROPORTIONAL
     elif self._family == self.SANS_SERIF:
         family = lcg.FontFamily.SANS_SERIF
     elif self._family == self.FIXED_WIDTH:
         family = lcg.FontFamily.FIXED_WIDTH
     return lcg.Container(self._lcg_contents(),
                          presentation=lcg.Presentation(font_family=family))
Esempio n. 4
0
 def _lcg(self):
     presentation = lcg.Presentation()
     if self.arg_boxed:
         presentation.boxed = True
         presentation.box_margin = self.arg_box_margin
     if self.arg_vertical:
         orientation = lcg.Orientation.VERTICAL
     else:
         orientation = lcg.Orientation.HORIZONTAL
     return lcg.Container(self._lcg_contents(), orientation=orientation,
                          presentation=presentation,
                          halign=lcg.HorizontalAlignment.LEFT,
                          valign=lcg.VerticalAlignment.TOP)
Esempio n. 5
0
File: misc.py Progetto: cerha/pytis
 def body(self):
     spec = self._parameter(pytis.output.P_NAME)
     row = self._parameter((spec, pytis.output.P_ROW,))
     p = pytis.output.Paragraph(u"Price of %s is %s." %
                                (row['product'].value(),
                                 row['price'].value(),))
     presentation = lcg.Presentation()
     presentation.noindent = True
     doc = pytis.output.Document(pytis.output.Group(pytis.output.VSpace(10), p, vertical=True),
                                 page_header=self.page_header(),
                                 page_footer=self.page_footer(),
                                 page_background=self.page_background(),
                                 presentation={None: presentation})
     return [doc]
Esempio n. 6
0
File: lcgmake.py Progetto: cerha/lcg
def read_presentation(filename):
    presentation = lcg.Presentation()
    import importlib.util
    try:
        spec = importlib.util.spec_from_file_location('_lcg_presentation',
                                                      filename)
        mod = importlib.util.module_from_spec(spec)
        spec.loader.exec_module(mod)
    except Exception as e:
        die("Can't process presentation file: %s" % (e, ))
    for o in dir(mod):
        if o[0] in string.ascii_lowercase and hasattr(presentation, o):
            setattr(presentation, o, mod.__dict__[o])
    return lcg.PresentationSet(((
        presentation,
        lcg.TopLevelMatcher(),
    ), ))
Esempio n. 7
0
    def _lcg(self):
        def coalesce(a, b):
            return a if a is not None else b

        padding = self.arg_padding
        if padding is not None:
            if not isinstance(padding, (tuple, list)):
                padding = (padding, padding, padding, padding)
            elif len(padding) == 2:
                padding = (padding[0], padding[1], padding[0], padding[1])
            padding = [
                self._dimension(coalesce(x, y))
                for x, y in zip((self.arg_padding_top, self.arg_padding_right,
                                 self.arg_padding_bottom,
                                 self.arg_padding_left), padding)
            ]
        presentation = dict(
            font_color=_color(self.arg_color),
            background_color=_color(self.arg_background),
        )
        if self.arg_boxed:
            presentation.update(
                boxed=True,
                box_margin=self._dimension(self.arg_box_margin),
                box_radius=self._dimension(self.arg_box_radius),
                box_width=self._dimension(self.arg_box_width),
                box_color=_color(self.arg_box_color),
                box_mask=self.arg_box_mask,
            )
        contents = self._lcg_contents()
        orientation = self._orientation()
        if self.arg_spacing:
            if orientation == VERTICAL:
                space = [VSpace(self.arg_spacing).lcg()]
            else:
                space = [HSpace(self.arg_spacing).lcg()]
            contents = reduce(lambda a, b: a + space + [b], contents[1:],
                              contents[0:1])
        return lcg.Container(contents,
                             orientation=orientation,
                             width=self._dimension(self.arg_width),
                             height=self._dimension(self.arg_height),
                             padding=padding,
                             presentation=lcg.Presentation(**presentation),
                             halign=self.arg_halign,
                             valign=self.arg_valign)
Esempio n. 8
0
 def _lcg(self):
     presentation = lcg.Presentation()
     presentation.font_size = self._size
     return lcg.Container(self._lcg_contents(), presentation=presentation)
Esempio n. 9
0
 def _lcg(self):
     presentation = lcg.Presentation()
     presentation.bold = presentation.italic = False
     return lcg.Container(self._lcg_contents(), presentation=presentation)
Esempio n. 10
0
    def _pdf(self):
        start_time = pytis.data.DateTime.now()
        T = pytis.data.DBTransactionDefault
        transaction = T(connection_data=pytis.config.dbconnection,
                        isolation=T.REPEATABLE_READ)
        template_nodes = []
        if self._form is not None and self._row_template is not None:
            i = 1
            row_template = self._row_template
            for row in self._form.presented_rows():
                row_lcg_globals = self._LCGGlobals(self._resolver,
                                                   self._form,
                                                   self._form_bindings,
                                                   self._codebooks,
                                                   transaction,
                                                   current_row=row,
                                                   parameters=self._parameters)
                id_ = 'pytissubdoc%d' % (i, )
                row_template_lcg = row_template.lcg()
                parameters = self._template_parameters(row_template)
                document = lcg.ContentNode(
                    id=id_,
                    title=' ',  # let's avoid printing the id
                    content=row_template_lcg,
                    globals=row_lcg_globals,
                    **parameters)
                template_nodes.append(document)
                i += 1
        lcg_globals = self._LCGGlobals(self._resolver,
                                       self._form,
                                       self._form_bindings,
                                       self._codebooks,
                                       transaction,
                                       parameters=self._parameters)
        lcg_globals['app'] = self._application_variables

        def margin(key):
            size = self._page_layout.get(key)
            if size is None:
                size = UMm(10)
            return size

        presentation = lcg.Presentation(
            font_name='DejaVu',
            font_family=lcg.FontFamily.FIXED_WIDTH,
            top_margin=margin(PAGE_TOP_MARGIN),
            bottom_margin=margin(PAGE_BOTTOM_MARGIN),
            left_margin=margin(PAGE_LEFT_MARGIN),
            right_margin=margin(PAGE_RIGHT_MARGIN),
            page_width=self._page_layout.get(PAGE_WIDTH),
            page_height=self._page_layout.get(PAGE_HEIGHT),
            landscape=self._page_layout.get(PAGE_LANDSCAPE_MODE),
        )
        start_time_export = pytis.data.DateTime.now()
        exporter = lcg.pdf.PDFExporter(translations=self._translations)
        body = xtuple(self._body) if self._body else ()
        body_nodes = [doc.lcg_document(globals=lcg_globals) for doc in body]
        root_node = lcg.ContentNode(id='__dummy',
                                    content=lcg.Content(),
                                    children=body_nodes + template_nodes,
                                    **self._body_parameters)
        context = exporter.context(root_node,
                                   self._language,
                                   presentation=lcg.PresentationSet(self._style
                                                                    or []))
        try:
            pdf = exporter.export(context, global_presentation=presentation)
        except lcg.SubstitutionIterator.IteratorError as e:
            message = _(
                "Invalid use of iterator.\n"
                "Maybe you refer to an non-existent or inaccessible object in the table?"
            )
            message += "\n" + unistr(e)
            pytis.form.run_dialog(pytis.form.Error, message)
            return ''
        show_time = pytis.data.DateTime.now()
        log(EVENT, ('Output formatting took %.3fs (PDF export %.3fs)' % (
            pytis.data.DateTime.diff_seconds(start_time, show_time),
            pytis.data.DateTime.diff_seconds(start_time_export, show_time),
        )))
        try:
            transaction.commit()
        except pytis.data.DBSystemException:
            pass
        return pdf
Esempio n. 11
0
 def _lcg_presentation(self):
     if self._vmargin == 0:
         margin = lcg.UMm(0)
     else:
         margin = lcg.UFont(0.2)
     return lcg.Presentation(separator_margin=margin)
Esempio n. 12
0
 def _lcg(self):
     return lcg.Container(
         self._lcg_contents(),
         presentation=lcg.Presentation(font_size=self._size))
Esempio n. 13
0
 def _lcg(self):
     return lcg.Container(self._lcg_contents(),
                          presentation=lcg.Presentation(italic=False))
Esempio n. 14
0
 def _lcg(self):
     return lcg.Container(self._lcg_contents(),
                          presentation=lcg.Presentation(bold=True))