From aab5ae31ab9bfd9493c9d6ea54d286f99456420d Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 14 May 2015 14:40:55 -0700 Subject: [PATCH] No longer duplicates human_readable_filesize functions. Closes #170 --- onionshare_gui/file_selection.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/onionshare_gui/file_selection.py b/onionshare_gui/file_selection.py index 89d2e560..c22a2407 100644 --- a/onionshare_gui/file_selection.py +++ b/onionshare_gui/file_selection.py @@ -114,9 +114,9 @@ class FileList(QtGui.QListWidget): icon = ip.icon(fileinfo) if os.path.isfile(filename): - size = self.human_readable_filesize(fileinfo.size()) + size = helpers.human_readable_filesize(fileinfo.size()) else: - size = self.human_readable_filesize(helpers.dir_size(filename)) + size = helpers.human_readable_filesize(helpers.dir_size(filename)) item_name = unicode('{0} ({1})'.format(basename, size)) item = QtGui.QListWidgetItem(item_name) item.setToolTip(QtCore.QString(size)) @@ -126,18 +126,6 @@ class FileList(QtGui.QListWidget): self.files_updated.emit() - def human_readable_filesize(self, b): - thresh = 1024.0 - if b < thresh: - return '{0} B'.format(b) - units = ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'] - u = 0 - b /= thresh - while b >= thresh: - b /= thresh - u += 1 - return '{0} {1}'.format(round(b, 1), units[u]) - class FileSelection(QtGui.QVBoxLayout): def __init__(self): @@ -220,4 +208,3 @@ class FileSelection(QtGui.QVBoxLayout): def get_num_files(self): return len(self.file_list.filenames) -