diff --git a/lutris/gui/dialogs/__init__.py b/lutris/gui/dialogs/__init__.py index a7bbe9358..2ff8b58b2 100644 --- a/lutris/gui/dialogs/__init__.py +++ b/lutris/gui/dialogs/__init__.py @@ -324,7 +324,6 @@ class LutrisInitDialog(Gtk.Dialog): self.label = Gtk.Label(_("Checking for runtime updates, please wait…")) vbox.add(self.label) self.progress = Gtk.ProgressBar(visible=True) - self.progress.set_pulse_step(0.1) vbox.add(self.progress) self.get_content_area().add(vbox) self.progress_timeout = GLib.timeout_add(125, self.show_progress) @@ -335,13 +334,13 @@ class LutrisInitDialog(Gtk.Dialog): AsyncCall(self.run_init, self.init_cb) def show_progress(self): - self.progress.pulse() + self.progress.set_fraction(self.runtime_updater.percentage_completed()) return True def run_init(self): self.runtime_updater.update_runtimes() - def init_cb(self, _result, error): + def init_cb(self, _result, error: Exception): if error: ErrorDialog(error, parent=self) self.destroy() diff --git a/lutris/runtime.py b/lutris/runtime.py index 12297e829..ecea3fe9a 100644 --- a/lutris/runtime.py +++ b/lutris/runtime.py @@ -34,11 +34,12 @@ class Runtime: """Class for manipulating runtime folders""" - def __init__(self, name, updater): + def __init__(self, name: str, updater) -> None: self.name = name self.updater = updater self.versioned = False # Versioned runtimes keep 1 version per folder self.version = None + self.download_progress: float = 0 @property def local_runtime_path(self): @@ -91,7 +92,7 @@ class Runtime: return False return True - def download(self, remote_runtime_info): + def download(self, remote_runtime_info: dict): """Downloads a runtime locally""" url = remote_runtime_info["url"] self.versioned = remote_runtime_info["versioned"] @@ -164,7 +165,7 @@ class Runtime: self.on_downloaded(None) return False - downloader.check_progress() + self.download_progress = downloader.check_progress() if downloader.state == downloader.COMPLETED: self.on_downloaded(downloader.dest) return False @@ -276,7 +277,13 @@ class RuntimeUpdater: if self.cancelled: return - def _populate_component_downloaders(self): + def percentage_completed(self) -> float: + if not self.downloaders: + return 0 + + return sum(downloader.progress_fraction for downloader in self.downloaders.values()) / len(self.downloaders) + + def _populate_component_downloaders(self) -> int: """Launch the update process""" if RUNTIME_DISABLED: logger.warning("Runtime disabled, not updating it.") diff --git a/lutris/util/downloader.py b/lutris/util/downloader.py index 9dedf64d1..ae7d8a4da 100644 --- a/lutris/util/downloader.py +++ b/lutris/util/downloader.py @@ -32,11 +32,11 @@ class Downloader: COMPLETED ) = list(range(5)) - def __init__(self, url, dest, overwrite=False, referer=None, cookies=None): - self.url = url - self.dest = dest + def __init__(self, url: str, dest: str, overwrite: bool = False, referer=None, cookies=None) -> None: + self.url: str = url + self.dest: str = dest self.cookies = cookies - self.overwrite = overwrite + self.overwrite: bool = overwrite self.referer = referer self.stop_request = None self.thread = None @@ -44,22 +44,22 @@ class Downloader: # Read these after a check_progress() self.state = self.INIT self.error = None - self.downloaded_size = 0 # Bytes - self.full_size = 0 # Bytes - self.progress_fraction = 0 - self.progress_percentage = 0 + self.downloaded_size: int = 0 # Bytes + self.full_size: int = 0 # Bytes + self.progress_fraction: float = 0 + self.progress_percentage: float = 0 self.speed = 0 self.average_speed = 0 - self.time_left = "00:00:00" # Based on average speed - self.last_size = 0 - self.last_check_time = 0 + self.time_left: str = "00:00:00" # Based on average speed + self.last_size: int = 0 + self.last_check_time: float = 0.0 self.last_speeds = [] self.speed_check_time = 0 self.time_left_check_time = 0 self.file_pointer = None self.progress_event = threading.Event() - def __str__(self): + def __repr__(self): return "downloader for %s" % self.url def start(self): @@ -85,7 +85,7 @@ class Downloader: self.average_speed = 0 self.time_left = "00:00:00" # Based on average speed self.last_size = 0 - self.last_check_time = 0 + self.last_check_time = 0.0 self.last_speeds = [] self.speed_check_time = 0 self.time_left_check_time = 0 @@ -156,7 +156,7 @@ class Downloader: logger.exception("Download failed: %s", ex) self.on_download_failed(ex) - def on_download_failed(self, error): + def on_download_failed(self, error: Exception): # Cancelling closes the file, which can result in an # error. If so, we just remain cancelled. if self.state != self.CANCELLED: @@ -217,7 +217,7 @@ class Downloader: self.speed_check_time = get_time() return speed, average_speed - def get_average_time_left(self): + def get_average_time_left(self) -> str: """Return average download time left as string.""" if not self.full_size: return "???"