コード例 #1
0
    def __init__(self,
                 elements_to_group=None,
                 x='center',
                 y='auto',
                 width=None,
                 height=None,
                 background=None):

        if width != None:
            width = width
        if height != None:
            height = height

        self.id = document._global_counter['group']
        self.args = {'group_id': self.id, "background": background}

        self.data = {
            'args': self.args,
            'id': self.id,
            'content': '',
            'render': render_group,
            'type': 'group'
        }

        self.positionner = add_to_slide(self.data, x, y, width, height)
        document._contents[gcs()]['groups'] += [self.data]
        document._global_counter['group'] += 1

        if elements_to_group != None:
            eids = [e.id for e in elements_to_group]
            print("[Beampy][%s] render %i elements in group %i" %
                  (gcs(), len(eids), self.id))
            render_group_content(eids, self.data)
コード例 #2
0
ファイル: code.py プロジェクト: frankier/beampy
def code( codetext, x='center', y='auto', width=None, height=None, langage=None, size="14px" ):
    """
        Color a given code using python pygment

        option
        ------

        langage[None]: try to infer the lexer from codetext

        size['9px']: size of the text

    """


    if width == None:
        width = float(document._width)
    if height == None:
        height = float(document._height)

    args = {"langage": langage, 'font-size': size }

    codeout = {'type': 'code', 'content': codetext, 'args': args,
              "render": render_code}

    if is_pigment:
        return add_to_slide( codeout, x, y, width, height )
    else:
        print("Python pygment is not installed, I can't translate code into svg...")
コード例 #3
0
def video(videofile, **kwargs):
    """
    Add video in webm/ogg/mp4 format

    arguments
    ---------

    width = None -> document._width
    heigh = None -> document._height

    x ['center']: x position
    y ['auto']: y position

    autoplay [False]: To launch video when slide appears

    control [True]: Display video control bar

    still_image_time [0]: extract the still image for pdf export at the given still_image_time in second
    """

    #Check function args
    args = check_function_args(video, kwargs)

    #if no width is given get the default width
    if args['width'] == None:
        args['width'] = str(document._width)

    #check extension
    ext = None
    if '.webm' in videofile.lower():
        ext = 'webm'
    elif '.ogg' in videofile.lower():
        ext = 'ogg'
    elif '.mp4' in videofile.lower():
        ext = 'mp4'
    else:
        print('Video need to be in webm/ogg/mp4(h.264) format!')

    if ext != None:
        args['ext'] = ext
        args['filename'] = videofile

        #Add video to the document type_nohtml used to remplace video by svg still image when not exported to HTML5
        videout = {
            'type': 'html',
            'type_nohtml': 'svg',
            'content': '',
            'args': args,
            "render": render_video,
            'filename': videofile
        }

        return add_to_slide(videout,
                            x=args['x'],
                            y=args['y'],
                            width=args['width'],
                            height=None)
コード例 #4
0
def animatesvg(files_folder, **kwargs):
    """
        Function to create svg animation from a folder containing svg files

        - files_folder: Folder containing svg like "./my_folder/"

        - x['center']: x coordinate of the image
                       'center': center image relative to document._width
                       '+1cm": place image relative to previous element

        - y['auto']: y coordinate of the image
                     'auto': distribute all slide element on document._height
                     'center': center image relative to document._height (ignore other slide elements)
                     '+3cm': place image relative to previous element

        - start[0]: svg image number to start the sequence
        - end['end']: svg image number to stop the sequence
        - width[None]: Width of the figure (None = slide width)
        - fps[25]: animation framerate
        - autoplay[False]: autoplay animation when slide is displayed

    """

    #Check input args for this module
    args = check_function_args(animatesvg, kwargs)

    if args['width'] == None:
        args['width'] = str(document._width)

    #Read all svg files
    svg_files = glob.glob(files_folder + '*.svg')

    #Need to sort using the first digits finded in the name
    svg_files = sorted(svg_files,
                       key=lambda x: int(''.join(re.findall(r'\d+', x))))

    #check how many images we wants
    if args['end'] == 'end':
        args['end'] = len(svg_files)

    svg_files = svg_files[args['start']:args['end']]

    svgcontent = []
    for svgf in svg_files:
        with open(svgf, 'r') as f:
            svgcontent += [f.read()]

    animout = {
        'type': 'animatesvg',
        'content': svgcontent,
        'args': args,
        "render": render_animatesvg
    }

    return add_to_slide(animout, args['x'], args['y'], args['width'], None)
コード例 #5
0
ファイル: animatesvg.py プロジェクト: frankier/beampy
def animatesvg(files_folder, **kwargs):
    """
        Function to create svg animation from a folder containing svg files

        - files_folder: Folder containing svg like "./my_folder/"

        - x['center']: x coordinate of the image
                       'center': center image relative to document._width
                       '+1cm": place image relative to previous element

        - y['auto']: y coordinate of the image
                     'auto': distribute all slide element on document._height
                     'center': center image relative to document._height (ignore other slide elements)
                     '+3cm': place image relative to previous element

        - start[0]: svg image number to start the sequence
        - end['end']: svg image number to stop the sequence
        - width[None]: Width of the figure (None = slide width)
        - fps[25]: animation framerate
        - autoplay[False]: autoplay animation when slide is displayed

    """

    #Check input args for this module
    args = check_function_args(animatesvg, kwargs)

    if args['width'] == None:
        args['width'] = str(document._width)

    #Read all svg files
    svg_files = glob.glob(files_folder+'*.svg')

    #Need to sort using the first digits finded in the name
    svg_files = sorted(svg_files, key=lambda x: int(''.join(re.findall(r'\d+', x))))

    #check how many images we wants
    if args['end'] == 'end':
        args['end'] = len(svg_files)

    svg_files = svg_files[args['start']:args['end']]

    svgcontent = []
    for svgf in svg_files:
        with open(svgf,'r') as f:
            svgcontent += [f.read()]

    animout = {'type': 'animatesvg', 'content': svgcontent, 'args': args,
               "render": render_animatesvg }

    return add_to_slide( animout, args['x'], args['y'], args['width'], None)
コード例 #6
0
ファイル: video.py プロジェクト: frankier/beampy
def video(videofile, **kwargs):
    """
    Add video in webm/ogg/mp4 format

    arguments
    ---------

    width = None -> document._width
    heigh = None -> document._height

    x ['center']: x position
    y ['auto']: y position

    autoplay [False]: To launch video when slide appears

    control [True]: Display video control bar

    still_image_time [0]: extract the still image for pdf export at the given still_image_time in second
    """

    #Check function args
    args = check_function_args(video, kwargs)

    #if no width is given get the default width
    if args['width'] == None:
        args['width'] = str(document._width)

    #check extension
    ext = None
    if '.webm' in videofile.lower():
        ext = 'webm'
    elif '.ogg' in videofile.lower():
        ext = 'ogg'
    elif '.mp4' in videofile.lower():
        ext = 'mp4'
    else:
        print('Video need to be in webm/ogg/mp4(h.264) format!')

    if ext != None:
        args['ext'] = ext
        args['filename'] = videofile

        #Add video to the document type_nohtml used to remplace video by svg still image when not exported to HTML5
        videout = {'type': 'html', 'type_nohtml': 'svg', 'content': '', 'args': args,
                   "render": render_video,
                   'filename': videofile}

        return add_to_slide( videout, x=args['x'], y=args['y'], width=args['width'], height=None  )
コード例 #7
0
ファイル: title.py プロジェクト: frankier/beampy
def title( title_text , **kwargs):
    """
        Add a title to a slide
    """

    #Check function arguments from THEME
    args = check_function_args(title, kwargs)
    #Add text arguments because we use the text render
    args = inherit_function_args('text', args)

    if args['width'] == None:
        args['width'] = document._width
    
    titleout = {'type': 'svg',
                'content':title_text,
                "args":args,
                "render": render_text }

    document._contents[gcs()]['title']=titleout
    out = add_to_slide(titleout, args['x'], args['y'], width=args['width'], height=None)
コード例 #8
0
ファイル: text.py プロジェクト: frankier/beampy
def text(textin, **kwargs):
    """
        Function to add a text to the current slide

        Options
        -------

        - x['center']: x coordinate of the image
                       'center': center image relative to document._width
                       '+1cm": place image relative to previous element

        - y['auto']: y coordinate of the image
                     'auto': distribute all slide element on document._height
                     'center': center image relative to document._height (ignore other slide elements)
                     '+3cm': place image relative to previous element

        Exemples
        --------

        text('this is my text', '20', '20')
    """

    args = check_function_args(text, kwargs)

    #Check width
    if args['width'] == None:
        args['width'] = document._width

    textout = {
        'type': 'text',
        'content': textin,
        'args': args,
        "render": render_text
    }

    #Add text to the document
    return add_to_slide(textout,
                        x=args['x'],
                        y=args['y'],
                        width=args['width'],
                        height=None)
コード例 #9
0
ファイル: core.py プロジェクト: frankier/beampy
    def __init__(self, elements_to_group=None, x='center', y='auto', width = None, height = None, background=None):

        if width != None:
            width = width
        if height != None:
            height = height

        self.id = document._global_counter['group']
        self.args = {'group_id': self.id, "background": background}

        self.data = {'args': self.args, 'id': self.id, 'content':'',
                    'render':render_group,'type':'group'}

        self.positionner = add_to_slide(self.data, x, y, width, height)
        document._contents[gcs()]['groups'] += [ self.data ]
        document._global_counter['group'] += 1

        if elements_to_group != None:
            eids = [e.id for e in elements_to_group]
            print("[Beampy][%s] render %i elements in group %i"%(gcs(), len(eids), self.id))
            render_group_content( eids, self.data )
コード例 #10
0
ファイル: tikz.py プロジェクト: frankier/beampy
def tikz(tikscommands, **kwargs):
    """
        Function to render tikz commands to svg

        options:
        --------
        - tikz_header: allow to add extra tikslibraries and style, everything that
                       is included befor \begin{document}

                       exp:
                       tikz_header = " \usetikzlibrary{shapes.geometric}
                                     % Vector Styles
                                     \tikzstyle{load}   = [ultra thick,-latex]
                                     \tikzstyle{stress} = [-latex]
                                     \tikzstyle{dim}    = [latex-latex]
                                     \tikzstyle{axis}   = [-latex,black!55]
                                     "
        - tex_packages: Add extra \usepackages in tex document.
                        Need to be a list of string

                        expl:
                        tex_packages = ['xolors','tikz-3dplot']

        - figure_options: options for \begin{tikzfigure}[options]

        - figure_anchor ['top_left']: set the anchor of tikz output svg 'top_left', 'bottom_left', 'top_right', bottom_right'
    """

    args = check_function_args(tikz, kwargs)

    textout = {'type': 'tikz', 'content': tikscommands,
               'args': args,
               "render": render_tikz}


    return add_to_slide( textout, args['x'], args['y'], None, None )
コード例 #11
0
def figure(filename, ext=None, **kwargs):
    """
        Add figure to current slide
        Accepted format: [svg, png, jpeg, bokeh figure]

        - x['center']: x coordinate of the image
                       'center': center image relative to document._width
                       '+1cm": place image relative to previous element

        - y['auto']: y coordinate of the image
                     'auto': distribute all slide element on document._height
                     'center': center image relative to document._height (ignore other slide elements)
                     '+3cm': place image relative to previous element
https://duckduckgo.com/?q=feder+inra&t=ffab
        - height[None]: Image heigt

        - ext[None]: Image format, if None, format is guessed from filename.

    """

    args = check_function_args(figure, kwargs)

    #Check if the given filename is a string
    if type(filename) == type(''):
        #Check extension
        if ext == None:
            if '.svg' in filename.lower():
                ext = 'svg'

            if '.png' in filename.lower():
                ext = 'png'

            if ( '.jpeg' in filename.lower() ) or ( '.jpg' in filename.lower() ):
                ext = 'jpeg'

            if '.pdf' in filename.lower():
                ext = 'pdf'

    else:
        if "bokeh" in str(type(filename)):
            ext = 'bokeh'

    ######################################


    if ext == None:
        print("figure format can't be guessed from file name")
        sys.exit(1)

    #Bokeh image
    elif ext == 'bokeh':
        #print('I got a bokeh figure')
        figscript, figdiv = components(filename, wrap_script=False)

        #Todo get width and height from a bokeh figure
        if args['width'] == None:
            args['width'] = '%ipx'%filename.plot_width
        if args['height'] == None:
            args['height'] = '%ipx'%filename.plot_height

        #Transform figscript to givea function name load_bokehjs
        tmp = figscript.splitlines()
        goodscript = '\n'.join( ['["load_bokeh"] = function() {'] + tmp[1:-1] + ['};\n'] )
        args['ext'] = ext
        args['script']=goodscript

        figout = {'type': 'html',
                  'content': figdiv,
                  'args': args,
                  'render': render_figure}

        return add_to_slide( figout, args['x'], args['y'], args['width'], args['height'] )


    #Other filetype images
    else:

        if args['width'] == None:
            args['width'] = document._width

        args['ext']=ext
        args['filename']=filename

        figout = {'type': 'figure', 'content': filename, 'args': args,
                  "render": render_figure}

        return add_to_slide( figout, args['x'], args['y'], args['width'], args['height'] )