예제 #1
0
def first_slide(slide):
    # Create a box that fill the whole slide horizontaly
    title_box1 = slide.box(width="fill", height=120)
    title_box1.rect(bg_color=COLOR2)  # Draw a filled rectangle

    # Create a sub-box in title_box1.
    # "fbox" is shortcut for box(width="fill", height="fill")
    # p_y is vertical padding (other options are:
    # p_left, p_right, p_top, p_bootom, p_x, padding)
    title_box2 = title_box1.fbox(p_y=10)
    title_box2.rect(bg_color=COLOR1)

    # Put text into a box with style "header"
    title_box2.text(
        "Elsie: Slides in Python in Programmable Way",
        elsie.TextStyle(size=35, color="white"),
    )

    # Create a box that just serves as space filler
    slide.box(height=30)

    # Subtitle box
    subtitle = slide.box()
    subtitle.text(
        "Stanislav Böhm\n~tt{https://github.com/spirali/elsie}",
        elsie.TextStyle(size=25, color=COLOR2),
    )

    # Put an image in a fix position
    slide.box(x="[50%]", y=60, height=170).image("../../docs/logo.jpeg")
예제 #2
0
def test_text_style_compose():

    style = elsie.TextStyle(font="Y", size=10)
    style2 = style.compose(elsie.TextStyle(size=20, align="left"))

    assert style2.font == "Y"
    assert style2.size == 20
    assert style2.align == "left"
    assert style.font == "Y"
    assert style.size == 10
    assert style.align is None
예제 #3
0
def test_text_style_update():

    style = elsie.TextStyle(font="Y", size=10)
    style2 = elsie.TextStyle(size=20, align="left")
    style.update(style2)

    assert style2.font is None
    assert style2.size == 20
    assert style2.align == "left"
    assert style.font == "Y"
    assert style.size == 20
    assert style.align == "left"
예제 #4
0
def intro(slide):
    head_style = elsie.TextStyle(size=35)
    slide.box().text(
        "State-Space Reduction of Non-deterministically\n"
        "Synchronizing Systems Applicable to\n"
        "Deadlock Detection in MPI", head_style)

    slide.box(height=40)
    slide.box().text("Stanislav Böhm¹, Ondřej Meca¹, Petr Jančar²")
    slide.box(height=40)
    slide.box().text(
        "¹ IT4Innovations - National Supercomputing Center, Czech Republic\n"
        "² FEI, Technical University of Ostrava, Czech Republic",
        elsie.TextStyle(size=18))
예제 #5
0
def list_demo(slide):
    main = slide.box()
    main.update_style("default", elsie.TextStyle(align="left"))

    list_item(main).text("This is LIST DEMO")
    list_item(main).text("This is\nmulti-line\nitem")
    list_item(main).text("Last item")
예제 #6
0
def chessboard_demo(slide):
    # Create a chess board

    board = slide.box(width=500, height=500)
    board.set_style("black", elsie.TextStyle(color="black", size=50))

    colors = [COLOR2, COLOR1]
    tiles = {}
    for i in range(8):
        row = board.box(height="fill", width="100%", horizontal=True)
        for j in range(8):
            b = row.box(width="fill", height="100%")
            b.rect(bg_color=colors[(i + j) % 2])
            tiles[(j, i)] = b.overlay(z_level=1)
    board.rect(color=COLOR1, stroke_width=3)

    # Create the arrow
    points = [
        tiles[(3, 4)].mid_point(),
        tiles[(3, 2)].mid_point(),
        tiles[(4, 2)].mid_point(),
    ]

    arrow = elsie.Arrow(30)
    slide.box(show="1-3").line(points,
                               color="white",
                               stroke_width=15,
                               end_arrow=arrow)

    tiles[(3, 4)].box(show="1").text("♞", "black")
    tiles[(3, 3)].box(show="2").text("♞", "black")
    tiles[(3, 2)].box(show="3").text("♞", "black")
    tiles[(4, 2)].box(show="4").text("♞", "black")
예제 #7
0
파일: test_text.py 프로젝트: spirali/elsie
def test_text_scale_to_fit_b(test_env):
    slide = test_env.slide
    slide.box(x=50, y=50, width=300,
              height=300).fbox().rect(bg_color="#bbffbb").text("This is\ntext")
    slide.box(x=650, y=50, width=300,
              height=300).fbox().rect(bg_color="#bbffbb").text(
                  "This is\ntext", scale_to_fit=True)

    slide.box(x=50, y=400, width=300,
              height=300).fbox().rect(bg_color="#bbffbb").text(
                  "This is\ntext", elsie.TextStyle(size=160))
    slide.box(x=650, y=400, width=300,
              height=300).fbox().rect(bg_color="#bbffbb").text(
                  "This is\ntext",
                  elsie.TextStyle(size=160),
                  scale_to_fit=True)
예제 #8
0
def svg_demo(slide):
    # Include SVG image into slide, it automatically fills the box.
    slide.image("testimage.svg")

    # Now we are creating the window with another picture
    # x="[90%]" is alignment of box ([0%] means left-aligning,
    # [100%] right-aligning).
    window = slide.box(x="[90%]",
                       y="30%",
                       width="30%",
                       height="30%",
                       show="4+")
    window.rect("black", bg_color="white")

    # Title of the window
    title = window.box(width="fill")
    title.rect(bg_color="black")
    title.box(padding=10).text("Scaling and placing images",
                               elsie.TextStyle(size=15, color="white"))

    # Placing a image into window. Note that we are using fbox
    # (i.e. width="fill", height="fill")
    # ('image' method does not enforce a size, so if you create a box
    # containing only image without any width/height, then you will see
    # nothing as the image fills box of the zero size).
    window.fbox().image("testimage.svg", fragments=False)
예제 #9
0
def mpi(slide):
    slide = slide_with_title(slide, "MPI - Message Passing Interface")
    slide.set_style("emph", elsie.TextStyle(bold=True))
    slide.box(height="70%").rect(bg_color="#eee").box(p_x=30, p_y=15).code(
        "c",
        """~emph{MPI_Init}(&argc, &argv);
int rank;
~emph{MPI_Comm_rank}(MPI_COMM_WORLD, &rank);
int size;
~emph{MPI_Comm_size}(MPI_COMM_WORLD, &size);
int value;
if (rank == 0) {
    value = 0;
    ~emph{MPI_Send}(&value, 1, MPI_INT,
            (rank + 1) % size,
            0, MPI_COMM_WORLD);
}
for (int t=0; t < 1000; t++) {
    ~emph{MPI_Recv}(&value, 1, MPI_INT,
                MPI_ANY_SOURCE,
                MPI_ANY_TAG,
                MPI_COMM_WORLD,
                MPI_STATUS_IGNORE);

    ~emph{MPI_Send}(&value, 1, MPI_INT,
                (rank + 1) % size,
                0, MPI_COMM_WORLD);
}
~emph{MPI_Finalize}();""",
        scale_to_fit=True,
        use_styles=True)
예제 #10
0
def text_box_in_code_demo(slide):
    slide.set_style("small", elsie.TextStyle(size=10))
    slide.box().text("Words inside code block")
    slide.box(height=80)

    c = slide.box().code(
        "c",
        """#include <stdio.h>

/* Hello world program */

    int ~#MAIN{main}() {
    printf(~small{"Hello world!\\n"});
    return ~#RETURN_VALUE{0};
}""",
        use_styles=True,
    )  # <--- use_styles=True is important to enable styling in code block

    p2 = c.inline_box("#RETURN_VALUE").p("50%", "100%")

    c.inline_box("#MAIN", z_level=-1, p_x=-2).rect(bg_color="#FBB",
                                                   color="black")

    arrow = elsie.Arrow(10)
    slide.line([p2.add(0, 40), p2], stroke_width=3, end_arrow=arrow)

    c.line_box(4).box(x="100%", height="100%").text("← Inline highlight",
                                                    "small")
    c.line_box(5).box(x="100%", height="100%").text("← Font style changed",
                                                    "small")
    c.line_box(6).box(x="100%", height="100%").text("← Pointing to a word",
                                                    "small")
예제 #11
0
def test_styles(test_env):
    slide = test_env.slide

    slide.set_style("h1", elsie.TextStyle(size=60))
    slide.set_style("h2", elsie.TextStyle(size=50))
    slide.set_style("h3", elsie.TextStyle(size=40))

    slide.set_style("my_red", elsie.TextStyle(color="red"))
    slide.set_style("my_green", elsie.TextStyle(color="green"))
    slide.set_style("my_blue", elsie.TextStyle(color="blue"))

    slide.box().text("Header 1", "h1")
    slide.box().text("Header 2", "h2")
    slide.box().text("Header 3", "h3")

    # Build in styles
    text = "Normal text | ~tt{Type writer} | ~emph{emphasis} | ~alert{alert}"
    slide.box().text(text)

    slide.box().text("~my_red{red} ~my_green{green} ~my_blue{blue}")

    # Inline style
    slide.box().text("~my_red{red} gray ~my_blue{blue}",
                     elsie.TextStyle(size=7, color="gray"))

    test_env.check("styles")
예제 #12
0
def line_highlighting(slide):
    slide.box().text("Line Highlighting")
    slide.box(height=30)

    code = slide.box().code(
        "c",
        """#include <stdio.h>

/* Hello world program */

int main() {
    printf("Hello world!\\n");
    return 0;
}""",
    )

    # 'line_box' creates box around a specified line of a text (the 1st argument)
    # Lines are counter from 0
    # We are using z_level to put highlights behind the text
    code.line_box(4, show="1-3", z_level=-1).rect(bg_color="#D0D0FF")
    code.line_box(5, show="2-3", z_level=-1).rect(bg_color="#D0D0FF")
    # Another way how to put box behind text is to 'below' parameter
    code.line_box(6, show="3", below=code).rect(bg_color="#D0D0FF")

    # The same as previous three, but we are stroking border and
    # not filling the rectangle
    code.line_box(4, n_lines=4, show="4").rect(color="blue")

    # Creating a "commenting label"
    label = slide.box(x=100, y=400, width=200, height=130, show="5")
    label.rect(bg_color="green", rx=10, ry=10)
    label.text("Comment for\na line", elsie.TextStyle(color="white"))

    # Here we creates the triangle heading to a line,
    # method 'p' returns a position relatively to the box
    label.polygon(
        [
            label.p("99%", "40%"),
            label.p("99%", "60%"),
            code.line_box(4).p(0, "50%"),
        ],
        bg_color="green",
    )

    # Now we are creating an arrow head for the orange line
    arrow = elsie.Arrow(10)
    p1 = code.line_box(0).p("100%", "50%")
    p2 = code.line_box(5).p("100%", "50%")
    slide.box(show="6").line(
        [p1, p1.add(40, 0), p2.add(40, 0), p2],
        stroke_width=3,
        color="orange",
        end_arrow=arrow,
    )
예제 #13
0
def _test_text_box_slide(slide):
    slide.set_style("my_red", elsie.TextStyle(color="red"))
    slide.set_style("my_green", elsie.TextStyle(color="green"))
    slide.set_style("my_blue", elsie.TextStyle(color="blue"))

    text = (
        "This is a long ~my_red{text}\n\nthat\n~my_green{has} a various\nproperties,"
        " ~my_blue{like a boxes} used in the text.")

    b = slide.box().text(text)
    b.inline_box("my_red").rect(color="red")
    b.inline_box("my_green").rect(color="green")
    b.inline_box("my_blue").rect(color="blue")

    slide.box(height=70)

    b = slide.box().text(text, style=elsie.TextStyle(size=40))
    b.inline_box("my_red").rect(color="red")
    b.inline_box("my_green").rect(color="green")
    b.inline_box("my_blue").rect(color="blue")
예제 #14
0
def test_line_highlight_fragments(test_env):
    slide = test_env.slide

    img = test_env.assets_path("testimage.svg")
    slide.image(img)

    b = slide.box(x="[90%]", y="[30%]", width="30%", height="30%", show="4+")
    b.rect("black", bg_color="white")
    b2 = b.box(width="fill")
    b2.update_style("default", elsie.TextStyle(size=15, color="white"))
    b2.rect(bg_color="black")
    b2.box(padding=10).text("Scaling and placing images")
    b.fbox().image(img, show_begin=4)
예제 #15
0
파일: test_text.py 프로젝트: spirali/elsie
def test_console(test_env):
    slide = test_env.slide

    slide.set_style("shell", elsie.TextStyle(color="white"), base="code")
    slide.set_style("prompt", elsie.TextStyle(color="#aaaaff"))
    slide.set_style("cmd", elsie.TextStyle(color="yellow"))

    slide.box().text("Console demo")
    slide.box(height=30)

    b = slide.box()
    b.rect(bg_color="black")
    b.box(p_x=10, p_y=5).text(
        "!prompt{~/path/to/elphie/example$} !cmd{ls}\n"
        "example.py\n\n"
        "!prompt{~/path/to/elphie/example$} !cmd{python3 example.py}\n"
        "Preprocessing................. done\n"
        "Building...................... done\n"
        "Creating 'example.pdf'........ done\n",
        "shell",
        escape_char="!",
    )
예제 #16
0
파일: test_text.py 프로젝트: spirali/elsie
def test_list(test_env):
    slide = test_env.slide

    def list_item(parent):
        b = parent.box(x=0, horizontal=True)
        b.box(width=25, y=0).text("•")
        return b.box(width="fill")

    main = slide.box()
    main.update_style("default", elsie.TextStyle(align="left"))
    list_item(main).text("This is LIST DEMO")
    list_item(main).text("This is multi\nline\nitem")
    list_item(main).text("Last item")
예제 #17
0
def debugging_slides(slide):
    slide.box(p_bottom=120, width=300, height=200,
              name="debug title").text("Debugging layout")

    title_box1 = slide.box(width="fill", height=120, name="title")
    title_box1.rect(bg_color=COLOR2)

    title_box2 = title_box1.fbox(p_y=10, name="header")
    title_box2.rect(bg_color=COLOR1)

    title_box2.text(
        "Elsie: Slides in Python in Programmable Way",
        elsie.TextStyle(size=35, color="white"),
    )

    slide.box(height=30, name="filler")

    # Subtitle box
    subtitle = slide.box(name="name")
    subtitle.text(
        "Stanislav Böhm\n~tt{https://github.com/spirali/elsie}",
        elsie.TextStyle(size=25, color=COLOR1),
    )
예제 #18
0
def console_demo(slide):
    slide.set_style("shell", elsie.TextStyle(color="white"), base="code")
    slide.set_style("prompt", elsie.TextStyle(color="#aaaaff"))
    slide.set_style("cmd", elsie.TextStyle(color="yellow"))

    slide.box().text("Console demo")
    slide.box(height=30)

    # The 'console' is just text with a few styles
    # As we want to use "~" character in the text,
    # we are changing escape_char for styles from "~" to "!"
    console = slide.box()
    console.rect(bg_color="black")
    console.box(p_x=10, p_y=5).text(
        "!prompt{~/path/to/elsie/example$} !cmd{ls}\n"
        "example.py\n\n"
        "!prompt{~/path/to/elsie/example$} !cmd{python3 example.py}\n"
        "Preprocessing................. done\n"
        "Building...................... done\n"
        "Creating 'example.pdf'........ done\n",
        "shell",
        escape_char="!",
    )
예제 #19
0
def header_footer(slide):
    slide.set_style("header", elsie.TextStyle(color="white", align="right"))
    slide.set_style("footer", elsie.TextStyle(color="white", size=15))

    header = slide.box(width="fill", height="10%")
    header.rect(bg_color="#5F8DD3")
    header.box(width="fill", p_right=20).text("Demo of Header & Footer",
                                              "header")

    slide.box(width="fill", height="10").rect(bg_color="#DDD")

    content = slide.box(height="fill")
    content.text("Content")

    footer = slide.box(width="fill", height="5%", horizontal=True)
    f1 = footer.box(width="fill", height="fill")
    f1.rect(bg_color="#5F8DD3")
    f1.text("Hello!", "footer")
    f2 = footer.box(width="fill", height="fill")
    f2.rect(bg_color="#0F2DD3")
    f2.text("Footer!", "footer")
    f3 = footer.box(width="fill", height="fill")
    f3.rect(bg_color="#5F8DD3")
    f3.text("Hello!", "footer")
예제 #20
0
def problem(slide):
    s = elsie.TextStyle(align="left", size=22)
    slide = slide_with_title(slide, "Problem")
    slide.box(p_bottom=20).text("~alert{Input}")
    slide.box().text(
        "~alert{R} - a system obtained by applying any* POR method on a system ~alert{T}\n"
        "any POR that preserves Mazurkiewicz Traces\n"
        "~alert{I} - the independent set used in reduction\n"
        "~alert{C} - set of 'candidates' that may nondetermistically synchronize",
        s)
    slide.box(height=60)
    slide.box(p_bottom=20).text("~alert{Output}")
    slide.box().text(
        "Is there a deadlock in ~alert{T} while considering synchronizations of ~alert{C} ?",
        s)
예제 #21
0
def test_text_style_create():
    style = elsie.TextStyle()
    assert style.size is None
    assert style.font is None

    style = elsie.TextStyle(
        font="X",
        size=10,
        align="left",
        line_spacing=1.2,
        color="black",
        bold=True,
        italic=False,
    )
    assert style.size == 10
    assert style.font == "X"
    assert style.bold is True
    assert style.italic is False
    assert style.color == "black"
    assert style.line_spacing == 1.2
    assert style.align == "left"

    with pytest.raises(Exception, match="font"):
        elsie.TextStyle(font=12)
    with pytest.raises(Exception, match="size"):
        elsie.TextStyle(size="zzz")
    with pytest.raises(Exception, match="line_spacing"):
        elsie.TextStyle(line_spacing="zzz")
    with pytest.raises(Exception, match="color"):
        elsie.TextStyle(color=123)
    with pytest.raises(Exception, match="bold"):
        elsie.TextStyle(bold=10)
    with pytest.raises(Exception, match="italic"):
        elsie.TextStyle(italic="a")
    with pytest.raises(Exception, match="no attribute"):
        style.unknown = 10
예제 #22
0
def test_line_highlight_1(test_env):
    slide = test_env.slide

    slide.box().text("Line Highlighting")
    slide.box(height="20%")
    b = slide.box(height="70%")
    b.rect(bg_color="#DEDEDE")
    t = b.box().code(
        "c",
        """#include <stdio.h>

    /* Hello world program */

    int main() {
        printf("Hello world!\\n");
        return 0;
    }""",
    )

    t.line_box(4, show="1-3", prepend=1).rect(bg_color="#D0D0FF")
    t.line_box(5, show="2-3", below=t).rect(bg_color="#D0D0FF")
    t.line_box(6, show="3", below=t).rect(bg_color="#D0D0FF")
    t.line_box(4, n_lines=4, show="4", below=t).rect(color="blue")

    label = slide.box(x=100, y=400, width=200, height=130, show="5+")
    label.update_style("default", elsie.TextStyle(color="white"))
    label.rect(bg_color="green", rx=10, ry=10)
    label.text("Comment for\nline")
    label.polygon(
        [
            label.p("99%", "40%"),
            label.p("99%", "60%"),
            t.line_box(4).p(0, "50%")
        ],
        bg_color="green",
    )

    test_env.check("linehighlight", 5)
예제 #23
0
def text_demo(slide):
    # New created styles
    slide.set_style("h1", elsie.TextStyle(size=60))
    slide.set_style("h2", elsie.TextStyle(size=50))
    slide.set_style("h3", elsie.TextStyle(size=40))

    slide.set_style("my_red", elsie.TextStyle(color="red"))
    slide.set_style("my_green", elsie.TextStyle(color="green"))
    slide.set_style("my_blue", elsie.TextStyle(color="blue"))

    slide.box().text("Header 1", "h1")
    slide.box().text("Header 2", "h2")
    slide.box().text("Header 3", "h3")

    # Build in styles
    text = "Normal text | ~tt{Type writer} | ~emph{emphasis} | ~alert{alert}"
    slide.box().text(text)
    slide.box().text("~my_red{red} ~my_green{green} ~my_blue{blue}")
예제 #24
0
import elsie

# Let us create primary colors used in slides
COLOR1 = "#676767"
COLOR2 = "#6699CC"

slides = elsie.SlideDeck()

# Modify text styles
slides.update_style("default", elsie.TextStyle(color=COLOR1))  # Default font
slides.update_style("emph", elsie.TextStyle(color=COLOR2))  # Emphasis

# First slide #############################################


@slides.slide()
def first_slide(slide):
    # Create a box that fill the whole slide horizontaly
    title_box1 = slide.box(width="fill", height=120)
    title_box1.rect(bg_color=COLOR2)  # Draw a filled rectangle

    # Create a sub-box in title_box1.
    # "fbox" is shortcut for box(width="fill", height="fill")
    # p_y is vertical padding (other options are:
    # p_left, p_right, p_top, p_bootom, p_x, padding)
    title_box2 = title_box1.fbox(p_y=10)
    title_box2.rect(bg_color=COLOR1)

    # Put text into a box with style "header"
    title_box2.text(
        "Elsie: Slides in Python in Programmable Way",
예제 #25
0
def final_slide(slide):
    slide.text("Have a nice day!", elsie.TextStyle(size=60))
예제 #26
0
파일: test_text.py 프로젝트: spirali/elsie
def test_text_box_left(test_env):
    slide = test_env.slide
    slide.update_style("default", elsie.TextStyle(align="left"))
    _test_text_box_slide(slide)
예제 #27
0
def zoomed_position_demo(slide):
    position_demo_helper(slide)
    slide.box(x=390, y=200).rect(bg_color="black").fbox(padding=10).text(
        "Zooming demo", elsie.TextStyle(color="white"))
예제 #28
0
def position_demo_helper(slide):
    slide.box().text("Position demo")
    slide.box(height=15)

    slide.set_style("inner", elsie.TextStyle(color="white", size=15))

    b = slide.box(width="70%", height=40)
    b.rect(color=COLOR1)
    bb = b.box(x=200, width="30%", height="fill")
    bb.rect(color=COLOR1, bg_color=COLOR2)
    bb.text("Fixed position (x=200)", "inner")
    slide.box(height=10)

    b = slide.box(width="70%", height=40)
    b.rect(color=COLOR1)
    bb = b.box(x="50%", width="30%", height="fill")
    bb.rect(color=COLOR1, bg_color=COLOR2)
    bb.text("Ratio (x='50%')", "inner")
    slide.box(height=10)

    b = slide.box(width="70%", height=40)
    b.rect(color=COLOR1)
    bb = b.box(x="[50%]", width="30%", height="fill")
    bb.rect(color=COLOR1, bg_color=COLOR2)
    bb.text("Align (x='[50%]')", "inner")
    slide.box(height=30)

    slide.box().text("Size demo")
    slide.box(height=15)

    b = slide.box(width="70%", height=40)
    b.rect(color=COLOR1)
    bb = b.box(x=0, width="200", height="fill")
    bb.rect(color=COLOR1, bg_color=COLOR2)
    bb.text("Fixed size (width=200)", "inner")
    slide.box(height=10)

    b = slide.box(width="70%", height=40)
    b.rect(color=COLOR1)
    bb = b.box(x=0, width="50%", height="fill")
    bb.rect(color=COLOR1, bg_color=COLOR2)
    bb.text("Ratio (width='50%')", "inner")
    slide.box(height=10)

    b = slide.box(width="70%", height=40, horizontal=True)
    b.rect(color=COLOR1)
    bb = b.box(width="fill", height="fill")
    bb.rect(color=COLOR1, bg_color=COLOR2)
    bb.text("Fill (width='fill')", "inner")

    slide.box(height=10)

    b = slide.box(width="70%", height=40, horizontal=True)
    b.rect(color=COLOR1)

    bb = b.box(width="fill", height="fill")
    bb.rect(color=COLOR1, bg_color=COLOR2)
    bb.text("Fill (width='fill')", "inner")

    bb = b.box(width="fill(3)", height="fill")
    bb.rect(color=COLOR1, bg_color=COLOR2)
    bb.text("Fill (width='fill(3)')", "inner")

    bb = b.box(width="fill(2)", height="fill")
    bb.rect(color=COLOR1, bg_color=COLOR2)
    bb.text("Fill (width='fill(2)')", "inner")
예제 #29
0
def test_text_box_middle(test_env):
    slide = test_env.slide
    slide.update_style("default", elsie.TextStyle(align="middle"))
    _test_text_box_slide(slide)
    test_env.check("text-box-middle")
예제 #30
0
def test_text_box_right(test_env):
    slide = test_env.slide
    slide.update_style("default", elsie.TextStyle(align="right"))
    _test_text_box_slide(slide)
    test_env.check("text-box-right")