示例#1
0
    def process_bar(self, done, block, total, mode=1):
        """
        Draw `Process Bar` at the bottom which is used to indicate progress of
        downloading operation.

        .. note:: This method is a callback function responses to
            :meth:`urllib.urlretrieve` method while fetching hosts data
            file.

        :param done: Block count of packaged retrieved.
        :type done: int
        :param block: Block size of the data pack retrieved.
        :type block: int
        :param total: Total size of the hosts data file.
        :type total: int
        :param mode: A flag indicating the status of `Process Bar`.
            The default value of `mode` is `1`.

            ====  ====================================
            mode  `Process Bar` status
            ====  ====================================
            1     Downloading operation is processing.
            0     Not downloading.
            ====  ====================================
        :type mode: int
        """
        screen = self._stdscr.subwin(2, 80, 20, 0)
        screen.bkgd(' ', curses.color_pair(4))
        normal = curses.A_NORMAL
        line_width = 76
        prog_len = line_width - 20
        # Progress Bar
        if mode:
            done *= block
            prog = 1.0 * prog_len * done / total
            progress = ''.join(['=' * int(prog), '-' * int(2 * prog % 2)])
            progress = progress.ljust(prog_len)
            total = CommonUtil.convert_size(total).ljust(7)
            done = CommonUtil.convert_size(done).rjust(7)
        else:
            progress = ' ' * prog_len
            done = total = 'N/A'.center(7)
        # Show Progress
        prog_bar = "[%s] %s | %s" % (progress, done, total)
        screen.addstr(1, 2, prog_bar, normal)
        screen.refresh()
示例#2
0
    def set_progress(self, done, block, total):
        """
        Send message to the main dialog to set the progress bar.

        :param done: Block count of packaged retrieved.
        :type done: int
        :param block: Block size of the data pack retrieved.
        :type block: int
        :param total: Total size of the hosts data file.
        :type total: int
        """
        done = done * block
        if total <= 0:
            total = self.filesize
        prog = 100 * done / total
        done = CommonUtil.convert_size(done)
        total = CommonUtil.convert_size(total)
        text = unicode(_translate(
            "Util", "Downloading: %s / %s", None)) % (done, total)
        self.prog_trigger.emit(prog, text)
示例#3
0
    def set_progress(self, done, block, total):
        """
        Send message to the main dialog to set the progress bar.

        :param done: Block count of packaged retrieved.
        :type done: int
        :param block: Block size of the data pack retrieved.
        :type block: int
        :param total: Total size of the hosts data file.
        :type total: int
        """
        done = done * block
        if total <= 0:
            total = self.filesize
        prog = 100 * done / total
        done = CommonUtil.convert_size(done)
        total = CommonUtil.convert_size(total)
        text = unicode(_translate("Util", "Downloading: %s / %s",
                                  None)) % (done, total)
        self.prog_trigger.emit(prog, text)