def handle_work_event(self, type, args): if type in ("append", "replace"): text, stream_name = args if type == "replace": self.log_text.text.direct_delete("end-1c linestart", "end-1c") self.log_text.text.direct_insert("end", text, (stream_name, )) self.log_text.text.see("end") elif type == "action": set_text_if_different(self._current_action_label, args[0]) elif type == "progress": value, maximum = args if value is None or maximum is None: if self._progress_bar["mode"] != "indeterminate": self._progress_bar["mode"] = "indeterminate" self._progress_bar.start() else: if self._progress_bar["mode"] != "determinate": self._progress_bar["mode"] = "determinate" self._progress_bar.stop() self._progress_bar.configure(value=value, maximum=maximum) elif type == "done": self.success = args[0] if self.success: self._state = "done" else: # allows trying again when failed self._state = "idle" self._progress_bar.stop()
def update_ui(self): while not self._work_events_queue.empty(): self.handle_work_event(*self._work_events_queue.get()) if self._state == "idle": if self.is_ready_for_work(): self._ok_button.configure(state="normal") else: self._ok_button.configure(state="disabled") else: self._ok_button.configure(state="disabled") if self._state == "done": set_text_if_different(self._cancel_button, tr("Close")) else: set_text_if_different(self._cancel_button, tr("Cancel"))
def update_ui(self): if self._state == "idle": self._possible_targets = self.get_possible_targets() if not self._possible_targets: set_text_if_different(self.target_label, "") set_text_if_different(self.model_label, "") else: unpacked = list(zip(*self._possible_targets)) set_text_if_different(self.target_label, "\n".join(unpacked[0])) model_changed = set_text_if_different(self.model_label, "\n".join(unpacked[2])) desc = self.get_firmware_description() if desc is None: set_text_if_different(self._version_label, self.get_unknown_version_text()) else: set_text_if_different(self._version_label, desc) super(Uf2FlashingDialog, self).update_ui()