FedericoCeratto / dashing

Terminal dashboards for Python
https://dashing.readthedocs.io/en/latest/
444 stars 33 forks source link

`ImportError: cannot import name 'ColorRangeVGauge' from 'dashing'` running demo.py #26

Open ken-morel opened 5 months ago

ken-morel commented 5 months ago

Traceback (most recent call last): File "C:\dashing\examples\demo.py", line 4, in from dashing import ( ImportError: cannot import name 'ColorRangeVGauge' from 'dashing' (C:\Users\CHEF SEC\AppData\Roaming\Python\Python311-32\site-packages\dashing__init__.py) [Finished in 719ms with exit code 1]

ken-morel commented 3 months ago

listening...

3rd-Musketeer commented 2 months ago

Same issue, here is my solution. If you run pip install dashing, you can import ColorRangeVGauge, but you will fail to run demo.py because open_terminal() is missing, but if you implement open_terminal() manually (same with the implementation in __init__.py), it arises TypeError: Tile.display() takes 1 positional argument but 2 were given. I remove the input of ui.display() and it works. The runnable code should be:

import math
from time import sleep, time
from blessed import Terminal
import contextlib
from typing import Generator

from dashing import (
    ColorRangeVGauge,
    HBrailleChart,
    HChart,
    HGauge,
    HSplit,
    Log,
    Text,
    VChart,
    VGauge,
    VSplit,
)

@contextlib.contextmanager
def open_terminal() -> Generator:
    """
    Helper function that creates a Blessed terminal session to restore the screen after
    the UI closes.
    """
    t = Terminal()

    with t.fullscreen(), t.hidden_cursor():
        yield t

if __name__ == "__main__":

    ui = HSplit(
        VSplit(
            HGauge(val=50, title="only title", border_color=5),
            HGauge(label="only label", val=20, border_color=5),
            HGauge(label="only label", val=30, border_color=5),
            HGauge(label="only label", val=50, border_color=5),
            HGauge(label="only label", val=80, border_color=5),
            HGauge(val=20),
            HGauge(label="label, no border", val=55),
            HSplit(
                VGauge(val=0, border_color=2),
                VGauge(val=5, border_color=2),
                VGauge(val=30, border_color=2),
                VGauge(val=50, border_color=2),
                VGauge(val=80, border_color=2, color=4),
                VGauge(val=95, border_color=2, color=3),
                ColorRangeVGauge(
                    val=100,
                    border_color=2,
                    colormap=(
                        (33, 2),
                        (66, 4),
                        (100, 1),
                    ),
                ),
            ),
        ),
        VSplit(
            Text("Hello World,\nthis is dashing.", border_color=2),
            Log(title="logs", border_color=5),
            VChart(border_color=2, color=2),
            HChart(border_color=2, color=2),
            HBrailleChart(border_color=2, color=2),
            # HBrailleFilledChart(border_color=2, color=2),
        ),
        title="Dashing",
    )
    log = ui.items[1].items[1]
    vchart = ui.items[1].items[2]
    hchart = ui.items[1].items[3]
    bchart = ui.items[1].items[4]
    # bfchart = ui.items[1].items[5]
    log.append("0 -----")
    log.append("1 Hello")
    log.append("2 -----")
    prev_time = time()

    terminal = Terminal()

    with terminal.fullscreen(), terminal.hidden_cursor():
        for cycle in range(0, 100):
            ui.items[0].items[0].value = int(50 + 49.9 * math.sin(cycle / 80.0))
            ui.items[0].items[1].value = int(50 + 45 * math.sin(cycle / 20.0))
            ui.items[0].items[2].value = int(50 + 45 * math.sin(cycle / 30.0 + 3))

            vgauges = ui.items[0].items[-1].items
            for gaugenum, vg in enumerate(vgauges):
                vg.value = 50 + 49.9 * math.sin(cycle / 12.0 + gaugenum)

            t = int(time())
            if t != prev_time:
                log.append("%s" % t)
                prev_time = t
            vchart.append(50 + 50 * math.sin(cycle / 16.0))
            hchart.append(99.9 * abs(math.sin(cycle / 26.0)))
            bchart.append(50 + 50 * math.sin(cycle / 6.0))
            # bfchart.append(50 + 50 * math.sin(cycle / 16.0))
            print("TERMINAL", terminal)
            ui.display()

            sleep(1.0 / 25)
ken-morel commented 2 months ago

Thanks! @3rd-Musketeer . Currently AFK but will Try that out

ken-morel commented 2 months ago

Just leaving This open for @FedericoCeratto to see This and modify example script