Code Monkey home page Code Monkey logo

python-progressbar's People

Contributors

niltonvolpato avatar terencehonles avatar

python-progressbar's Issues

Progressbar should update on a regular interval

Currently the progressbar only updates 100 times, for large progressbars this 
is not nearly enough. I am currently using the script for a queue of about 2 
hours.

To fix this we could modify the _need_update method to change every second 
instead. This should do:

def _need_update(self):
    if self.seconds_elapsed:
        return int(self.seconds_elapsed) != int(time.time() - self.start_time)
    else:
        return True

Original issue reported on code.google.com by Wolphie on 1 Aug 2010 at 3:20

Cannot install with pip

pip3 install progressbar

Collecting progressbar
  Using cached progressbar-2.3.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/private/var/folders/w_/6ddpl57d1hx5m1m_nbhwd3qw0000gn/T/pip-build-3lzw6hbv/progressbar/setup.py", line 5, in <module>
        import progressbar
      File "/private/var/folders/w_/6ddpl57d1hx5m1m_nbhwd3qw0000gn/T/pip-build-3lzw6hbv/progressbar/progressbar/__init__.py", line 59, in <module>
        from progressbar.widgets import *
      File "/private/var/folders/w_/6ddpl57d1hx5m1m_nbhwd3qw0000gn/T/pip-build-3lzw6hbv/progressbar/progressbar/widgets.py", line 121, in <module>
        class FileTransferSpeed(Widget):
      File "/Users/mortenb/Downloads/test/env/bin/../lib/python3.4/abc.py", line 133, in __new__
        cls = super().__new__(mcls, name, bases, namespace)
    ValueError: 'format' in __slots__ conflicts with class variable

    ----------------------------------------
    Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/w_/6ddpl57d1hx5m1m_nbhwd3qw0000gn/T/pip-build-3lzw6hbv/progressbar

Original issue reported on code.google.com by [email protected] on 11 Apr 2015 at 11:16

Update PyPI

The newest version on PyPI is 2.3-dev. This is assumedly not as new as the 2.3 
version here. Note that pip no longer finds binaries from external sites as it 
did when this release was made. 

Original issue reported on code.google.com by [email protected] on 8 Dec 2014 at 4:51

Support for IPython and fancy HTML progress bars in IPython notebook

Made some changes to support running from an ipython qtconsole (requires the \r 
to be at the beginning of the line and the stream to be flushed).

Also added support for rendering widgets as HTML and using javascript to update 
them for use inside an IPython notebook. Falls back to using the regular text. 
Added a fancy jQuery UI based implementation of Bar.

Code available on a feature branch on my github:

https://github.com/fnoble/python-progressbar/tree/ipython_support

Again, if you want to merge and need help then let me know.

Thanks,
Fergus

Original issue reported on code.google.com by [email protected] on 30 Nov 2012 at 9:14

Python 3.3 compatibility - FileTransferSpeed class

The FileTransferSpeed class in widgets.py won't compile in Python 3.3 because 
the __slots__ tuple contains "format" which is a class member. This seems to be 
a new restriction in Python 3.3.

Removing format from __slots_ seems to fix it.

Original issue reported on code.google.com by [email protected] on 21 Sep 2012 at 10:31

Explicitly import __builtin__ instead of __builtins__

Patch included: 
http://code.google.com/r/hongminhee-jython-compat/source/detail?r=143bbef65e9d5e
d38c1edb628ccbd5d6c66835a0

__builtins__ is an implementation detail of CPython and it would be eximplictly 
imported (as instead __builtin__). See the note of the below link:

http://docs.python.org/library/__builtin__.html

Note that this issue had been discussed in the Jython bug tracket once:

http://bugs.jython.org/issue1890

Original issue reported on code.google.com by [email protected] on 11 Jun 2012 at 12:09

Your own examples don't run

What steps will reproduce the problem?
1. virtualenv .
2. source bin/activate
3. pip install progressbar
4. wget http://python-progressbar.googlecode.com/hg/examples.py
5. python examples.py

What is the expected output? What do you see instead?

The expected output is 19 different examples of progress bars.

The actual output is:

    Traceback (most recent call last):
    File "examples.py", line 7, in <module>
        from progressbar import AnimatedMarker, Bar, BouncingBar, Counter, ETA, \
    ImportError: cannot import name AnimatedMarker

What version of the product are you using? On what operating system?

pip installs version 2.2. The operating system is linux mint (an ubuntu 
derivative).

Please provide any additional information below.

My initial attempts to use this library were as simple as:

    python -c 'import time
    from progressbar import ProgressBar          
    progress = ProgressBar()
    for i in progress(range(80)):
      time.sleep(0.01)'

(based on example 19). This does not work:

    Traceback (most recent call last):
      File "<string>", line 5, in <module>
    TypeError: 'ProgressBar' object is not callable

Original issue reported on code.google.com by [email protected] on 25 Feb 2014 at 10:48

ProgressBar.__call__ always calls __len__ even when maxval is already specified

ProgressBar.__call__ also only expects TypeError to be raised as a result of 
calling __len__, when in fact other errors are seen to be raised (e.g. on a 
csv.DictReader this raises an AttributeError). But in general it would be nice 
if there were a (non-hacky) way to force a maxval onto a ProgressBar, 
regardless of the iteratee's len.

Original issue reported on code.google.com by [email protected] on 10 May 2011 at 4:35

__slots__ fail in python 3.3

What steps will reproduce the problem?
1. Install python 3.3
2. python setup.py build

What is the expected output? What do you see instead?

[root@archbuild progressbar-2.3]# python setup.py  build
Traceback (most recent call last):
  File "setup.py", line 5, in <module>
    import progressbar
  File "/build/src/progressbar-2.3/progressbar/__init__.py", line 59, in <module>
    from progressbar.widgets import *
  File "/build/src/progressbar-2.3/progressbar/widgets.py", line 121, in <module>
    class FileTransferSpeed(Widget):
  File "/usr/lib/python3.3/abc.py", line 130, in __new__
    cls = super().__new__(mcls, name, bases, namespace)
ValueError: 'format' in __slots__ conflicts with class variable


What version of the product are you using? On what operating system?
Archlinux with python 3.3

Original issue reported on code.google.com by sebastien.luttringer on 29 Sep 2012 at 8:05

  • Merged into: #21

How to use adaptiveETA when execution time is unknown?

Hi Guys,

I'm running AWS SDK and call API to create instance. The finish time is unknown 
operation, how can I adjust progressbar to accomodate this?

as soon as progress bar reaches the highest value - it crashes with the 
following code:

Traceback (most recent call last):
  File "D:/Projects/devops/development/experiments-elasticbeanstalk.py", line 124, in <module>
    pbar.update(difference)
  File "C:\Programming\Python275\lib\site-packages\progressbar\progressbar.py", line 252, in update
    raise ValueError('Value out of range')
ValueError: Value out of range

my code:
print "Waiting for prod-web-env to launch | " + status
pbar.start()
while status <> "Green":
    ret = conn.describe_environments(application_name='Web', environment_ids=eid)
    status = ret['DescribeEnvironmentsResponse']['DescribeEnvironmentsResult']['Environments'][0]['Health']
    time.sleep(5)
    later = time.time()
    difference = int(later - now)
    pbar.update(difference)
    # I tried this solution to adjust maxval dynamically and increase it to 10% each time we hit 90% of progress - but that didn't work
    if int((difference/pbar.maxval)*100)>90:
        pbar.maxval = pbar.maxval + int(pbar.maxval*0.1)
    if status=="Terminated":
        break


pbar.finish()
if status=="Terminated":
    print "Major problem running the environment"
    exit(1)

Original issue reported on code.google.com by [email protected] on 2 May 2014 at 11:51

Feature Request: a new AnimatedMarker that only animates the "current marker point"

Instead of:
[/////////////////////    ]
[---------------------    ]

It would be nice if it was more like:
[||||||||||||||||||||/    ]
[||||||||||||||||||||-    ]

Where it would update the "current marker" to show "sub marker percent 
completion" relative to the length of markers.
For a simple example, if you have maxval=100, and you have 10 markers (0-9) and 
bar length is 10.
For each val, (let's start at 50) it should increment like so:
[000000    ]
[000001    ]
[000002    ]
...
[000009    ]
[0000000   ]

This would make the Balloon example really cute (as well as being cute in 
general.)

Thanks for your time.

Original issue reported on code.google.com by [email protected] on 24 Jun 2011 at 3:55

Progressbar signal handler for SIGWINCH causes system calls to be interrupted

What steps will reproduce the problem?

1. Install the latest version of euca2ools 3.0.0 available here: 
https://github.com/eucalyptus/euca2ools/tree/requestbuilder
2. Use the euca-bundle-vol tool (which uses progressbar)
3. Attempt to resize the terminal window during tarball bundling

What is the expected output? What do you see instead?

I expect to see the progressbar resized properly, but instead an IOError 
exception is raised with EINTR, since the write system call is being 
interrupted by the signal handler for SIGWINCH.

Here's the exception output below:

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 

tune2fs 1.42.3 (14-May-2012)
  done
Syncing volume contents...  done
euca-bundle-vol: error: Interrupted system call                                 
Exception in thread Thread-2:                     | 718.55 MB  35.40 MB/s ETA:  
Traceback (most recent call last):
  File "/usr/lib64/python2.7/threading.py", line 551, in __bootstrap_inner
    self.run()
  File "/usr/lib64/python2.7/threading.py", line 504, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/lib/python2.7/site-packages/euca2ools-3.0.0_alpha6-py2.7.egg/euca2ools/commands/bundle/bundle.py", line 187, in _add_fileobj_to_tarball
    tarball.close()
  File "/usr/lib64/python2.7/tarfile.py", line 1776, in close
    self.fileobj.write(NUL * (BLOCKSIZE * 2))
  File "/usr/lib64/python2.7/tarfile.py", line 471, in write
    self.__write(s)
  File "/usr/lib64/python2.7/tarfile.py", line 479, in __write
    self.fileobj.write(self.buf[:self.bufsize])
IOError: [Errno 32] Broken pipe

Exception IOError: (32, 'Broken pipe') in <bound method _Stream.__del__ of 
<tarfile._Stream instance at 0x29673f8>> ignored
Bundling image 100% |======================|  10.00 GB 503.30 MB/s Time: 0:00:21
euca-bundle-vol: error: 
[root@i euca2ools]# 


What version of the product are you using? On what operating system?

I'm using progressbar 0.9.8 on CentOS 6.4

Please provide any additional information below.

I've attached a patch that fixes the issue. After installing the signal 
handler, progressbar should then set the SA_RESTART flag so that system calls 
are restarted after the signal handler executes.

Original issue reported on code.google.com by [email protected] on 16 May 2013 at 4:46

Attachments:

Adaptive ETA

I just discovered this project and really like it.

I had one quibble though, which is that the I found that the ETA doesn't adapt 
very well if progress speeds up or slows down. I made my own AdaptiveETA class 
that does this and wondered if it was something that you might want to include 
in the project (see the attached file).

The AdaptiveETA uses two different ETA estimates, one base on the total 
progress so far and one based on the progress during the most recent update 
reports. The reported ETA is a weighted average of these two where the weight 
depends on the how much progress has been made. When not much progress has been 
made. At the start the ETA will reflect the total rate of progress so far. At 
the end the ETA will only reflect the recent rate of progress.

Thanks,
Oscar

Original issue reported on code.google.com by [email protected] on 27 Sep 2012 at 10:34

Attachments:

RFE: Support progress bar with undefined ends

It would be convenient if this progress measuring tool will be able to display 
progress of processes with undefined end.

Example of such process is calculating statistics on very big CSV table from 
file---when time of measuring number of items is big and almost equal to time 
of processing. It is impossible to estimate running time on such processes but 
it would be very useful to see number of processed items, rotating marker and 
current running time.

Thanks,

Vladimir Rutsky

Original issue reported on code.google.com by [email protected] on 17 Sep 2010 at 4:16

Does not work with py2exe

What steps will reproduce the problem?
Tried to build windows executable with py2exe

What is the expected output? What do you see instead?
Py2exe generates the following warning:
The following modules appear to be missing
['_scproxy', 'chardet', 'cjkcodecs.aliases', 'iconv_codec', 'progressbar']

Generated program stops with:

Traceback (most recent call last):
  File "autoparser.py", line 1, in <module>
ImportError: No module named progressbar

What version of the product are you using? On what operating system?
progressbar 2.3, Python 2.7



Original issue reported on code.google.com by [email protected] on 15 Oct 2011 at 10:45

Include Changelog.yaml in the released tarballs

Hello,
it would be really nice to have the Changelog.yaml in the released tarballs, so 
that us packagers (in particular for Debian) can include that file in the 
packages we prepare.

Thanks for considering,
Sandro

Original issue reported on code.google.com by sandro.tosi on 22 Oct 2013 at 9:38

Progress bar does not work in ipython notebook due to '\r' issued _after_ output string

What steps will reproduce the problem?

The following simple example will not work in ipython notebook:

  from progressbar import ProgressBar
  import time
  pbar = ProgressBar()
  for i in pbar(range(0,10000)):
    time.sleep(0.001)

Instead of updating the progressbar, it will only show the result when the 
progress has reached 100%.

What is the expected output? What do you see instead?

Instead, the progressbar should be updated every time in the loop. This can be 
trivially achieved by changing the line 238 in progressbar/__init__.py from

  self.fd.write(self._format_line() + 'r' )

to 

  self.fd.write('\r' + self._format_line() )


What version of the product are you using? On what operating system?
ipython 0.13 (+Chrome)
progressbar 2.2

Original issue reported on code.google.com by [email protected] on 27 Nov 2012 at 9:49

  • Merged into: #27

division by zero error

What steps will reproduce the problem?
1. pbar.update(0) 
2.
3.

What is the expected output? What do you see instead?

exception at least... because i couldn't understand what goes on

What version of the product are you using? On what operating system?

freebsd8

Please provide any additional information below.

Well I think exceptions is a must to inform user about his mistake.. this is 
quite common error I belive... 
maybe it's lame to say so but.. this will save like 2 minutes for debugging :)

Original issue reported on code.google.com by [email protected] on 16 Mar 2012 at 2:50

Doesn't work on google app engine

I think this "issue" has more to do with app engine than the code itself. 
I mean, I can see the progress but only when it's finished, so it's kind 
of useless.

Thanks anyway!

Cheers,
Fred

Original issue reported on code.google.com by [email protected] on 16 Mar 2009 at 7:08

Using ProgressBar as iterator from empty iterable causes traceback

progressbar==2.3
Ubuntu 13.04


So this works:

for n in progressbar.ProgressBar()([1]):
    print n

It will print 1 and all the progress information as expected.

But

for n in progressbar.ProgressBar()([]):
    print n

gives traceback as follows:


AttributeError                            Traceback (most recent call last)
<ipython-input-4-bf738fc09ad4> in <module>()
----> 1 for n in progressbar.ProgressBar()([]):
      2     print n
      3 

/home/tcorbettclark/.virtualenvs/ice/local/lib/python2.7/site-packages/progressb
ar/__init__.pyc in __next__(self)
    182             return value
    183         except StopIteration:
--> 184             self.finish()
    185             raise
    186 

/home/tcorbettclark/.virtualenvs/ice/local/lib/python2.7/site-packages/progressb
ar/__init__.pyc in finish(self)
    318 
    319         self.finished = True
--> 320         self.update(self.maxval)
    321         self.fd.write('\n')
    322         if self.signal_set:

/home/tcorbettclark/.virtualenvs/ice/local/lib/python2.7/site-packages/progressb
ar/__init__.pyc in update(self, value)
    274 
    275 
--> 276         if not self._need_update(): return
    277         if self.start_time is None:
    278             raise RuntimeError('You must call "start" before calling "update"')

/home/tcorbettclark/.virtualenvs/ice/local/lib/python2.7/site-packages/progressb
ar/__init__.pyc in _need_update(self)
    249     def _need_update(self):
    250         'Returns whether the ProgressBar should redraw the line.'
--> 251         if self.currval >= self.next_update or self.finished: return 
True
    252 
    253         delta = time.time() - self.last_update_time

AttributeError: next_update

Original issue reported on code.google.com by [email protected] on 13 Apr 2014 at 11:41

ZeroDvisionError

I'm getting a ZeroDivisionError from line 208 in progressbar/__init__.py. This 
happens in 2.3, possibly because I'm trying to set the progress to 0. 

Original issue reported on code.google.com by [email protected] on 15 Jul 2011 at 10:24

python 3.3 import errors

When trying to install from the mercurial tip (changeset 36:3c94a3a1ebe1 from 
September 21), I get the following error:

     Traceback (most recent call last):
      File "setup.py", line 5, in <module>
        import progressbar
      File "/usr/local/src/python-progressbar/progressbar/__init__.py", line 47, in <module>
        from compat import *
    ImportError: No module named 'compat'

This is because the imports aren't relative to the current package. Changing 
the imports in __init__.py to 

     from .compat import *

and so on works, as would `from progressbar.compat`.

I also needed to change `import widgets` to `from . import widgets` in 
`progressbar.py`. Then everything worked.

Also note that the version in pypi (2.3-dev) still has the `__slots__` problem 
that was fixed back in September - it'd be nice to release a new version with 
these two problems fixed, so `pip install progressbar` works.

Original issue reported on code.google.com by [email protected] on 17 Dec 2012 at 1:31

ProgressBar __init__ function uses same default widget list for all instances

What steps will reproduce the problem?

Python 2.6.2 (r262:71600, Apr 18 2009, 06:27:57) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from progressbar import *
>>> p1 = ProgressBar()
>>> print len(p1.widgets)
3
>>> p1.widgets.append(ETA())
>>> print len(p1.widgets)
4
>>> p2 = ProgressBar()
>>> print len(p2.widgets)
4

What is the expected output? What do you see instead?

I would expect that individual ProgressBar objects would not share widget
lists. I think the problem is that you are setting a default value for the
widgets list in the argument list of ProgressBar.__init__, and this ends up
passing the same widgets list instance to all ProgressBar objects.

See for example,

http://www.ferg.org/projects/python_gotchas.html#contents_item_6

What version of the product are you using? On what operating system?

version 2.2, from http://pypi.python.org/pypi/progressbar. This problem
should exist for all operating systems and all python versions.

Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 9 Jun 2009 at 11:35

Display both the current file number and the transfer speed

What steps will reproduce the problem?
1. Set maxval to the total number of bytes being downloaded
2. Set up the FileTransferSpeed widget
3. Set up the SimpleProgress widget to display the number of the current file 
being downloaded

What is the expected output? What do you see instead?
I wanted to have this sort of output:
Downloading file 7 of 535 100% |||||||||||||| Time: 00:00:41  1.95 MB/s

But I can only get this sort of output:
Downloading file 7 of 10979307 100% ||||||||| Time: 00:00:41  1.95 MB/s

What version of the product are you using? On what operating system?
OS: Tested on both Windows 7 and Ubuntu Linux 10.04 LTS
ProgressBar Version: progressbar-2.3-dev

Please provide any additional information below.
N/A

Original issue reported on code.google.com by [email protected] on 28 Dec 2010 at 11:36

ETA() does not update to Time upon finishing

The ETA() is supposed to switch to total time spent after the ProgressBar() is 
finished. However, this does not happen because there is no update of the text. 
(Similarly, the RotatingMarker() should go to | but this too is not updated.)

The reason for the lack of update is that _need_update() returns
         return self.currval >= self.next_update
whereas it should be:
         return self.currval >= self.next_update or self.finished

*** What is the expected output? What do you see instead? ***

Using the following code:
x = []
for y in withProgress(range(10**6), 
pbar=StandardProgressBar(title='squaring...')):
    x.append(y**2)

The output is:
squaring...\ 100% |=============================================| ETA:  00:00:00

The expected output (obtained with the above fix) is:

squaring...| 100% |=============================================| Time: 00:00:04


*** What version of the product are you using? On what operating system? ***
Python 2.7, progressbar 2.3-dev, Mac OSX and Linux (Fedora Core 12)

Original issue reported on code.google.com by [email protected] on 18 Apr 2011 at 9:11

Adding code to support a formatter function for the counter

What steps will reproduce the problem?
1. There is no problem to reproduce.

What is the expected output? What do you see instead?
There is no output expected yet.

What version of the product are you using? On what operating system?
progressbar-2.3.tar.gz

Please provide any additional information below.

I'm writing code that counts drive space in bytes and I have a function to 
convert bytes to KB, MB, GB, etc. The progress Counter() only counts bytes and 
the "format" argument is not sophisticated enough for deciding KB/MB/etc. 
Adding code to format the counter would be very useful for me.

I have made a clone and some changes if you would like to pull and/or alter 
them:
http://code.google.com/r/tstone2077-counter-formatter-func/

Original issue reported on code.google.com by [email protected] on 28 Oct 2011 at 6:56

Feature Request: Progressbar for collections and iterators of fixed size

This is very much a question of subjective taste, but about 95% of the time I 
use progressbar (which is a great library by the way), it is with a list or 
with an iterator who's size I know beforehand. And so, I always wind up writing 
the same 3/4 lines to set up my progress bar.

I have attached a mercurial patch that adds a function to progressbar.py called 
fixed_bar, which does exactly that. Would really appreciate it if you would 
merge them in.

Original issue reported on code.google.com by [email protected] on 15 Nov 2013 at 8:39

Attachments:

Division by zero in `ProgressBar.percentage`

It would be nice if this division by zero was avoided:

diff --git a/progressbar/progressbar.py b/progressbar/progressbar.py
--- a/progressbar/progressbar.py
+++ b/progressbar/progressbar.py
@@ -184,7 +184,7 @@

     def percentage(self):
         """Returns the progress as a percentage."""
-        if self.currval >= self.maxval:
+        if self.currval >= self.maxval or self.maxval == 0:
             return 100.0
         return self.currval * 100.0 / self.maxval

Original issue reported on code.google.com by [email protected] on 8 Aug 2014 at 6:57

update value one step ahead

What steps will reproduce the problem?
Consider the following piece of code:

from progressbar import *
import time
pbar = ProgressBar(widgets=[Percentage(), Bar(), ETA()])
for i in pbar(range(3)):
    time.sleep(2)


What is the expected output? What do you see instead?
I would expect to start at 0%, then display 33% after t=2s, 66% at t=4s and 
finally 100% at t=6, which is also the end of the program.
Instead, it starts at 33%, displays 66% at t=2s, 100% at t=4s and returns at 
t=6s....


What version of the product are you using? On what operating system?
Using v2.3 on linux with python 2.6

Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 23 Nov 2010 at 8:20

Update progress more often (echoing https://github.com/olivierverdier/python-progressbar/pull/1)

Hello,
if you're maxvalues is big, updates in the progress bar happen only at 
"discrete" interval, so when we reach 1%, 2%, and so on.

I noticed this issue on github: 
https://github.com/olivierverdier/python-progressbar/pull/1 (and its relative 
pull request: 
https://github.com/wonderfulll/python-progressbar/commit/a6f92b81ab6e7ea67029486
62d99ff16663d63df ) that should fix this problem, introducing an optional value 
to Start().

Please consider merging it.

Thanks,
Sandro

Original issue reported on code.google.com by matrixhasu on 1 Dec 2011 at 4:09

Update progressbar without printing newline

How can I update current progress bar without progress bar being printed into a 
new line every time?

I've read about ProgressBarWidgetHFill.

How can I use this widget? I found nothing in code examples.

Original issue reported on code.google.com by [email protected] on 14 Aug 2013 at 3:19

'Attributes' feature implemented

I have implemented a feature allowing ProgressBar to hold a dictionary of 
'attributes' that can be updated when calling ProgressBar.update.

These attributes can then be accessed from within widgets to display 
information other than just a simple progress indication e.g. current filename.

I have also implemented a generic Attribute widget that takes a format string 
and displays a number of attributes accordingly.

There is an example in examples.py

Code available on a feature branch on my github:

https://github.com/fnoble/python-progressbar/tree/attributes

It would be wonderful to have this merged upstream, if you would like to do so 
then please let me know if you would like me to make any alterations or if you 
need me to move this from git to mercurial.

Thanks,
Fergus

Original issue reported on code.google.com by [email protected] on 30 Nov 2012 at 9:09

Windows terminal size

Hi,

The library uses the wrong terminal width on windows so here is some code for 
finding it:


def get_windows_term_width():
    from ctypes import windll, create_string_buffer
    h = windll.kernel32.GetStdHandle(-12)
    csbi = create_string_buffer(22)
    res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
    if res:
        import struct
        (bufx, bufy, curx, cury, wattr,
         left, top, right, bottom, maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
        sizex = right - left + 1
    else:
        sizex = 80
    return sizex

Your library really rocks btw!

Original issue reported on code.google.com by [email protected] on 30 May 2011 at 9:02

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.