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

Issue with hex colour in VS Code terminal #1298

Closed
5 tasks done
EmidioStani opened this issue Feb 10, 2022 · 7 comments
Closed
5 tasks done

Issue with hex colour in VS Code terminal #1298

EmidioStani opened this issue Feb 10, 2022 · 7 comments
Assignees
Labels
invalid ⛔ Not-an-issue or upstream (not-our-issue) p2-bug-warning ⚠ Visual output bad
Projects

Comments

@EmidioStani
Copy link

EmidioStani commented Feb 10, 2022

  • I have marked all applicable categories:
    • visual output bug
  • I have visited the [source website], and in particular
    read the [known issues]
  • I have searched through the [issue tracker] for duplicates
  • I have mentioned version numbers, operating system and
    environment, where applicable:
    import tqdm, sys
    print(tqdm.__version__, sys.version, sys.platform)

4.62.3 3.9.8 (tags/v3.9.8:bb3fdcf, Nov 5 2021, 20:48:33) [MSC v.1929 64 bit (AMD64)] win32

Hello I am running my python script in the terminal of Visual Studio Code (in dark mode), when I use the predefined colours like (RED, YELLOW, etc.) I can see the progress bar in that colour (see yellow in screenshot) but when I try any hex like #ff0000 or whatever combination I put it is always grey (see below in the screenshot)
image

@sudhamsugurijala
Copy link

sudhamsugurijala commented Feb 17, 2022

Hi @EmidioStani

I tried to reproduce the issue in VS Code (dark mode), but looks like hex color code is working fine.

P.S. I cloned this tqdm repository locally and tested it. I hope it is also alright in the default pip tqdm installation as well.

image

@EmidioStani
Copy link
Author

Thanks for checking this, I wonder what the problem would be

@joshinils
Copy link

joshinils commented Mar 3, 2022

this should print various colors randomly

#!/usr/bin/env python3
import tqdm, time, random, colorsys

def hsv_to_rgb(h, s, v):
    r, g, b = colorsys.hsv_to_rgb(h, s, v)
    return f"#{hex(int(r*255))[2:].rjust(2,'0')}{hex(int(g*255))[2:].rjust(2,'0')}{hex(int(b*255))[2:].rjust(2,'0')}"


while True:
    total = 360
    pbar = tqdm.tqdm(total=total)
    s, v = random.random(), random.random()
    for h in range(total):
        pbar.update()
        pbar.colour = hsv_to_rgb(h / 360, s, v)
        pbar.refresh()
        time.sleep(1 / total)

my system info;

4.60.0 3.8.10 (default, Nov 26 2021, 20:14:08) 
[GCC 9.3.0] linux

and info for code --version

1.64.2
f80445acd5a3dadef24aa209168452a3d97cc326
x64

but i did have some issues with this skipping lines up and down, and even a runtime error:

100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 360/360 [00:03<00:00, 114.02it/s]
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 360/360 [00:02<00:00, 176.39it/s]
Exception in thread Thread-1:█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 360/360 [00:01<00:00, 323.08it/s]
Traceback (most recent call last):████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 360/360 [00:01<00:00, 324.86it/s]
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 360/360 [00:01<00:00, 322.13it/s]
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 360/360 [00:01<00:00, 323.49it/s    self.run()████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏                                    | 299/360 [00:00<00:00, 322.75it/s]
  File "/home/niels/.local/lib/python3.8/site-packages/tqdm/_monitor.py", line 69, in run
    instances = self.get_instances()
  File "/home/niels/.local/lib/python3.8/site-packages/tqdm/_monitor.py", line 49, in get_instances
    return [i for i in self.tqdm_cls._instances.copy()
  File "/usr/lib/python3.8/_weakrefset.py", line 92, in copy
    return self.__class__(self)
  File "/usr/lib/python3.8/_weakrefset.py", line 50, in __init__
    self.update(data)
  File "/usr/lib/python3.8/_weakrefset.py", line 119, in update
    for element in other:
  File "/usr/lib/python3.8/_weakrefset.py", line 60, in __iter__
    for itemref in self.data:
RuntimeError: Set changed size during iteration

@sudhamsugurijala
Copy link

Hi @joshinils
I added pbar.close() after the for loop and put pbar.update() after setting pbar.colour as shown below:

#!/usr/bin/env python3
import tqdm, time, random, colorsys

def hsv_to_rgb(h, s, v):
    r, g, b = colorsys.hsv_to_rgb(h, s, v)
    return f"#{hex(int(r*255))[2:].rjust(2,'0')}{hex(int(g*255))[2:].rjust(2,'0')}{hex(int(b*255))[2:].rjust(2,'0')}"

while True:
    total = 360
    pbar = tqdm.tqdm(total=total)
    s, v = random.random(), random.random()
    for h in range(total):
        pbar.colour = hsv_to_rgb(h / total, s, v) # Changed 360 to total
        pbar.update()
        pbar.refresh()
        time.sleep(1 / total)
    pbar.close()

The bars kept changing colours (not captured by this picture) and i got an output with no errors -

tqdm-snip

Was this the intended output?

I cloned this tqdm repository and checked your code. I hope it is the same with the standard pip tqdm installation.

@joshinils
Copy link

I added pbar.close() after the for loop and put pbar.update() after setting pbar.colour as shown below:

Aha, I forgot close(), that indeed was the issue.

The bars kept changing colours (not captured by this picture) and i got an output with no errors
Was this the intended output?

Yes, I wanted it to loop through as many colours as possible, so each bar goes through all hues with random saturation and value, but I guess that's not necessary to check for colour support.

I cloned this tqdm repository and checked your code. I hope it is the same with the standard pip tqdm installation.

I am using the standard pip install

@casperdcl casperdcl self-assigned this Jun 18, 2022
@casperdcl casperdcl added invalid ⛔ Not-an-issue or upstream (not-our-issue) p2-bug-warning ⚠ Visual output bad labels Jun 18, 2022
@casperdcl
Copy link
Sponsor Member

Closing this as it doesn't seem to be reproducible.

@casperdcl casperdcl closed this as not planned Won't fix, can't repro, duplicate, stale Jun 18, 2022
@casperdcl
Copy link
Sponsor Member

Also since v4.63.2 (thanks to #1309) you should be able to use the notebook version in VSCode (tqdm.auto/tqdm.notebook)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid ⛔ Not-an-issue or upstream (not-our-issue) p2-bug-warning ⚠ Visual output bad
Projects
Casper
  
Awaiting triage
Development

No branches or pull requests

4 participants