diff options
Diffstat (limited to 'urwid/graphics.py')
-rwxr-xr-x | urwid/graphics.py | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/urwid/graphics.py b/urwid/graphics.py index cb852b0..a40f1ba 100755 --- a/urwid/graphics.py +++ b/urwid/graphics.py @@ -20,6 +20,9 @@ # # Urwid web site: http://excess.org/urwid/ +from __future__ import division, print_function + +from urwid.compat import with_metaclass from urwid.util import decompose_tagmarkup, get_encoding_mode from urwid.canvas import CompositeCanvas, CanvasJoin, TextCanvas, \ CanvasCombine, SolidCanvas @@ -192,9 +195,7 @@ def nocache_bargraph_get_data(self, get_data_fn): class BarGraphError(Exception): pass -class BarGraph(Widget): - __metaclass__ = BarGraphMeta - +class BarGraph(with_metaclass(BarGraphMeta, Widget)): _sizing = frozenset([BOX]) ignore_focus = True @@ -481,7 +482,8 @@ class BarGraph(Widget): o = [] r = 0 # row remainder - def seg_combine((bt1, w1), (bt2, w2)): + def seg_combine(a, b): + (bt1, w1), (bt2, w2) = a, b if (bt1, w1) == (bt2, w2): return (bt1, w1), None, None wmin = min(w1, w2) @@ -811,6 +813,28 @@ class ProgressBar(Widget): foreground of satt corresponds to the normal part and the background corresponds to the complete part. If satt is ``None`` then no smoothing will be done. + + >>> pb = ProgressBar('a', 'b') + >>> pb + <ProgressBar flow widget> + >>> print(pb.get_text()) + 0 % + >>> pb.set_completion(34.42) + >>> print(pb.get_text()) + 34 % + >>> class CustomProgressBar(ProgressBar): + ... def get_text(self): + ... return u'Foobar' + >>> cpb = CustomProgressBar('a', 'b') + >>> print(cpb.get_text()) + Foobar + >>> for x in range(101): + ... cpb.set_completion(x) + ... s = cpb.render((10, )) + >>> cpb2 = CustomProgressBar('a', 'b', satt='c') + >>> for x in range(101): + ... cpb2.set_completion(x) + ... s = cpb2.render((10, )) """ self.normal = normal self.complete = complete @@ -915,3 +939,10 @@ class PythonLogo(Widget): """ fixed_size(size) return self._canvas + +def _test(): + import doctest + doctest.testmod() + +if __name__=='__main__': + _test() |