Example #1
0
def createSlideLayout():
    from beampy.modules.svg import rectangle
    from beampy.modules.core import group
    from beampy.modules.text import text
    from beampy.modules.figure import figure
    from beampy.document import document

    # Upper part
    with group(y=0, background=khaki, height=30, width='100%') as g1:
        text(r'\textsc{LABORATÓRIO DE ENGENHARIA BIOMÉDICA}',
             x=390,
             y='center',
             color='#ffffff',
             size=12)

    # Lower part
    with group(x=0, y=550, height=50, width=800) as g2:
        with group(x=g2.left + 10, y=g2.top - 8) as g3:
            figure('./figures/usp-logo-eps.jpg', width=50)
        with group(x=0, y=20, height=10, width=800) as g5:
            rectangle(y=0, color=rawUmber, height=5, edgecolor=rawUmber)
            rectangle(y=5, color=khaki, height=5, edgecolor=khaki)
        with group(x=g3.right + 690, y=g2.top + 2) as g4:
            figure('./figures/EP.jpg', width=40)

        # Counting slides and displaying them
        numSlides = len(document._slides)
        curSlide = int(document._curentslide.split('_')[1]) + 1
        text('%i/%i' % (curSlide, numSlides), x=12, y=32, size=10)
Example #2
0
def grid(dx, dy, **kwargs):
    """
    Create a grid with a given spacing.

    Parameters
    ----------

    Accept all arguments of :py:mod:`beampy.line`

    See Also
    --------

    :py:mod:`beampy.line`

    """

    assert dx > 0
    assert dy > 0

    with group(x=0, y=0, width=document._width, height=document._height) as g:
        # create horizontal line
        cur_x = 0
        while (cur_x <= document._height):
            hline('%spx' % cur_x, **kwargs)
            cur_x += dx

        cur_y = 0
        while (cur_y <= document._width):
            vline('%spx' % cur_y, **kwargs)
            cur_y += dy

    return g
Example #3
0
def hipstertitle(titlein, author= None, subtitle = None, date= None):

    
    args = THEME['maketitle']
    
    #TODO: the rectangle with a raw svg command
    tikz(r'\draw[fill={color}, line width=1.5pt] (0,0) rectangle (100,100);'.format(color=args['background-color']),
     x=0, y=0)

    with group(x=0.015, y='center', width=document._width-document._width*0.015):

        text(r"{\scshape %s}"%(titlein), x= 0, width=document._width*0.9, 
        y=0, color=args['title_color'], size=args['title_size'], 
        align='left')

        #TODO: the line with a raw svg command not tikz
        tikz(r'\draw[color={color}, line width=1.5pt] (0,0) -- ++ (800,0);'.format(color=args['title_color']),
         x=0, y='+0.2cm')

        if author != None :
            a = text(author, x=0, y="+0.6cm", color=args['author_color'],
            size=args['author_size'], align='left', width=document._width*0.45)

        if subtitle != None:
            st = text(r"\textit{%s}"%(subtitle), x={"align":'right', 'shift':0.02},
                 y=a.bottom+{"align":"bottom", "shift":0},
                 color=args['subtitle_color'], size=args['subtitle_size'],
                 width=document._width*0.45, align='left')

    if date != None:
        text(date, x='center', y={"align":'bottom', 'shift':0.05},
        color=args['date_color'], size=args['date_size'])
Example #4
0
def default_maketitle(titlein,
                      author=None,
                      subtitle=None,
                      date=None,
                      title_width=None,
                      vert_space=None):

    args = document._theme['maketitle']

    if date in ('Today', 'today', 'now'):
        date = datetime.datetime.now().strftime("%d/%m/%Y")

    if title_width is None:
        title_width = document._theme['document']['width'] * 0.75

    if vert_space is None:
        vert_space = document._theme['document']['height'] * 0.05

    with group(y='center'):

        text(titlein,
             width=title_width,
             y=0,
             color=args['title_color'],
             size=args['title_size'],
             align='center')

        if author is not None:
            if isinstance(author, str):
                text(author,
                     width=title_width,
                     y="+" + str(2 * vert_space),
                     color=args['author_color'],
                     size=args['author_size'],
                     align='center')

            elif isinstance(author, list):
                text(', '.join(author),
                     width=title_width,
                     y="+" + str(vert_space),
                     color=args['author_color'],
                     size=args['author_size'],
                     align='center')

        if subtitle is not None:
            text(subtitle,
                 width=title_width,
                 y="+" + str(vert_space),
                 color=args['subtitle_color'],
                 size=args['subtitle_size'])

        if date is not None:
            text(date,
                 width=title_width,
                 y="+" + str(vert_space),
                 color=args['date_color'],
                 size=args['date_size'])
Example #5
0
def createMakeTitle(titlein, author=[]):
    from beampy.modules.svg import rectangle
    from beampy.modules.core import group
    from beampy.modules.text import text
    from beampy.modules.figure import figure
    from beampy.document import document

    # Main maketitle text elements
    args = THEME['maketitle']

    rectangle(x=0,
              y=0,
              width=document._width,
              height=document._height,
              color=args['background-color'],
              edgecolor=None)

    with group(x=10, y='center', width='70%') as g6:
        text(titlein, y=0, color=args['title_color'], size=args['title_size'])
        text(author,
             x=g6.left + 10,
             y="+1.5cm",
             color=args['author_color'],
             size=args['author_size'])
        text('Orientador: André Fabio Kohn',
             x=g6.left + 10,
             y="+0.5cm",
             color=args['author_color'],
             size=args['author_size'])

    # Upper part
    with group(y=0, background=khaki, height=100, width='100%') as g1:
        text(r'\textsc{LABORATÓRIO DE ENGENHARIA BIOMÉDICA}',
             x=390,
             y='center',
             color='#ffffff',
             size=12)

    # Lower part
    with group(x=0, y=550, height=50, width=800) as g2:
        with group(x=g2.left + 10, y=g2.top - 8) as g3:
            figure('./figures/usp-logo-eps.jpg', width=50)
        with group(x=g2.left + 70, y=g2.top + 8) as g6:
            text(
                'Escola Politécnica da Universidade de São Paulo - 2 de julho de 2019',
                size=10,
                color='#888888')
        with group(x=0, y=20, height=10, width=800) as g5:
            rectangle(y=0, color=rawUmber, height=5, edgecolor=rawUmber)
            rectangle(y=5, color=khaki, height=5, edgecolor=khaki)
        with group(x=g3.right + 690, y=g2.top + 2) as g4:
            figure('./figures/EP.jpg', width=40)
Example #6
0
def itemize(items_list, **kwargs):
    '''

	Generates a list or an enumeration.

	See THEME['itemize'] for option

	TODO: ADD doc for function arguments
	'''

    args = check_function_args(itemize, kwargs)
    number = 1

    if args['width'] != None:
        in_width = float(convert_unit(args['width'])) - float(
            convert_unit(args['item_indent']))
    else:
        in_width = float(document._width) - float(
            convert_unit(args['item_indent']))

    with group(width=args['width'], x=args['x'], y=args['y']):

        for i, the_item in enumerate(items_list):

            if args['item_style'] == 'bullet':
                item_char = r'$\bullet$'

            elif args['item_style'] == 'number':
                item_char = str(number) + r'.'
                number += 1

            else:
                item_char = args['item_style']

            # Add color

            item_char = color_text(item_char, args['item_color'])
            the_item = color_text(the_item, args['text_color'])

            if i == 0:
                text(item_char + r' ' + the_item,
                     x=args['item_indent'],
                     y=0,
                     width=in_width)
            else:
                text(item_char + r' ' + the_item,
                     x=args['item_indent'],
                     y=args['item_spacing'],
                     width=in_width)
Example #7
0
def theme_maketitle(titlein, author = [], affiliation = None, meeting = None, lead_author = None, date=None ):
    """
        Function to create the presentation title slide
    """

    # get_command_line(maketitle)
    # Check function arguments from THEME
    args = THEME['maketitle']

    if lead_author is not None and len(author) > lead_author:
        print('Color author: %s in %s' % (author[lead_author],
                                          args['lead_author_color']))
        
        author[lead_author] = color_text(author[lead_author],
                                         args['lead_author_color'])
        
    author_string = '\hspace{0.7cm} '.join(author)

    if date in ('Today', 'today', 'now'):
        date = datetime.datetime.now().strftime("%d/%m/%Y")

    if isinstance(affiliation, list):
        affiliation = r'\\'.join(affiliation)
        
    with group(y="center"):

        with box(width='85%', y=0, auto_height_margin=20, background_color=lead_color) as tg:
            text(titlein, color=args['title_color'],
                 size=args['title_size'], align='center',
                 y=0, x='center', width='90%')

        if len(author) > 0:
            text(author_string, width='80%', y=tg.bottom+"1.5cm",
                 color=args['author_color'], size=args['author_size'],
                 align='center')

        if affiliation is not None:
            text(affiliation, width='90%', y="+1cm",
                 color=args['affiliation_color'], size=args['affiliation_size'],
                 align='center')

        if meeting is not None:
            text(meeting, width='90%', y="+1cm",
                 color=args['meeting_color'], size=args['subtitle_size'],
                 align='center')

        if date is not None:
            text(date, width=750, y="+1cm", color=args['date_color'],
                 size=args['date_size'])
Example #8
0
def itemize( items_list, **kwargs):

	'''

	Generates a list or an enumeration.

	See THEME['itemize'] for option

	TODO: ADD doc for function arguments
	'''

	args = check_function_args(itemize, kwargs)
	number = 1

	if args['width']!=None:
		in_width = float(convert_unit(args['width'])) - float(convert_unit(args['item_indent']))
	else:
		in_width = float(document._width) - float(convert_unit(args['item_indent']))

	with group(width=args['width'], x=args['x'], y=args['y']):

		for i, the_item in enumerate(items_list) :

			if args['item_style'] == 'bullet' :
				item_char = r'$\bullet$'

			elif args['item_style'] == 'number' :
				item_char = str(number) + r'.'
				number += 1

			else :
				item_char = item_style

			# Add color

			item_char = color_text( item_char, args['item_color'] )
			the_item = color_text( the_item, args['text_color'] )

			if i == 0 :
				text( item_char + r' ' + the_item, x = args['item_indent'],
				y = 0, width=in_width )
			else:
				text( item_char + r' ' + the_item, x = args['item_indent'],
				y = args['item_spacing'], width=in_width )
Example #9
0
def hipstertitle(titlein, author=None, subtitle=None, date=None):

    args = THEME['maketitle']

    rectangle(x=0,
              y=0,
              width=document._width,
              height=document._height,
              color=args['background-color'],
              edgecolor=None)

    with group(x=0.015,
               y='center',
               width=document._width - document._width * 0.015):

        t = text(r"{\scshape %s}" % (titlein),
                 x=0,
                 width=document._width * 0.9,
                 y=0,
                 color=args['title_color'],
                 size=args['title_size'],
                 align='left')

        hl = hline(y=t.bottom + "0.2cm",
                   color=args['title_color'],
                   linewidth='1.5pt')

        if author is not None:
            a = text(author,
                     x=0,
                     y=hl.bottom + 20,
                     color=args['author_color'],
                     size=args['author_size'],
                     align='left',
                     width=document._width * 0.45)

        if subtitle is not None:
            st = text(r"\textit{%s}" % (subtitle),
                      x={
                          "align": 'right',
                          'shift': 0.02,
                          'anchor': 'right'
                      },
                      y=hl.bottom + {
                          "anchor": "top",
                          "shift": 20
                      },
                      color=args['subtitle_color'],
                      size=args['subtitle_size'],
                      width=document._width * 0.45,
                      align='left')

    if date is not None:
        text(date,
             x='center',
             y={
                 "align": 'bottom',
                 'shift': 0.05
             },
             color=args['date_color'],
             size=args['date_size'])
Example #10
0
def create_header_bar():

    if len(document._TOC) == 0:
        bluerect = rectangle(x=0, y=0, height=28*1.6,
                             color=lead_color, edgecolor=lead_color)
        bluerect.first()
        # BUG Change the position of the title as we don't have the header bar
        print('No table of content, their is a bug to set the position of the title dynamically in BeamerFrankfurt Theme')
        print('''Please add in your file after doc = document
        doc._theme['title']['y'] -= 35
        doc._theme['title']['reserved_y'] = '1.8cm'
        ''')
        
    else:
        rtop = rectangle(x=0, y=0, height=35, color='black', edgecolor='black')
        bluerect = rectangle(x=0, y=rtop.bottom+0, height=28*1.6,
                             color=lead_color, edgecolor=lead_color)
        bluerect.first()
        
        cpt_title = 0
        cur_toc = document._slides[document._curentslide].TOCposition
        visibles_toc_pos = get_visibles_indices(document._curentslide,
                                                currentsection=True)
        last_pos = document._TOC.index(cur_toc)
        last_level1_pos = 0
        
        for i, toc in enumerate(document._TOC):
            if toc['level'] == 0:
                cpt_title += 1
            if toc['level'] == 1:
                if i in visibles_toc_pos and i <= last_pos:
                    last_level1_pos = i
        
        group_width = None
        groups = [] # store group with toc title and subtitle circle
        elems = []
        for i, toc in enumerate(document._TOC):
            if i in visibles_toc_pos and i <= last_pos:
                selected_opacity = 1
            else:
                selected_opacity = 0.5
        
            if i == last_level1_pos:
                circle_color = 'white'
            else:
                circle_color = 'black'
        
            if toc['slide'] <= document._global_counter['slide']:
                slidelink = '#%i-0' % (toc['slide'])
            else:
                slidelink = '#%i-0' % (document._global_counter['slide'])
        
            if toc['level'] == 0:
                if len(elems) > 0:
                    g = group(elems, x=0, y=5, width=group_width)
                    groups += [g]
                    elems = []
                
                t1 = text(r'\href{%s}{%s}' % (slidelink, toc['title']), x=0,
                          y=0, size=10, color='white',
                          opacity=selected_opacity, width=group_width)
                elems += [t1]
                t2 = None
                
            if toc['level'] == 1:
                if t2 is None:
                    xt = 2
                else:
                    xt = t2.right+2
                    
                t2 = circle(x=xt, y=t1.top+15, color=circle_color,
                            edgecolor='white', opacity=selected_opacity)
                elems += [t2]
                
        if len(elems) > 0:
            g = group(elems, x=0, y=0, width=group_width)
            groups += [ g ]
        
        # Compute the horizontal position for groups
        # The first element at the same x than the title
        groups[0].positionner.update_x(THEME['title']['x'])
        # groups[0].positionner.update_y((rtop.height-groups[0].height)/2)
        # The last element with the same margin as the first element 
        groups[-1].positionner.update_x(document._width-(groups[-1].width+THEME['title']['x']).value)
        groups[-1].positionner.update_y(groups[0].top+0)
        #Compute the available width
        available_width = document._width - (groups[-1].width+THEME['title']['x']).value
        
        for e in groups[1:-1]:
            e.positionner.update_y(groups[0].top+0)
            if e.width.value is None or e.height.value is None:
                e.width.run_render()
                
        if len(groups) > 2:
            distribute(groups[1:-1], 'hspace', available_width,
                       offset=(groups[0].width+THEME['title']['x']).value)
Example #11
0
def itemize(items_list, **kwargs):
    '''
    Generates a list or an enumeration.

    Parameters
    ----------

    items_list : list of str
        List of item sentences.

    x : int or float or {'center', 'auto'} or str, optional
        Horizontal position for the item list (the default is 'center'). See
        positioning system of Beampy.

    y : int or float or {'center', 'auto'} or str, optional
        Vertical position for the item list (the default is 'auto'). See
        positioning system of Beampy.

    width : int or float or None, optional
       Width of the group containing items (the default is None, which implies
       that the width is computed to fit the longest item width).

    item_style : {'bullet','number'} or str, optional
        Style of the item markers (the default theme sets this value to
        'bullet', which implies that item marker decorator is a bullet). The
        bullet could be replaced by any string, including latex symbols. When
        `item_style`='number', the item makers is an increasing number to
        create an enumeration.

    item_spacing : int or float or str, optional
        Vertical spacing between items (the default theme sets this value to
        '+1cm'). `item_spacing` accepts the same values as Beampy `x` or `y`.

    item_indent : int or float or str, optional
        Horizontal item indent (the default theme sets this value to '0cm').
        `item_indent` accepts the same values as Beampy `x` or `y`.

    item_color : str, optional
        Color of item marker (the default theme sets this value to
        doc._theme['title']['color']). Color could be given as svg-color-names
        or HTML color hex values (expl: #fffff for white).

    text_color : str, optional
        Color of the item texts (the default theme sets this value to
        doc._theme['text']['color']). Color could be given as svg-color-names
        or HTML color hex values (expl: #fffff for white).

    item_layers : (list of int or string) or None, optional
        Place items into layers to animate them (the default theme sets this
        value to None, which implies that all items are displayed on the same
        layer). The list should have the same length as the `items_list`. The
        item in `item_layers` list could refers to a given layer number, given
        as int, or use python list index syntax (like ':', ':-1', '3:') given
        as string.

        >>> itemize(['item1 on all layers', 'item2 on layer 1'],
                    item_layers=[':',1])

    '''

    args = check_function_args(itemize, kwargs)
    number = 1

    if args['width'] is not None:
        in_width = float(convert_unit(args['width'])) - float(
            convert_unit(args['item_indent']))
    else:
        in_width = float(document._width) - float(
            convert_unit(args['item_indent']))

    if args['item_layers'] is not None:
        if len(items_list) != len(args['item_layers']):
            raise ValueError(
                'Length of item_layers is not the same as the length of items_list'
            )

    with group(width=args['width'], x=args['x'], y=args['y']) as groupitem:

        for i, the_item in enumerate(items_list):

            if args['item_style'] == 'bullet':
                item_char = r'$\bullet$'

            elif args['item_style'] == 'number':
                item_char = str(number) + r'.'
                number += 1

            else:
                item_char = args['item_style']

            # Add color

            item_char = color_text(item_char, args['item_color'])
            the_item = color_text(the_item, args['text_color'])

            if i == 0:
                t = text(item_char + r' ' + the_item,
                         x=args['item_indent'],
                         y=0,
                         width=in_width)
            else:
                t = text(item_char + r' ' + the_item,
                         x=args['item_indent'],
                         y=args['item_spacing'],
                         width=in_width)

            # Add layers to item
            if args['item_layers'] is not None:
                layer = args['item_layers'][i]
                if isinstance(layer, str):
                    eval('t[%s]' % layer)
                else:
                    t[args['item_layers'][i]]

    return groupitem