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

Width of progressbar is wrong #33

Closed
maxnoe opened this issue Nov 6, 2015 · 14 comments
Closed

Width of progressbar is wrong #33

maxnoe opened this issue Nov 6, 2015 · 14 comments

Comments

@maxnoe
Copy link

maxnoe commented Nov 6, 2015

 10% (1 of 10) |##                          | Elapsed Time: 0:00:00 ETA: 0:00:0
 20% (2 of 10) |#####                       | Elapsed Time: 0:00:00 ETA: 0:00:0
 30% (3 of 10) |########                    | Elapsed Time: 0:00:00 ETA: 0:00:0
 40% (4 of 10) |###########                 | Elapsed Time: 0:00:00 ETA: 0:00:0
 50% (5 of 10) |##############              | Elapsed Time: 0:00:00 ETA: 0:00:0  
 60% (6 of 10) |################            | Elapsed Time: 0:00:00 ETA: 0:00:0 
 70% (7 of 10) |###################         | Elapsed Time: 0:00:00 ETA: 0:00:0
 80% (8 of 10) |######################      | Elapsed Time: 0:00:00 ETA: 0:00:0
 90% (9 of 10) |#########################   | Elapsed Time: 0:00:00 ETA: 0:00:0
100% (10 of 10) |#############################| Elapsed Time: 0:00:01 Time: 1.00

arch linux, i3wm, rxvt-unicode-256 color
Also on windows in mysy2

@maxnoe maxnoe changed the title Width of progressbar is off by 1 Width of progressbar is wrong Nov 6, 2015
@wolph
Copy link
Owner

wolph commented Nov 11, 2015

It could be due to an old version but there's not really a mistake (in my case at least).

 10% (1 of 10) |##                          | Elapsed Time: 0:00:00 ETA: 0:00:00
 20% (2 of 10) |#####                       | Elapsed Time: 0:00:00 ETA: 0:00:00
 30% (3 of 10) |########                    | Elapsed Time: 0:00:00 ETA: 0:00:00
 40% (4 of 10) |###########                 | Elapsed Time: 0:00:00 ETA: 0:00:00
 50% (5 of 10) |##############              | Elapsed Time: 0:00:00 ETA: 0:00:00
 60% (6 of 10) |################            | Elapsed Time: 0:00:00 ETA: 0:00:00
 70% (7 of 10) |###################         | Elapsed Time: 0:00:00 ETA: 0:00:00
 80% (8 of 10) |######################      | Elapsed Time: 0:00:00 ETA: 0:00:00
 90% (9 of 10) |#########################   | Elapsed Time: 0:00:00 ETA: 0:00:00
100% (10 of 10) |#############################| Elapsed Time: 0:00:00 Time: 0.12

While it looks weird, it's just adjusting to the width of the terminal (80 characters) and at the last line the Time: 1.00 is less wide than the ETA: 0:00:0 which causes it to be wider. Also, the 10 of 10 is wider than 9 of 10 which causes it to move.

I'll see if I can make those (mostly) fixed size to make it cleaner.

@wolph
Copy link
Owner

wolph commented Nov 11, 2015

Release 3.4.0 tries to make sure that the widgets always keep the same size. It won't work in all cases but many cases should be handled now.

@wolph wolph closed this as completed Nov 11, 2015
@maxnoe
Copy link
Author

maxnoe commented Nov 12, 2015

Now i do not get any progressbar at all.
100% (100 of 100) || Elapsed Time: 0:00:10 Time: 0:00:10-

@wolph wolph reopened this Nov 12, 2015
@wolph
Copy link
Owner

wolph commented Nov 12, 2015

That means something is wrong with the width detection... I tested it in several environments and it appeared to work but apparently it's still broken :(

Sorry about that, I'll have a look at it.

@maxnoe
Copy link
Author

maxnoe commented Nov 12, 2015

And on windows I get:
AttributeError: module 'signal' has no attribute 'SIGWINCH'

for

from progressbar import ProgressBar

progress = ProgressBar()

@maxnoe
Copy link
Author

maxnoe commented Nov 12, 2015

Oh, and I think you misunderstood: This is the exact output I posted.
Every time the progressbar was updated a new line was started, because it was slidly wider (1 or a feq charakters) than the line width.

I did not mean, that the last progressbar is wider than the others.

@wolph
Copy link
Owner

wolph commented Nov 12, 2015

That would actually be the effect if the width can't be detected. The bar should automatically resize to the size of your screen. But if your screen is somehow 0 (broken detection code), it makes the bar as small as possible. Regardless, it's significantly broken unfortunately :(

I've removed the release from pypi for the time being and I'll try to update the package soon.

@maxnoe
Copy link
Author

maxnoe commented Nov 13, 2015

Using blessings.Terminal gives me the correct results.

@maxnoe
Copy link
Author

maxnoe commented Nov 13, 2015

Just playing around a bit:

from blessings import Terminal
from time import sleep

t = Terminal()
with t.hidden_cursor():
    for i in range(101):
        percentage = '{:>3d} %'.format(i)
        start = '|'
        end = '|'

        barlength = t.width - (len(percentage) + len(start) + len(end))

        len_progress = max(int(round(barlength * (i/100), 0)) - 1, 0)
        bar = '=' * len_progress
        arrow = '>' if i < 100 else '='
        empty = ' ' * (barlength - len_progress - 1)

        full = percentage + start + bar + arrow + empty + end
        print('\r' + full, end='')
        print(t.move_right(1) + t.clear_eos, end='', flush=True)
        sleep(0.1)

@wolph wolph closed this as completed in 91cef88 Nov 15, 2015
@wolph
Copy link
Owner

wolph commented Nov 15, 2015

Blessings is a very nice module as well, I've added the module as a width detection option for people that have it installed but it still has some detection if it's not available

@wolph
Copy link
Owner

wolph commented Nov 15, 2015

Sorry for the trouble Max, I believe the current release should fix everything.

@maxnoe
Copy link
Author

maxnoe commented Nov 15, 2015

Ah yes. I think you forgot a debug output:

shutil 48 111

An idea: Elapsed Time: ... takes very much space. Could you maybe reduce the number of widgets automatically if the term width is so small, that no progressbar fits any more? First dropping Elapsed Time, than the ETA?

@wolph
Copy link
Owner

wolph commented Nov 15, 2015

Oops... indeed, it's gone now :)

As for collapsing widgets, not impossible to achieve but I'm not sure how to implement that cleanly in the base code. Generally screens are fairly large these days but it's a bit of a waste of screenspace indeed.

I've just pushed out a new release that has support for something along those lines. Give this code a try:

import time
import progressbar

bar = progressbar.ProgressBar(widgets=[
    progressbar.Timer(min_width=200),
    progressbar.Bar(),
])
for i in bar(range(200)):
    time.sleep(0.1)

@wolph
Copy link
Owner

wolph commented Nov 15, 2015

Note that the min_width and max_width settings indicate the width in characters, not pixels. So if the screen is at least 200 characters wide, the Timer will show.

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