Helpviewer/Download/DownloadUtilities.py

Sun, 07 Feb 2016 15:18:17 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 07 Feb 2016 15:18:17 +0100
branch
6_1_x
changeset 4721
18bde678a72d
parent 4632
ca310db386ed
child 4828
b313794f46a2
permissions
-rw-r--r--

Fixed a forgotten close() call in the web browser window.
(grafted from 7b77980d3255cfbdb11c93f49d97d6cae4c167b1)

# -*- coding: utf-8 -*-

# Copyright (c) 2010 - 2016 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing some utility functions for the Download package.
"""

from __future__ import unicode_literals

from PyQt5.QtCore import QCoreApplication


def timeString(timeRemaining):
    """
    Module function to format the given time.
    
    @param timeRemaining time to be formatted (float)
    @return time string (string)
    """
    if timeRemaining > 60:
        minutes = int(timeRemaining / 60)
        seconds = int(timeRemaining % 60)
        remaining = QCoreApplication.translate(
            "DownloadUtilities",
            "%n:{0:02} minutes remaining""", "",
            minutes).format(seconds)
    else:
        seconds = int(timeRemaining)
        remaining = QCoreApplication.translate(
            "DownloadUtilities",
            "%n seconds remaining", "", seconds)
    
    return remaining


def dataString(size):
    """
    Module function to generate a formatted size string.
    
    @param size size to be formatted (integer)
    @return formatted data string (string)
    """
    unit = ""
    if size < 1024:
        unit = QCoreApplication.translate("DownloadUtilities", "Bytes")
    elif size < 1024 * 1024:
        size /= 1024
        unit = QCoreApplication.translate("DownloadUtilities", "KiB")
    elif size < 1024 * 1024 * 1024:
        size /= 1024 * 1024
        unit = QCoreApplication.translate("DownloadUtilities", "MiB")
    else:
        size /= 1024 * 1024 * 1024
        unit = QCoreApplication.translate("DownloadUtilities", "GiB")
    return "{0:.1f} {1}".format(size, unit)

eric ide

mercurial