Beispiel #1
0
    def __init__(self,
                 x=None,
                 y=None,
                 w=None,
                 h=None,
                 name=None,
                 template=None,
                 fill=None,
                 stroke=None,
                 strokeWidth=0,
                 pt=None,
                 pr=None,
                 pb=None,
                 pl=None):
        self.x = x or 0  # (x, y) position of the element from bottom left of parent.
        self.y = y or 0
        self.w = w  # Width and height of the element bounding box
        self.h = h
        self.fill = color(fill)  # Default is drawing a black rectangle.
        self.stroke = color(stroke)  # Default is drawing no stroke frame
        self.strokeWidth = strokeWidth
        self.padding = pt, pr, pb, pl  # Initialize the padding
        self.elements = []  # Storage in case there are child elements

        # Optional name, e.g. for template or element finding. Defaults to class name.
        self.name = name or self.__class__.__name__
        self.template = template  # Optional template function for this element.

        # Allow elements, pages and templates to initialize themselves
        # by implementing the self.initialize method.
        self.initialize()
Beispiel #2
0
    def textColor(self, base, shade):
        """Answer the shade of base color that words best as text foreground
        on the `shade` color.

        >>> from pagebotnano.themes import BackToTheCity
        >>> theme = BackToTheCity()
        >>> theme.textColor(3, 0).name
        'black'
        """
        c = self.colors[base][shade]
        if c.averageRgb < 0.4:
            return color(1)
        return color(0)
Beispiel #3
0
class IntoTheWoods(BaseTheme):
    """The IntoTheWoods theme is ...

    >>> theme = IntoTheWoods()
    """

    NAME = 'Into the Woods'
    THEME_COLORS = dict(
        # Example logo colors, to be modified by an inheriting class.
        logo1=spotColor(300),
        logo2=color(1, 0, 0),
        logo3=color(0, 1, 0),
        # Theme colors
        main=spotColor('gray10u'),
        accent=spotColor(348),
        alt1=spotColor(376),
        alt2=spotColor(381),
        support1=spotColor(392), 
        support2=spotColor(398),
    )
class HappyHolidays(BaseTheme):
    NAME = 'Happy Holidays'
    BASE_COLORS = dict(
        base0=color(1, 0, 0.2),
        base1=color(0.7, 0.1, 0.2),
        base2=color(0.9, 0, 0.3),
        base3=color(0.5, 0.96, 0.2),
        base4=color(0, 1, 0),
        base5=color(0.55, 0.5, 0.5),
    )
Beispiel #5
0
class HappyHolidays(BaseTheme):
    NAME = 'Happy Holidays'
    THEME_COLORS = dict(
        # Example logo colors, to be modified by an inheriting class.
        logo1=color(1, 0, 0),
        #logo2
        #logo3
        main=color(1, 0, 0.2),
        accent=color(0.7, 0.1, 0.2),
        alt1=color(0.9, 0, 0.3),
        alt2=color(0.5, 0.96, 0.2),
        support1=color(0, 1, 0),
        support2=color(0.55, 0.5, 0.5),
    )
    def fill(self, c):
        """Set the fill mode of the context. `c` can be None, a number,
        a name or a Color instance. 

        >>> context = DrawBotContext()
        >>> context.fill(None)
        >>> context.fill('red')
        >>> context.fill((1, 0, 0))
        >>> context.fill(Color(1, 0, 0))
        >>> context.fill(0.5)
        """
        if c is None:
            drawBot.fill(None)
        else: # Make sure is it a Color instance.
            if not isinstance(c, Color):
                c = color(c)
            r, g, b, a = c.rgba
            drawBot.fill(r, g, b, a)
    def stroke(self, c, strokeWidth=None):
        """Set the stroke mode of the context. `c` can be None, a number,
        a name or a Color instance. 

        >>> context = DrawBotContext()
        >>> context.stroke(None)
        >>> context.stroke('red')
        >>> context.stroke((1, 0, 0))
        >>> context.stroke(Color(1, 0, 0))
        >>> context.stroke(0.5, 1)
        """
        if strokeWidth is not None:
            self.strokeWidth(strokeWidth)
        if c is None:
            drawBot.stroke(None)
        else: # Make sure it is a Color instance.
            if not isinstance(c, Color):
                c = color(c)
            r, g, b, a = c.rgba
            drawBot.stroke(r, g, b, a)
Beispiel #8
0
            tw, th = bs.textSize
            e = Text(bs, x=page.pl + page.pw, y=page.pb - th, w=page.pw)
            page.addElement(e)

    doc.export('_export/ThemeSpecimen-%s.%s' % (fileName, extension),
               multipage=True)


layoutDatas = (
    # Page size, filename, layout, labelColor, labels
    ((W, H), TITLE_SIZE, OVERLAY, OVERLAY, None, (
        HEX,
        NAME,
        RGB,
        SPOT,
        CMYK,
    ), 'pdf'),
    ((W, H), TITLE_SIZE, SPOTSAMPLE + '1', SPOTSAMPLE, color(0),
     (HEX, NAME, SPOT), 'pdf'),
    ((A5[1], A5[0]), TITLE_SIZE, SPOTSAMPLE + '-A5', SPOTSAMPLE, color(0),
     (HEX, ), 'pdf'),
    ((A5[1], A5[0] * 2 / 3), TITLE_SIZE, OVERLAY + '-A5ish', SPOTSAMPLE,
     color(0), (HEX, ), 'pdf'),
    ((2160, 2160), TITLE_SIZE * 3.6, OVERLAY + '-Instagram', SPOTSAMPLE,
     color(0), (HEX, ), 'jpg'),
)

for layoutData in layoutDatas:
    makeColorSpecimen(layoutData)

print('Done')
Beispiel #9
0
            tw, th = bs.textSize
            e = Text(bs, x=page.pl + page.pw, y=page.pb - th, w=page.pw)
            page.addElement(e)

    if not isinstance(extensions, (list, tuple)):
        extensions = [extensions]
    for extension in extensions:
        filePath = '_export/ThemeSpecimen-%s.%s' % (fileName, extension)
        print('Exporting', filePath)
        doc.export(filePath, multipage=True)


layoutDatas = (
    # Page size, filename, layout, labelColor, labels
    ((W, W), TITLE_SIZE, TITLE_SIZE * 0.6, OVERLAY, OVERLAY, None,
     (HEX, NAME, RGB, CMYK, CELL, BASE), 'pdf'),
    ((W, W), TITLE_SIZE, TITLE_SIZE * 0.4, SPOTSAMPLE + '1', SPOTSAMPLE,
     color(0), (HEX, NAME, SPOT, ROWCOL, CELL, BASE), 'pdf'),
    ((A5[1], A5[0]), TITLE_SIZE, TITLE_SIZE * 0.2, SPOTSAMPLE + '-A5',
     SPOTSAMPLE, color(0), (HEX, BASE), 'pdf'),
    ((A5[1], A5[0] * 2 / 3), TITLE_SIZE, TITLE_SIZE * 0.2, OVERLAY + '-A5ish',
     SPOTSAMPLE, color(0), (HEX, BASE), 'pdf'),
    ((2160, 2160), TITLE_SIZE * 3.6, TITLE_SIZE * 3.6 * 0.3,
     OVERLAY + '-Instagram', SPOTSAMPLE, color(0), (HEX, BASE), ('jpg',
                                                                 'pdf')),
)

for layoutData in layoutDatas:
    makeColorSpecimen(layoutData)

print('Done 020')