def bar(self): """ :rtype: str """ if self.total == 0 or self.amount is None or self.total is None: full_part_len = 0 partial_character = '' else: bar_length = self.amount*self._bar_length / self.total full_part_len = floor(bar_length) partial_part = bar_length - full_part_len if full_part_len < bar_length: partial_character = self._bar_characters[round(partial_part*(len(self._bar_characters)-1))] else: partial_character = '' empty_part_len = self._bar_length - full_part_len - len(partial_character) full_part_text = self._bar_characters[-1] * full_part_len + partial_character empty_part_text = self._bar_characters[0] * empty_part_len if self._full_colour is not None: character = 'РќЁ' # character = self._bar_empty full_part = colour(text=full_part_text, text_colour=self._full_colour) empty_part = colour(text=empty_part_text, text_colour=self._empty_colour) else: full_part = full_part_text empty_part = empty_part_text return full_part + empty_part
def format_bar(self, amount): """ :type amount: int or float :rtype: str """ amount = min(amount, self._total) full_part_len = round(amount*self._bar_length/self._total) empty_part_len = self._bar_length - full_part_len if self._full_colour is not None: character = 'РќЁ' # character = self._bar_empty full_part = colour(text=character * full_part_len, text_colour=self._full_colour) empty_part = colour(text=character * empty_part_len, text_colour=self._empty_colour) else: full_part = self._bar_full * full_part_len empty_part = self._bar_empty * empty_part_len return full_part + empty_part
def show(self, amount, percent=True, bar=True, time=True, text=''): """ :type amount: int or float :type percent: bool :type bar: bool :type time: bool :type text: str """ string = '' length = 0 animation = self.animation; length += len(animation) string += colour(text=animation, text_colour=self._empty_colour) if time: remaining = self.get_remaining_seconds(amount=amount) elapsed = self.get_elapsed_seconds() elapsed_text = f'e:{self.format_time(elapsed)} '.ljust(10) remaining_text = f'r:{self.format_time(remaining)} '.ljust(10) string += colour(text=elapsed_text, text_colour=self._full_colour) string += colour(text=remaining_text, text_colour=self._empty_colour) length += len(elapsed_text) + len(remaining_text) if bar: bar_coloured = self.format_bar(amount=amount) string += bar_coloured length += self._bar_length if percent: percent_text = (' ' + self.format_percent(amount=amount)).rjust(8) string += colour(text=percent_text, text_colour=self._full_colour) length += len(percent_text) string += ' ' + colour(text=text, text_colour=self._text_colour) length += 1 + len(text) if self._max_length < length: self._max_length = length padding = ' '*(self._max_length-length) self.write(string=string+padding) stdout.flush() if amount == self._total: self.complete() if self._next_line and self._completed: print('')
def _get_text_string(self, text): text_text = f' {text}' self._max_lengths['text'] = max(self._max_lengths['text'], len(text_text)) text_text = text_text.ljust(self._max_lengths['text']) return colour(text=text_text, text_colour=self._text_colour)
def _percent_string(self): percent_text = f' {self.percent_formatted}' self._max_lengths['percent'] = max(self._max_lengths['percent'], len(percent_text)) percent_text = percent_text.rjust(self._max_lengths['percent']) return colour(text=percent_text, text_colour=self._full_colour)
def _remaining_time_string(self): remaining_text = f'r:{self.format_time(self.remaining_seconds)} ' self._max_lengths['remaining'] = max(self._max_lengths['remaining'], len(remaining_text)) remaining_text = remaining_text.ljust(self._max_lengths['remaining']) return colour(text=remaining_text, text_colour=self._empty_colour)
def _elapsed_time_string(self): elapsed_text = f'e:{self.format_time(self.elapsed_seconds)} ' self._max_lengths['elapsed'] = max(self._max_lengths['elapsed'], len(elapsed_text)) elapsed_text = elapsed_text.ljust(self._max_lengths['elapsed']) return colour(text=elapsed_text, text_colour=self._full_colour)
def _animation_string(self): animation = self.animation self._max_lengths['animation'] = max(self._max_lengths['animation'], len(animation)) return colour(text=animation.ljust(self._max_lengths['animation']), text_colour=self._empty_colour)