Fix #728 and make size->string conversion more robust.

This commit is contained in:
Kovid Goyal 2008-06-01 10:41:37 -07:00
parent daa604df81
commit 9c119fc238
2 changed files with 7 additions and 8 deletions

View File

@ -57,16 +57,15 @@ def qstring_to_unicode(q):
def human_readable(size):
""" Convert a size in bytes into a human readable form """
if size < 1024:
divisor, suffix = 1, "B"
elif size < 1024*1024:
divisor, suffix = 1, "B"
if size < 1024*1024:
divisor, suffix = 1024., "KB"
elif size < 1024*1024*1024:
elif size < 1024*1024*1024:
divisor, suffix = 1024*1024, "MB"
elif size < 1024*1024*1024*1024:
elif size < 1024*1024*1024*1024:
divisor, suffix = 1024*1024*1024, "GB"
size = str(float(size)/divisor)
if size.find(".") > -1:
if size.find(".") > -1:
size = size[:size.find(".")+2]
if size.endswith('.0'):
size = size[:-2]

View File

@ -1,6 +1,6 @@
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import textwrap
import textwrap, re
from PyQt4.QtGui import QStatusBar, QMovie, QLabel, QFrame, QHBoxLayout, QPixmap, \
QVBoxLayout, QSizePolicy, QToolButton, QIcon
@ -153,7 +153,7 @@ class StatusBar(QStatusBar):
def jobs(self):
src = qstring_to_unicode(self.movie_button.jobs.text())
return int(src.rpartition(':')[2].lstrip())
return int(re.search(r'\d+', src).group())
def show_book_info(self):
self.emit(SIGNAL('show_book_info()'))