예제 #1
0
    def __call__(self, progress, data, width):
        '''Updates the progress bar and its subcomponents'''

        left = converters.to_unicode(self.left(progress, data, width))
        right = converters.to_unicode(self.right(progress, data, width))
        width -= progress.custom_len(left) + progress.custom_len(right)
        marker = converters.to_unicode(self.marker(progress, data, width))

        fill = converters.to_unicode(self.fill(progress, data, width))

        if width:  # pragma: no branch
            value = int(
                data['total_seconds_elapsed'] / self.INTERVAL.total_seconds())

            a = value % width
            b = width - a - 1
            if value % (width * 2) >= width:
                a, b = b, a

            if self.fill_left:
                marker = a * fill + marker + b * fill
            else:
                marker = b * fill + marker + a * fill

        return left + marker + right
예제 #2
0
    def __call__(self, progress, data, width):
        '''Updates the progress bar and its subcomponents'''

        left = converters.to_unicode(self.left(progress, data, width))
        right = converters.to_unicode(self.right(progress, data, width))
        width -= progress.custom_len(left) + progress.custom_len(right)
        marker = converters.to_unicode(self.marker(progress, data, width))
        fill = converters.to_unicode(self.fill(progress, data, width))

        if self.fill_left:
            marker = marker.ljust(width, fill)
        else:
            marker = marker.rjust(width, fill)

        return left + marker + right
예제 #3
0
    def __call__(self, progress, data, width):
        '''Updates the progress bar and its subcomponents'''

        left = converters.to_unicode(self.left(progress, data, width))
        right = converters.to_unicode(self.right(progress, data, width))
        width -= progress.custom_len(left) + progress.custom_len(right)
        marker = converters.to_unicode(self.marker(progress, data, width))
        fill = converters.to_unicode(self.fill(progress, data, width))

        if self.fill_left:
            marker = marker.ljust(width, fill)
        else:
            marker = marker.rjust(width, fill)

        return left + marker + right
예제 #4
0
    def _format_widgets(self):
        result = []
        expanding = []
        width = self.term_width
        data = self.data()

        for index, widget in enumerate(self.widgets):
            if isinstance(widget, widgets.WidgetBase) \
                    and not widget.check_size(self):
                continue
            elif isinstance(widget, widgets.AutoWidthWidgetBase):
                result.append(widget)
                expanding.insert(0, index)
            elif isinstance(widget, six.string_types):
                result.append(widget)
                width -= self.custom_len(widget)
            else:
                widget_output = converters.to_unicode(widget(self, data))
                result.append(widget_output)
                width -= self.custom_len(widget_output)

        count = len(expanding)
        while expanding:
            portion = max(int(math.ceil(width * 1. / count)), 0)
            index = expanding.pop()
            widget = result[index]
            count -= 1

            widget_output = widget(self, data, portion)
            width -= self.custom_len(widget_output)
            result[index] = widget_output

        return result
예제 #5
0
    def _format_widgets(self):
        result = []
        expanding = []
        width = self.term_width
        data = self.data()

        for index, widget in enumerate(self.widgets):
            if isinstance(widget, widgets.AutoWidthWidgetBase):
                result.append(widget)
                expanding.insert(0, index)
            elif isinstance(widget, six.string_types):
                result.append(widget)
                width -= self.custom_len(widget)
            else:
                widget_output = converters.to_unicode(widget(self, data))
                result.append(widget_output)
                width -= self.custom_len(widget_output)

        count = len(expanding)
        while expanding:
            portion = max(int(math.ceil(width * 1. / count)), 0)
            index = expanding.pop()
            widget = result[index]
            count -= 1

            widget_output = widget(self, data, portion)
            width -= self.custom_len(widget_output)
            result[index] = widget_output

        return result
예제 #6
0
    def __call__(self, progress, data, width):
        '''Updates the progress bar and its subcomponents'''

        left = converters.to_unicode(self.left(progress, data, width))
        right = converters.to_unicode(self.right(progress, data, width))
        width -= progress.custom_len(left) + progress.custom_len(right)
        marker = converters.to_unicode(self.marker(progress, data, width))
        fill = converters.to_unicode(self.fill(progress, data, width))

        # Make sure we ignore invisible characters when filling
        width += len(marker) - progress.custom_len(marker)

        if self.fill_left:
            marker = marker.ljust(width, fill)
        else:
            marker = marker.rjust(width, fill)

        return left + marker + right
예제 #7
0
    def update(self, *args, **kwargs):
        ProgressBarMixinBase.update(self, *args, **kwargs)

        line = converters.to_unicode(self._format_line())
        if not self.enable_colors:
            line = utils.no_color(line)

        if self.line_breaks:
            line = line.rstrip() + '\n'
        else:
            line = '\r' + line

        self.fd.write(line)
def test_markers(name, markers, as_unicode):
    if as_unicode:
        markers = converters.to_unicode(markers)
    else:
        markers = converters.to_str(markers)

    widgets = [
        '%s: ' % name.capitalize(),
        progressbar.AnimatedMarker(markers=markers),
    ]
    pbar = progressbar.ProgressBar(widgets=widgets)
    for i in pbar((i for i in range(24))):
        time.sleep(0.001)
예제 #9
0
def test_markers(name, markers, as_unicode):
    if as_unicode:
        markers = converters.to_unicode(markers)
    else:
        markers = converters.to_str(markers)

    widgets = [
        '%s: ' % name.capitalize(),
        progressbar.AnimatedMarker(markers=markers),
    ]
    bar = progressbar.ProgressBar(widgets=widgets)
    bar._MINIMUM_UPDATE_INTERVAL = 1e-12
    for i in bar((i for i in range(24))):
        time.sleep(0.001)
예제 #10
0
def create_marker(marker):
    def _marker(progress, data, width):
        if progress.max_value is not base.UnknownLength \
                and progress.max_value > 0:
            length = int(progress.value / progress.max_value * width)
            return (marker * length)
        else:
            return marker

    if isinstance(marker, six.string_types):
        marker = converters.to_unicode(marker)
        assert len(marker) == 1, 'Markers are required to be 1 char'
        return _marker
    else:
        return marker
예제 #11
0
def create_marker(marker, wrap=None):
    def _marker(progress, data, width):
        if progress.max_value is not base.UnknownLength and progress.max_value > 0:
            length = int(progress.value / progress.max_value * width)
            return marker * length
        else:
            return marker

    if isinstance(marker, six.string_types):
        marker = converters.to_unicode(marker)
        assert utils.len_color(
            marker) == 1, "Markers are required to be 1 char"
        return wrapper(_marker, wrap)
    else:
        return wrapper(marker, wrap)
예제 #12
0
파일: widgets.py 프로젝트: muma378/moose
def create_marker(marker):
    def _marker(progress, data, width):
        if progress.max_value is not base.UnknownLength \
                and progress.max_value > 0:
            length = int(progress.value / progress.max_value * width)
            return (marker * length)
        else:
            return marker

    if isinstance(marker, six.string_types):
        marker = converters.to_unicode(marker)
        assert len(marker) == 1, 'Markers are required to be 1 char'
        return _marker
    else:
        return marker
예제 #13
0
    def update(self, *args, **kwargs):
        ProgressBarMixinBase.update(self, *args, **kwargs)

        line = converters.to_unicode(self._format_line())
        if not self.enable_colors:
            line = utils.no_color(line)

        if self.line_breaks:
            line = line.rstrip() + '\n'
        else:
            line = '\r' + line

        try:  # pragma: no cover
            self.fd.write(line)
        except UnicodeEncodeError:  # pragma: no cover
            self.fd.write(line.encode('ascii', 'replace'))
예제 #14
0
 def _to_unicode(cls, args):
     for arg in args:
         yield converters.to_unicode(arg)
예제 #15
0
 def _to_unicode(cls, args):
     for arg in args:
         yield converters.to_unicode(arg)
예제 #16
0
 def update(self, *args, **kwargs):
     ProgressBarMixinBase.update(self, *args, **kwargs)
     line = converters.to_unicode('\r' + self._format_line())
     self.fd.write(line)
예제 #17
0
 def _convert(item):
     if isinstance(item, list):
         return [utils.to_unicode(i.value) for i in item]
     if item.filename:
         return MultipartFile(item)
     return utils.to_unicode(item.value)
예제 #18
0
 def __init__(self, storage):
     self.filename = utils.to_unicode(storage.filename)
     self.file = storage.file
예제 #19
0
 def update(self, *args, **kwargs):
     ProgressBarMixinBase.update(self, *args, **kwargs)
     line = converters.to_unicode('\r' + self._format_line())
     self.fd.write(line)