Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ken-morel opened this issue Jun 3, 2024 · 4 comments

Comments

@ken-morel
Copy link

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
Copy link
Author

listening...

@3rd-Musketeer
Copy link

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
Copy link
Author

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

@ken-morel
Copy link
Author

ken-morel commented Aug 20, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants