Esempio n. 1
0
            self.chart.strands[0].fillColor  = color01
            self.chart.strands[1].fillColor  = color02
            #self.chart.strands.strokeWidth   = 1
            #self.chart.strandLabels.fontName = 'Helvetica'
            #self.chart.strandLabels.fontSize = 6
            #self.chart.fillColor             = backgroundGrey

            self.chart.data                  = [ideal_values, real_values]
            self.chart.labels                = domains

            self._add(self,Legend(),name='Legend',validate=None,desc="The legend or key for the chart")
            self.Legend.colorNamePairs = [(color01, 'Ideal Value'), (color02, 'Real Value')]
            self.Legend.fontName       = 'Helvetica'
            self.Legend.fontSize       = 7
            # placing Legend on the top-left of the graphic
            self.Legend.x              = 0
            self.Legend.y              = self.chart.y + self.chart.height
            self.Legend.dxTextSpace    = 5
            self.Legend.dy             = 5
            self.Legend.dx             = 5
            self.Legend.deltay         = 5
            self.Legend.alignment      ='right'

            self.chart.strands.strokeWidth     = 1
            self.chart.spokes.strokeDashArray = (1,1)       ## Dotted lines
            self._add(self,0,name='preview',validate=None,desc=None)

    return RadarChart(**attrs)

register_tag('spider', spider_parser)
Esempio n. 2
0
    def draw(self):
        pos = 1
        for n in range(0, self.number):
            self.canv.rect(x=pos,y=1,width=self.width,height=self.height)
            pos += self.width + (2*self.space)


def radio_button_parser(fobj, node, extra_style=None):
    """
    RadioButton parser

    :param fobj: report.render.rml2pdf.trml2pdf._rml_flowable instance
    :param node: etree.Element instance, describing the rml current node
    """
    _cb_data = fobj._textual(node)
    attrs =  utils.attr_get(node,
                    ['x', 'y', 'size', 'number', 'context', 'space'],
                    {
                        'x' :'int',
                        'y' :'int',
                        'size': 'int',
                        'number': 'int',
                        'space': 'int'
                    })
    if 'context' not in attrs and _cb_data:
        attrs['context'] = _cb_data
    return RadioButton(**attrs)

register_tag('radioButton', radio_button_parser)

Esempio n. 3
0
    def draw(self):
        self.canv.saveState()
        self.canv.setStrokeColor(self.bordercolor)
        self.canv.rect(x=1,y=1,width=self.width,height=self.height)
        if self.checked:
            self.canv.setStrokeColor(self.color)
            self.canv.line(2, 2, self.width, self.height)
            self.canv.line(2, self.height, self.width, 2)
        self.canv.restoreState()

def checkbox_parser(fobj, node, extra_style=None):
    _cb_data = fobj._textual(node)
    attrs =  utils.attr_get(node,
                        ['x','y','size','context', 'checked',
                         'color', 'bordercolor'],
                        {
                            'x': 'int',
                            'y': 'int',
                            'size': 'int',
                            'checked': 'bool',
                            'color': 'str',
                            'bordercolor': 'str',
                        })
    # XXX rename variable: context is unicode string containing text node content inside checkbox
    if 'context' not in attrs and _cb_data:
        attrs['context'] = _cb_data
    attrs['localcontext'] = fobj.localcontext
    return CheckBox(**attrs)

register_tag('CheckBox', checkbox_parser)
Esempio n. 4
0
# -*- coding: utf-8 -*-
# Copyright 2011 Thamini S.à.R.L    This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

import base64
import cStringIO
from reportlab import platypus
from reportlab.lib.utils import ImageReader
from base_rml2pdf_extra_tags.trml2pdf_interface import register_tag

class ImageInline(platypus.Flowable):
    def __init__(self, img, width=-1, height=-1):
        platypus.Flowable.__init__(self)
        if img:
            imgdata = base64.decodestring(img)
            imgfile = cStringIO.StringIO(imgdata)
            self.img = ImageReader(imgfile)
            self.width, self.height = self.img.getSize()
        else:
            self.img = False

    def draw(self):
        if self.img:
            self.canv.drawImage(self.img, 0, 0, self.width, self.height)

def imageinline_parser(fobj, node, extra_style=None):
    _imagedata = fobj._textual(node)
    return ImageInline(_imagedata)

register_tag('imageinline', imageinline_parser)
Esempio n. 5
0
# -*- coding: utf-8 -*-
# Copyright 2011 Thamini S.à.R.L    This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

from reportlab import platypus
from report.render.rml2pdf.trml2pdf import utils
from base_rml2pdf_extra_tags.trml2pdf_interface import register_tag

class ParagraphNoWrap(platypus.Paragraph):
    def wrap(self, availableWidth, availableHeight):
        para_wrap = platypus.Paragraph.wrap(self, availableWidth, availableHeight)
        # fake null size
        self.height = 0
        self.width = 0
        # return real right
        return (para_wrap[0], para_wrap[1])


def paranowrap_parser(fobj, node, extra_style=None):
    style = fobj.styles.para_style_get(node)
    if extra_style:
        style.__dict__.update(extra_style)
    result = []
    text = fobj._textual(node).replace('\n','<br/>')
    attrs = utils.attr_get(node, [], {'bulletText':'str'})
    result.append(ParagraphNoWrap(text, style, **attrs))
    return result

register_tag('para-nowrap', paranowrap_parser)
Esempio n. 6
0
# -*- coding: utf-8 -*-
# Copyright 2011 Thamini S.à.R.L    This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

from tag_barchart_internal import Barchart
from report.render.rml2pdf import utils
from base_rml2pdf_extra_tags.trml2pdf_interface import register_tag

def barchart_parser(fobj, node, extra_style=None):
    attrs = utils.attr_get(node,
                ['width', 'height', 'orientation', 'fontName',
                 'fontSize', 'xticks', 'yticks', 'legend_display',
                 'stacked', 'flip_barlabel'],
                {
                    'width': 'int',
                    'height': 'int',
                    'orientation': 'str',
                    'fontName': 'str',
                    'fontSize': 'int',
                    'xticks': 'int',
                    'yticks': 'int',
                    'legend_display': 'str',
                    'stacked': 'bool',
                    'valueMax': 'float',
                    'flip_barlabel': 'bool'
                })
    datas = eval(fobj._textual(node))
    return [ Barchart(datas, **attrs) ]

register_tag('barchart', barchart_parser)
Esempio n. 7
0
        self.barcode.save(bc_buf, format='JPEG', quality=95, optimize=True)
        bc_buf.seek(0)
        bc_img = ImageReader(bc_buf)
        (bc_imgx, bc_imgy) = bc_img.getSize()
        self.canv.drawImage(bc_img, self.x, self.y)

        self.canv.restoreState()

    def wrap(self, availableWidth, availableHeight):
        if self.absolutePos:
            # fake size as we won't be display in place where we are.
            return (0,0)
        return self.barcode.size

def qrbarcode_parser(fobj, node, extra_style=None):
    attrs = utils.attr_get(node,
                    ['version', 'eclevel', 'x', 'y','appendPageNumber',
                     'absolutePos', 'model'],
                    {
                        'version': 'int',
                        'eclevel': 'int',
                        'appendPageNumber': 'bool',
                        'absolutePos': 'bool',
                        'model': 'str',
                    })
    attrs['text'] = fobj._textual(node)
    attrs['localcontext'] = fobj.localcontext
    return QrBarcode(**attrs)

register_tag('qrBarCode', qrbarcode_parser)