Created
February 19, 2012 01:42
-
-
Save livibetter/1861570 to your computer and use it in GitHub Desktop.
Making useful of REE. ^_*
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # -*- coding: utf-8 -*- | |
| # Copyright (c) 2012 Yu-Jie Lin | |
| # Copyright (c) 2005 Nilton Volpato | |
| # | |
| # This library is free software; you can redistribute it and/or | |
| # modify it under the terms of the GNU Lesser General Public | |
| # License as published by the Free Software Foundation; either | |
| # version 2.1 of the License, or (at your option) any later version. | |
| # | |
| # This library is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| # Lesser General Public License for more details. | |
| # | |
| # You should have received a copy of the GNU Lesser General Public | |
| # License along with this library; if not, write to the Free Software | |
| # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
| import time | |
| from progressbar import Bar, FormatLabel, ProgressBar, RotatingMarker | |
| def REE_example(): | |
| def format_updatable(updatable, pbar): | |
| if hasattr(updatable, 'update'): return updatable.update(pbar) | |
| else: return updatable | |
| class MyBouncingBar(Bar): | |
| def update(self, pbar, width): | |
| 'Updates the progress bar and its subcomponents' | |
| left, marker, right = (format_updatable(i, pbar) for i in | |
| (self.left, self.marker, self.right)) | |
| width -= len(left) + len(right) | |
| if pbar.finished: return '%s%s%s' % (left, width * '|', right) | |
| width -= len(marker) - 1 | |
| position = int(pbar.currval % (width * 2 - 1)) | |
| if position > width: position = width * 2 - position | |
| lpad = self.fill * (position - 1) | |
| rpad = self.fill * (width - len(marker) - len(lpad) + (len(marker) - 1)) | |
| # Swap if we want to bounce the other way | |
| if not self.fill_left: rpad, lpad = lpad, rpad | |
| return '%s%s%s%s%s' % (left, lpad, marker, rpad, right) | |
| widgets = [FormatLabel('Animated REE Bouncer: value %(value)d - '), | |
| MyBouncingBar(marker=RotatingMarker(markers=('>_>', 'v_v', '<_<', '^_^')))] | |
| pbar = ProgressBar(widgets=widgets) | |
| for i in pbar((i for i in range(180))): | |
| time.sleep(0.05) | |
| if __name__ == '__main__': | |
| REE_example() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python-progressbar: http://code.google.com/p/python-progressbar/
REE: https://github.com/livibetter/REE
Screencast: http://youtu.be/goeZaYERNnM