diff --git a/csaxs_bec/bec_ipython_client/plugins/flomni/gui_tools.py b/csaxs_bec/bec_ipython_client/plugins/flomni/gui_tools.py index 5d03537..7eeaf53 100644 --- a/csaxs_bec/bec_ipython_client/plugins/flomni/gui_tools.py +++ b/csaxs_bec/bec_ipython_client/plugins/flomni/gui_tools.py @@ -123,8 +123,24 @@ class flomniGuiTools: # dev.cam_flomni_overview.stop_live_mode() # dev.cam_flomni_gripper.stop_live_mode() # dev.cam_xeye.live_mode = False - if hasattr(self.gui, "flomni"): - self.gui.flomni.delete_all(timeout=self.GUI_RPC_TIMEOUT) + flomni_window = self._flomnigui_get_window() + if flomni_window is not None: + flomni_window.delete_all(timeout=self.GUI_RPC_TIMEOUT) + self._flomnigui_clear_widget_references() + + def _flomnigui_get_window(self): + """Return the flOMNI dock area proxy without falling back to root GUI actions.""" + flomni_window = getattr(self, "flomni_window", None) + if flomni_window is not None: + if not (hasattr(flomni_window, "_is_deleted") and flomni_window._is_deleted()): + return flomni_window + + flomni_window = self.gui.windows.get("flomni") + if flomni_window is not None: + self.flomni_window = flomni_window + return flomni_window + + def _flomnigui_clear_widget_references(self): self.progressbar = None self.text_box = None self.xeyegui = None @@ -231,56 +247,61 @@ class flomniGuiTools: client.get_global_var("tomo_progress") """ + if self.progressbar is None: + return + if hasattr(self.progressbar, "_is_deleted") and self.progressbar._is_deleted(): + self.progressbar = None + return + main_progress_ring = self.progressbar.rings[0] subtomo_progress_ring = self.progressbar.rings[1] - if self.progressbar is not None: - progress = self.progress["projection"] / self.progress["total_projections"] * 100 - subtomo_progress = ( - self.progress["subtomo_projection"] - / self.progress["subtomo_total_projections"] - * 100 - ) - main_progress_ring.set_value(progress) - subtomo_progress_ring.set_value(subtomo_progress) + total_projections = self.progress["total_projections"] or 1 + subtomo_total_projections = self.progress["subtomo_total_projections"] or 1 + progress = self.progress["projection"] / total_projections * 100 + subtomo_progress = self.progress["subtomo_projection"] / subtomo_total_projections * 100 + main_progress_ring.set_value(progress) + subtomo_progress_ring.set_value(subtomo_progress) - # --- format start time for display -------------------------------- - start_str = self.progress.get("tomo_start_time") - if start_str is not None: - import datetime as _dt - start_display = _dt.datetime.fromisoformat(start_str).strftime("%Y-%m-%d %H:%M:%S") + # --- format start time for display -------------------------------- + start_str = self.progress.get("tomo_start_time") + if start_str is not None: + import datetime as _dt + + start_display = _dt.datetime.fromisoformat(start_str).strftime("%Y-%m-%d %H:%M:%S") + else: + start_display = "N/A" + + # --- format estimated remaining time ------------------------------ + remaining_s = self.progress.get("estimated_remaining_time") + if remaining_s is not None and remaining_s >= 0: + import datetime as _dt + + remaining_s = int(remaining_s) + h, rem = divmod(remaining_s, 3600) + m, s = divmod(rem, 60) + if h > 0: + eta_display = f"{h}h {m:02d}m {s:02d}s" + elif m > 0: + eta_display = f"{m}m {s:02d}s" else: - start_display = "N/A" + eta_display = f"{s}s" + else: + eta_display = "N/A" + # ------------------------------------------------------------------ - # --- format estimated remaining time ------------------------------ - remaining_s = self.progress.get("estimated_remaining_time") - if remaining_s is not None and remaining_s >= 0: - import datetime as _dt - remaining_s = int(remaining_s) - h, rem = divmod(remaining_s, 3600) - m, s = divmod(rem, 60) - if h > 0: - eta_display = f"{h}h {m:02d}m {s:02d}s" - elif m > 0: - eta_display = f"{m}m {s:02d}s" - else: - eta_display = f"{s}s" - else: - eta_display = "N/A" - # ------------------------------------------------------------------ - - text = ( - f"Progress report:\n" - f" Tomo type: {self.progress['tomo_type']}\n" - f" Projection: {self.progress['projection']:.0f}\n" - f" Total projections expected {self.progress['total_projections']:.1f}\n" - f" Angle: {self.progress['angle']:.1f}\n" - f" Current subtomo: {self.progress['subtomo']}\n" - f" Current projection within subtomo: {self.progress['subtomo_projection']}\n" - f" Total projections per subtomo: {int(self.progress['subtomo_total_projections'])}\n" - f" Scan started: {start_display}\n" - f" Est. remaining: {eta_display}" - ) - self.progressbar.set_center_label(text) + text = ( + f"Progress report:\n" + f" Tomo type: {self.progress['tomo_type']}\n" + f" Projection: {self.progress['projection']:.0f}\n" + f" Total projections expected {self.progress['total_projections']:.1f}\n" + f" Angle: {self.progress['angle']:.1f}\n" + f" Current subtomo: {self.progress['subtomo']}\n" + f" Current projection within subtomo: {self.progress['subtomo_projection']}\n" + f" Total projections per subtomo: {int(self.progress['subtomo_total_projections'])}\n" + f" Scan started: {start_display}\n" + f" Est. remaining: {eta_display}" + ) + self.progressbar.set_center_label(text) if __name__ == "__main__":