From fde332251d5e4622f107d9c0ca94f6d63d4fc389 Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Wed, 15 Sep 2021 18:05:58 -0300 Subject: [PATCH] Update progress inside region growing dialog --- invesalius/data/styles.py | 30 ++++++++++++++++++------------ invesalius/gui/dialogs.py | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 13 deletions(-) diff --git a/invesalius/data/styles.py b/invesalius/data/styles.py index 4e3867a..e4b5dd2 100644 --- a/invesalius/data/styles.py +++ b/invesalius/data/styles.py @@ -2600,6 +2600,7 @@ class SelectMaskPartsInteractorStyle(DefaultInteractorStyle): class FFillSegmentationConfig(metaclass=utils.Singleton): def __init__(self): self.dlg_visible = False + self.dlg = None self.target = "2D" self.con_2d = 4 self.con_3d = 6 @@ -2634,7 +2635,6 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): self.slice_data = viewer.slice_data self.config = FFillSegmentationConfig() - self.dlg_ffill = None self._progr_title = _(u"Region growing") self._progr_msg = _(u"Segmenting ...") @@ -2652,14 +2652,14 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): self.config.t1 = int(_max) self.config.dlg_visible = True - self.dlg_ffill = dialogs.FFillSegmentationOptionsDialog(self.config) - self.dlg_ffill.Show() + self.config.dlg = dialogs.FFillSegmentationOptionsDialog(self.config) + self.config.dlg.Show() def CleanUp(self): - if (self.dlg_ffill is not None) and (self.config.dlg_visible): + if (self.config.dlg is not None) and (self.config.dlg_visible): self.config.dlg_visible = False - self.dlg_ffill.Destroy() - self.dlg_ffill = None + self.config.dlg.Destroy() + self.config.dlg = None def OnFFClick(self, obj, evt): if (self.viewer.slice_.buffer_slices[self.orientation].mask is None): @@ -2787,22 +2787,28 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): with futures.ThreadPoolExecutor(max_workers=1) as executor: future = executor.submit(self.do_rg_confidence, image, mask, (x, y, z), bstruct) - dlg = wx.ProgressDialog(self._progr_title, self._progr_msg, parent=wx.GetApp().GetTopWindow(), style=wx.PD_APP_MODAL|wx.PD_AUTO_HIDE) + self.config.dlg.panel_ffill_progress.Enable() + self.config.dlg.panel_ffill_progress.StartTimer() while not future.done(): - dlg.Pulse() + self.config.dlg.panel_ffill_progress.Pulse() + self.config.dlg.Update() time.sleep(0.1) - dlg.Destroy() + self.config.dlg.panel_ffill_progress.StopTimer() + self.config.dlg.panel_ffill_progress.Disable() out_mask = future.result() else: out_mask = np.zeros_like(mask) with futures.ThreadPoolExecutor(max_workers=1) as executor: future = executor.submit(floodfill.floodfill_threshold, image, [[x, y, z]], t0, t1, 1, bstruct, out_mask) - dlg = wx.ProgressDialog(self._progr_title, self._progr_msg, parent=wx.GetApp().GetTopWindow(), style=wx.PD_APP_MODAL|wx.PD_AUTO_HIDE) + self.config.dlg.panel_ffill_progress.Enable() + self.config.dlg.panel_ffill_progress.StartTimer() while not future.done(): - dlg.Pulse() + self.config.dlg.panel_ffill_progress.Pulse() + self.config.dlg.Update() time.sleep(0.1) - dlg.Destroy() + self.config.dlg.panel_ffill_progress.StopTimer() + self.config.dlg.panel_ffill_progress.Disable() mask[out_mask.astype('bool')] = self.config.fill_value diff --git a/invesalius/gui/dialogs.py b/invesalius/gui/dialogs.py index f8ac7a8..67c5a24 100644 --- a/invesalius/gui/dialogs.py +++ b/invesalius/gui/dialogs.py @@ -2560,6 +2560,41 @@ class PanelFFillConfidence(wx.Panel): self.config.confid_iters = self.spin_iters.GetValue() +class PanelFFillProgress(wx.Panel): + def __init__(self, parent, ID=-1, style=wx.TAB_TRAVERSAL|wx.NO_BORDER): + wx.Panel.__init__(self, parent, ID, style=style) + self._init_gui() + + def _init_gui(self): + self.progress = wx.Gauge(self, -1) + self.lbl_progress_caption = wx.StaticText(self, -1, _("Elapsed time:")) + self.lbl_time = wx.StaticText(self, -1, _("00:00:00")) + + main_sizer = wx.BoxSizer(wx.VERTICAL) + main_sizer.Add(self.progress, 0, wx.EXPAND | wx.ALL, 5) + time_sizer = wx.BoxSizer(wx.HORIZONTAL) + time_sizer.Add(self.lbl_progress_caption, 0, wx.EXPAND, 0) + time_sizer.Add(self.lbl_time, 1, wx.EXPAND | wx.LEFT, 5) + main_sizer.Add(time_sizer, 0, wx.EXPAND | wx.ALL, 5) + + self.SetSizer(main_sizer) + main_sizer.Fit(self) + main_sizer.SetSizeHints(self) + + def StartTimer(self): + self.t0 = time.time() + + def StopTimer(self): + fmt = "%H:%M:%S" + self.lbl_time.SetLabel(time.strftime(fmt, time.gmtime(time.time() - self.t0))) + self.progress.SetValue(0) + + def Pulse(self): + fmt = "%H:%M:%S" + self.lbl_time.SetLabel(time.strftime(fmt, time.gmtime(time.time() - self.t0))) + self.progress.Pulse() + + class FFillOptionsDialog(wx.Dialog): def __init__(self, title, config): wx.Dialog.__init__(self, wx.GetApp().GetTopWindow(), -1, title, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.STAY_ON_TOP) @@ -2817,6 +2852,10 @@ class FFillSegmentationOptionsDialog(wx.Dialog): self.panel_ffill_confidence.SetMinSize((250, -1)) self.panel_ffill_confidence.Hide() + self.panel_ffill_progress = PanelFFillProgress(self, -1, style=wx.TAB_TRAVERSAL) + self.panel_ffill_progress.SetMinSize((250, -1)) + # self.panel_ffill_progress.Hide() + self.close_btn = wx.Button(self, wx.ID_CLOSE) # Sizer @@ -2873,11 +2912,16 @@ class FFillSegmentationOptionsDialog(wx.Dialog): sizer.Add(0, 0, (12, 0)) except TypeError: sizer.AddStretchSpacer((12, 0)) - sizer.Add(self.close_btn, (13, 0), (1, 6), flag=wx.ALIGN_RIGHT|wx.RIGHT, border=5) + sizer.Add(self.panel_ffill_progress, (13, 0), (1, 6), flag=wx.ALIGN_RIGHT|wx.RIGHT, border=5) try: sizer.Add(0, 0, (14, 0)) except TypeError: sizer.AddStretchSpacer((14, 0)) + sizer.Add(self.close_btn, (15, 0), (1, 6), flag=wx.ALIGN_RIGHT|wx.RIGHT, border=5) + try: + sizer.Add(0, 0, (16, 0)) + except TypeError: + sizer.AddStretchSpacer((16, 0)) self.SetSizer(sizer) sizer.Fit(self) -- libgit2 0.21.2