Helpviewer/Download/DownloadUtilities.py

Sat, 26 Oct 2013 17:37:39 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 26 Oct 2013 17:37:39 +0200
branch
5_3_x
changeset 3049
a6847e5eb1b9
parent 2302
f29e9405c851
child 2525
8b507a9a2d40
child 2954
bf0215fe12d1
child 3163
9f50365a0870
permissions
-rw-r--r--

Fixed an issue causing trouble if the printer name is empty.
(grafted from 83f86da6344eeb0cbdb3c56e270f2f0a276c8b14)

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

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

from PyQt4.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""", "", QCoreApplication.UnicodeUTF8, minutes)\
            .format(seconds)
    else:
        seconds = int(timeRemaining)
        remaining = QCoreApplication.translate("DownloadUtilities",
            "%n seconds remaining", "", QCoreApplication.UnicodeUTF8, 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