From f05bcdb829cba819e9271059204a371932afb83f Mon Sep 17 00:00:00 2001 From: Yuri Date: Fri, 11 Jul 2014 11:12:58 -0700 Subject: [PATCH] Made sent/received byte counts to be in human readable format. --- src/bitmessageqt/__init__.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 35a4b563..9304706b 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -1471,11 +1471,22 @@ class MyForm(QtGui.QMainWindow): "MainWindow", "Processed %1 public keys.").arg(str(shared.numberOfPubkeysProcessed))) self.updateNumberOfBytes() + + def formatNumberAsHumanReadable(self, num): + for x in ['bytes','KB','MB','GB']: + if num < 1024.0: + return "%3.1f %s" % (num, x) + num /= 1024.0 + return "%3.1f %s" % (num, 'TB') + + def formatNumberOfBytes(self, num): + return "%s (%s bytes)" % (self.formatNumberAsHumanReadable(num), str(locale.format("%d", num, grouping=True))) + def updateNumberOfBytes(self): self.ui.labelBytesRecvCount.setText(_translate( - "MainWindow", "Received %1 bytes.").arg(str(locale.format("%d", shared.numberOfBytesReceived, grouping=True)))) + "MainWindow", "Received %1.").arg(self.formatNumberOfBytes(shared.numberOfBytesReceived))) self.ui.labelBytesSentCount.setText(_translate( - "MainWindow", "Sent %1 bytes.").arg(str(locale.format("%d", shared.numberOfBytesSent, grouping=True)))) + "MainWindow", "Sent %1.").arg(self.formatNumberOfBytes(shared.numberOfBytesSent))) def updateNetworkStatusTab(self): # print 'updating network status tab'