94 def update(self, text_or_percentage):
95 """
96 Update the widget with a new event number
97 """
98
99 if isinstance(text_or_percentage, numbers.Number):
100
101 current_percentage = float(text_or_percentage)
102 current_time = time.time()
103
104 remaining_percentage = 1.0 - current_percentage
105
106 time_delta = current_time - self.last_time
107 percentage_delta = current_percentage - self.last_percentage
108
109 if percentage_delta > 0:
110 time_delta_per_percentage = 1.0 * time_delta / percentage_delta
111
112
113 attrs = ['years', 'months', 'days', 'hours', 'minutes', 'seconds']
114
115 def human_readable(delta): return [f'{int(getattr(delta, attr))} {getattr(delta, attr) > 1 and attr or attr[:-1]}'
116 for attr in attrs if getattr(delta, attr)]
117
118 times_list = human_readable(relativedelta(seconds=time_delta_per_percentage * remaining_percentage))
119 human_readable_str = " ".join(times_list)
120
121 display_text = f"{int(100 * current_percentage)} % Remaining time: {human_readable_str}"
122
123 self.progress_label.value = display_text
124 self.progress_bar.value = float(current_percentage)
125 else:
126
127 self.progress_label.value = f"Status: {text_or_percentage}"
128 if "finished" in str(text_or_percentage):
129 self.progress_bar.value = 1.0
130 self.progress_bar.bar_style = "success"
131 elif "failed" in str(text_or_percentage):
132 self.progress_bar.bar_style = "danger"
133
134 self.progress_box.box_style = "danger"
135