コード例 #1
0
 def predict_sequence(wrapper: Box, values, start=1):
     for i in range(len(values)):
         value = "Taken" if values[i] else "Not taken"
         show_start = start + i * 2
         wrapper.overlay(
             show="{}-{}".format(show_start, show_start + 1)).rect(
                 bg_color="white").text("Prediction: {}".format(value),
                                        style=text_style)
コード例 #2
0
ファイル: utils.py プロジェクト: Kobzol/elsie-gallery
def slide_header(box: Box,
                 text: str,
                 return_header=False) -> Union[Box, Tuple[Box, Box]]:
    header = box.box(width="fill", height="10%").rect(bg_color="#23363A")
    row = header.box(horizontal=True)
    row.box().text(text, style=s(size=40, bold=True, color="#FFFFFF"))

    content = box.box(height="fill", width="fill")
    if return_header:
        return (content, row)
    return content
コード例 #3
0
ファイル: utils.py プロジェクト: Kobzol/elsie-gallery
def code_step(parent: Box, code_content: str, show_start, line_steps,
              **code_args):
    show_start = int(show_start)

    code_content = code_content.strip()
    lines = code_content.split("\n")

    def get_line(lines, visible):
        if visible is None:
            return INVISIBLE_SPACE
        elif isinstance(visible, int):
            return lines[visible]
        else:
            return visible

    last = None
    for (step, visible_lines) in enumerate(line_steps):
        assert len(visible_lines) == len(lines)

        show = str(step + show_start)
        if step == len(line_steps) - 1:
            show += "+"
        wrapper = parent.overlay(show=show)

        current_lines = [get_line(lines, visible) for visible in visible_lines]
        last = code(wrapper, "\n".join(current_lines), **code_args)
    return last
コード例 #4
0
def code(parent: Box,
         code: str,
         language="rust",
         width=None,
         code_style="code") -> TextBoxItem:
    content = parent.box(width=width)
    content.rect(bg_color="#EEEEEE")
    codebox = content.box(p_left=10, p_right=50, p_y=10, z_level=100, x=0)
    return codebox.code(language, code, style=code_style)
コード例 #5
0
ファイル: utils.py プロジェクト: Kobzol/elsie-gallery
def bash(parent: Box, code: str, text_style=None, **box_args):
    if text_style is None:
        text_style = s()

    text_style = text_style.compose(s(color="#E9E9ED", font="monospace"))

    wrapper = parent.box(**box_args)
    wrapper.rect(bg_color="#3F3F3F")
    code_wrapper = wrapper.box(x=0, p_x=10, p_y=5)
    return code_wrapper.text(code, style=text_style)
コード例 #6
0
    def table(wrapper: Box,
              size,
              dimension,
              buckets=None,
              bucket_indices=True):
        htable = wrapper.box(horizontal=True)
        items = []
        for i in range(size):
            cell = htable.box(width=dimension,
                              height=dimension,
                              horizontal=True).rect("black", stroke_width=2)
            items.append(cell)

        if buckets:
            bucket_width = int((size / buckets) * dimension)
            for i in range(buckets):
                pos = i * bucket_width
                htable.box(x=pos, y=0, width=bucket_width,
                           height=dimension).rect("black", stroke_width=6)
                if bucket_indices:
                    htable.box(x=pos, y=dimension - 5,
                               width=bucket_width).text(str(i))

        return (htable, items)
コード例 #7
0
ファイル: denormals.py プロジェクト: Kobzol/elsie-gallery
 def floating_point(wrapper: Box, colors, values):
     for i in range(len(colors)):
         box = wrapper.box(width=box_dimension, height=box_dimension)
         box.rect(color="black", bg_color=colors[i], stroke_width=2)
         box.text(str(values[i]), s(color="white", bold=True))
コード例 #8
0
ファイル: utils.py プロジェクト: Kobzol/elsie-gallery
def with_bg(parent: Box, bg_color="#DDDDDD") -> Box:
    quote = parent.box()
    quote.rect(bg_color=bg_color)
    return quote.box(padding=10, z_level=100)
コード例 #9
0
ファイル: utils.py プロジェクト: Kobzol/elsie-gallery
def with_border(parent: Box, color="red", padding=5, **box_args):
    return parent.box(**box_args).rect(color=color).box(padding=padding)