예제 #1
0
    def __init__(self, total=None, verbose=True, is_lying=False):
        """
        Initializes the progress bar.

        :param total: The total amount of units. If None, a general progress bar will be printed.
        :param verbose: If True, the progress bar will be printed to the screen after every eval call.
        :param is_lying: If True, this is a lying progress bar and you shouldn't believe it!
        """
        self._is_lying = is_lying
        self._verbose = verbose
        self.total = total
        self._width = get_console_width() - self._METERS_LEN
        self._start_time = time.time()
        if total is not None and total > 0:
            meters = [Bar(total), Percentage(total)]
        else:
            meters = [Animated(n_per_cycle=10000)]
        meters.append(Timing(total))
        super(ProgressBar, self).__init__(meters)
예제 #2
0
파일: table.py 프로젝트: ofir123/py-printer
    def _get_pretty_table(self,
                          indent: int = 0,
                          align: int = ALIGN_CENTER,
                          border: bool = False) -> PrettyTable:
        """
        Returns the table format of the scheme, i.e.:

            <table name>
        +----------------+----------------
        |    <field1>    |   <field2>...
        +----------------+----------------
        | value1(field1) |  value1(field2)
        | value2(field1) |  value2(field2)
        | value3(field1) |  value3(field2)
        +----------------+----------------
        """
        rows = self.rows
        columns = self.columns
        # Add the column color.
        if self._headers_color != Printer.NORMAL and len(rows) > 0 and len(
                columns) > 0:
            # We need to copy the lists so that we wont insert colors in the original ones.
            rows[0] = rows[0][:]
            columns = columns[:]
            columns[0] = self._headers_color + columns[0]
            # Write the table itself in NORMAL color.
            rows[0][0] = Printer.NORMAL + str(rows[0][0])

        table = PrettyTable(columns,
                            border=border,
                            max_width=get_console_width() - indent)
        table.align = self._ALIGN_DICTIONARY[align]

        for row in rows:
            table.add_row(row)

        # Set the max width according to the columns size dict, or by default size limit when columns were not provided.
        for column, max_width in self._column_size_map.items():
            table.max_width[column] = max_width

        return table
예제 #3
0
파일: table.py 프로젝트: ofir123/PyPrinter
    def _get_pretty_table(self, indent=0, align=ALIGN_CENTER, border=False):
        """
        Returns the table format of the scheme, i.e.:

            <table name>
        +----------------+----------------
        |    <field1>    |   <field2>...
        +----------------+----------------
        | value1(field1) |  value1(field2)
        | value2(field1) |  value2(field2)
        | value3(field1) |  value3(field2)
        +----------------+----------------
        """
        rows = self.rows_list
        columns = self.columns
        # Adding the column color.
        if len(columns) > 0 and self._headers_color != pyprinter.Printer.NORMAL and len(rows) > 0 and len(rows[0]) > 0:
            # We need to copy the lists so that we wont insert colors in the original ones.
            rows[0] = rows[0][:]
            columns = columns[:]
            columns[0] = self._headers_color + columns[0]
            # Write the table itself in NORMAL color.
            rows[0][0] = pyprinter.Printer.NORMAL + str(rows[0][0])

        table = prettytable.PrettyTable(columns, border=border, max_width=pyprinter.get_console_width() - indent)
        table.align = self._ALIGN_DICTIONARY[align]

        for row in rows:
            table.add_row(row)
        # Set the max width according to the columns size dict, or by default size limit when columns were not provided.
        if len(self._columns.keys()) != 0:
            for column, max_width in self._columns.items():
                table.max_width[column] = max_width
        else:
            for column in columns:
                table.max_width[column] = self._column_size_limit
        return table