Use human_size to display sizes in progress bars

This commit is contained in:
Mathieu Comandon 2023-09-25 13:27:07 -07:00
parent 761c8d7b57
commit fd4ffacb62
3 changed files with 10 additions and 11 deletions

View file

@ -5,7 +5,7 @@ from gi.repository import GLib, GObject, Gtk, Pango
from lutris.util.downloader import Downloader
from lutris.util.log import logger
from lutris.util.strings import gtk_safe
from lutris.util.strings import gtk_safe, human_size
# Same reason as Downloader
get_time = time.monotonic
@ -171,10 +171,10 @@ class DownloadCollectionProgressBox(Gtk.Box):
self.update_speed_and_time()
megabytes = 1024 * 1024
progress_text = _(
"{downloaded:0.2f} / {size:0.2f}MB ({speed:0.2f}MB/s), {time} remaining"
"{downloaded} / {size} ({speed:0.2f}MB/s), {time} remaining"
).format(
downloaded=(downloaded_size) / megabytes,
size=float(self.full_size) / megabytes,
downloaded=human_size(downloaded_size),
size=human_size(self.full_size),
speed=float(self.avg_speed) / megabytes,
time=self.time_left,
)

View file

@ -5,7 +5,7 @@ from gi.repository import GLib, GObject, Gtk, Pango
from lutris.util.downloader import Downloader
from lutris.util.log import logger
from lutris.util.strings import gtk_safe
from lutris.util.strings import gtk_safe, human_size
class DownloadProgressBox(Gtk.Box):
@ -120,10 +120,10 @@ class DownloadProgressBox(Gtk.Box):
self.progressbar.set_fraction(progress)
megabytes = 1024 * 1024
progress_text = _(
"{downloaded:0.2f} / {size:0.2f}MB ({speed:0.2f}MB/s), {time} remaining"
"{downloaded} / {size} ({speed:0.2f}MB/s), {time} remaining"
).format(
downloaded=float(self.downloader.downloaded_size) / megabytes,
size=float(self.downloader.full_size) / megabytes,
downloaded=human_size(self.downloader.downloaded_size),
size=human_size(self.downloader.full_size),
speed=float(self.downloader.average_speed) / megabytes,
time=self.downloader.time_left,
)

View file

@ -1,8 +1,7 @@
"""Manipulates installer files"""
import os
from functools import reduce
from urllib.parse import urlparse
from gettext import gettext as _
from urllib.parse import urlparse
from lutris import cache, settings
from lutris.gui.widgets.download_collection_progress_box import DownloadCollectionProgressBox
@ -29,7 +28,7 @@ class InstallerFileCollection:
def _get_files_size(self):
if self.num_files > 0:
self.full_size = reduce(lambda x, y: x + y, map(lambda a: a.size, self.files_list))
self.full_size = sum(f.size for f in self.files_list)
def _get_service(self):
"""Try to get the service using the url of an InstallerFile"""