Пример #1
0
def test_get_pulse_segments():
    bar = ProgressBar()
    segments = bar._get_pulse_segments(Style.parse("red"),
                                       Style.parse("yellow"), None, False,
                                       False)
    print(repr(segments))
    expected = [
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
    ]
    assert segments == expected
Пример #2
0
def test_render():
    bar = ProgressBar(completed=11, width=50)
    bar_render = render(bar)
    assert bar_render == expected[0]
    bar.update(completed=12)
    bar_render = render(bar)
    assert bar_render == expected[1]
Пример #3
0
def update_motors(st):
    panel = Table.grid()
    panel.title = "Motor Channels"
    panel.title_style = "bold white"
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    for ch in range(0, 2):
        motor = st.motors[ch]
        tgtspd = motor.target_speed
        curspd = motor.current_speed
        pwmspd = motor.pwm_speed
        chactive = (ch == 0 and st.status_latch2 & 0x03) or (
            ch == 1 and st.status_latch2 & 0x0C)
        style = "green"
        if not chactive:
            s = ":black_medium_square:"
        if chactive and motor.dir == "Forward":
            s = ":arrow_forward:"
            style = "green"
        elif chactive:
            s = ":arrow_backward:"
            tgtspd = (~tgtspd + 1) & 0xFF
            curspd = (~curspd + 1) & 0xFF
            style = "red"
        tgt = ProgressBar(total=255,
                          completed=tgtspd,
                          complete_style=style,
                          finished_style=style)
        curr = ProgressBar(total=255,
                           completed=curspd,
                           complete_style=style,
                           finished_style=style)
        pwm = ProgressBar(total=255,
                          completed=pwmspd,
                          complete_style=style,
                          finished_style=style)
        panel.add_row(
            "Ch %d %s Tgt: " % (ch + 1, s),
            tgt,
            " [cyan]%3d " % (tgtspd),
            "Curr: ",
            curr,
            " [cyan]%3d " % (curspd),
            "PWM: ",
            pwm,
            " [cyan]0x%02X" % (pwmspd),
        )
    return Panel(panel)
Пример #4
0
 def render(self, task):
     return ProgressBar(
         pulse=task.completed < task.total,
         animation_time=task.get_time(),
         width=40,
         total=task.total,
         completed=task.completed,
     )
Пример #5
0
 def render(self, task: "Task") -> ProgressBar:
     """Gets a progress bar widget for a task."""
     return ProgressBar(
         total=max(0, task.total),
         completed=max(0, task.completed),
         width=None if self.bar_width is None else max(1, self.bar_width),
         pulse=not task.started or not math.isfinite(task.remaining),
         animation_time=task.get_time(),
         style=self.style,
         complete_style=self.complete_style,
         finished_style=self.finished_style,
         pulse_style=self.pulse_style,
     )
Пример #6
0
def update_lights(st):
    panel = Table.grid()
    panel.title = "Light Channels"
    panel.title_style = "bold white"
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    style = "light_goldenrod3"
    for ch in range(0, 8):
        light = st.lights[ch]
        tgt = ProgressBar(
            total=255,
            completed=light.target_level,
            complete_style=style,
            finished_style=style,
        )
        curr = ProgressBar(
            total=255,
            completed=light.current_level,
            complete_style=style,
            finished_style=style,
        )
        if light.active:
            s = ":black_square_button: "
        else:
            s = ":black_large_square: "
        panel.add_row(
            "Ch %d %s Tgt: " % (ch + 1, s),
            tgt,
            " [cyan]%3d " % (light.target_level),
            "Curr: ",
            curr,
            " [cyan]%3d " % (light.current_level),
        )
    return Panel(panel)
Пример #7
0
def update_volume(value) -> Panel:
    """Some example content."""
    panel = Table.grid()
    bright_bar = ProgressBar(
        total=255,
        complete_style="aquamarine3",
        finished_style="aquamarine3",
        completed=value,
    )
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    panel.add_row("Volume: ", bright_bar, "[aquamarine3]%3d" % (value))
    return Panel(panel)
Пример #8
0
def update_brightness(value) -> Panel:
    """Some example content."""
    panel = Table.grid(padding=1)
    bright_bar = ProgressBar(
        total=255,
        complete_style="light_slate_blue",
        finished_style="light_slate_blue",
        completed=value,
    )
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    panel.add_column(ratio=1)
    panel.add_row("Brightness: ", bright_bar,
                  "[light_slate_blue]%3d" % (value))
    return Panel(panel)
Пример #9
0
def test_update():
    bar = ProgressBar()
    assert bar.completed == 0
    assert bar.total == 100
    bar.update(10, 20)
    assert bar.completed == 10
    assert bar.total == 20
    assert bar.percentage_completed == 50
    bar.update(100)
    assert bar.percentage_completed == 100
Пример #10
0
def update_audio_state(st):
    panel = Table.grid()
    level_bar = ProgressBar(
        total=255,
        complete_style="aquamarine3",
        finished_style="aquamarine3",
        completed=st.audio_peak,
    )
    for i in range(3):
        panel.add_column(ratio=1)
    panel.add_row(
        "Audio peak: ",
        level_bar,
        "[aquamarine3]0x%02X" % (st.audio_peak),
    )
    return Panel(panel)
Пример #11
0
    def _add(self, message, iterables=[], override=None):

        key = Text(message, overflow='ellipsis', no_wrap=True)
        busy = Text()

        if override is None:

            total = 1.0
            pulse = True

            try:
                total = len(iterables) if iterables != [] else 1
                pulse = iterables == []

            # Not all iterables have a length
            except TypeError:
                pass

            busy._text = ["→"]
            color = Style(color="rgb(161, 209, 255)", dim=True)
            value = ProgressBar(total=total,
                                pulse=pulse,
                                complete_style=color,
                                finished_style=color,
                                pulse_style=color)
        else:
            value = override

        operation = Table(box=None,
                          show_header=False,
                          show_footer=False,
                          show_edge=True,
                          padding=(0, 0 if self.show_header else 1))

        operation.add_column(width=3 if self.show_header else 2,
                             justify="center")
        operation.add_column(width=62 if self.show_header else 60)
        operation.add_column()
        operation.add_row(busy, key, value)

        self.add_row(operation)
        return (key, value, busy)
Пример #12
0
def test_measure():
    console = Console(width=120)
    bar = ProgressBar()
    measurement = bar.__rich_measure__(console, console.options)
    assert measurement.minimum == 4
    assert measurement.maximum == 120
Пример #13
0
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("red"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
        Segment("━", Style.parse("yellow"), False),
    ]
    assert segments == expected


if __name__ == "__main__":
    bar = ProgressBar(completed=11, width=50)
    bar_render = render(bar)
    print(repr(bar_render))
    bar.update(completed=12)
    bar_render = render(bar)
    print(repr(bar_render))
Пример #14
0
def test_init():
    bar = ProgressBar(completed=50)
    repr(bar)
    assert bar.percentage_completed == 50.0
Пример #15
0
def test_measure():
    bar = ProgressBar()
    measurement = bar.__rich_measure__(None, 120)
    assert measurement.minimum == 4
    assert measurement.maximum == 120
Пример #16
0
def test_pulse():
    bar = ProgressBar(pulse=True, animation_time=10)
    bar_render = render(bar)
    print(repr(bar_render))
    expected = "\x1b[38;2;249;38;114m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;58;58;58m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;249;38;114m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;58;58;58m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;249;38;114m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;58;58;58m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;249;38;114m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;58;58;58m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;249;38;114m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;58;58;58m━\x1b[0m\x1b[38;2;62;57;59m━\x1b[0m\x1b[38;2;76;56;63m━\x1b[0m\x1b[38;2;97;53;69m━\x1b[0m\x1b[38;2;123;51;77m━\x1b[0m\x1b[38;2;153;48;86m━\x1b[0m\x1b[38;2;183;44;94m━\x1b[0m\x1b[38;2;209;42;102m━\x1b[0m\x1b[38;2;230;39;108m━\x1b[0m\x1b[38;2;244;38;112m━\x1b[0m"
    assert bar_render == expected
Пример #17
0
def test_zero_total():
    # Shouldn't throw zero division error
    bar = ProgressBar(total=0)
    render(bar)