Commit fde332251d5e4622f107d9c0ca94f6d63d4fc389
1 parent
9f54b6b7
Exists in
master
Update progress inside region growing dialog
Showing
2 changed files
with
63 additions
and
13 deletions
Show diff stats
invesalius/data/styles.py
... | ... | @@ -2600,6 +2600,7 @@ class SelectMaskPartsInteractorStyle(DefaultInteractorStyle): |
2600 | 2600 | class FFillSegmentationConfig(metaclass=utils.Singleton): |
2601 | 2601 | def __init__(self): |
2602 | 2602 | self.dlg_visible = False |
2603 | + self.dlg = None | |
2603 | 2604 | self.target = "2D" |
2604 | 2605 | self.con_2d = 4 |
2605 | 2606 | self.con_3d = 6 |
... | ... | @@ -2634,7 +2635,6 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): |
2634 | 2635 | self.slice_data = viewer.slice_data |
2635 | 2636 | |
2636 | 2637 | self.config = FFillSegmentationConfig() |
2637 | - self.dlg_ffill = None | |
2638 | 2638 | |
2639 | 2639 | self._progr_title = _(u"Region growing") |
2640 | 2640 | self._progr_msg = _(u"Segmenting ...") |
... | ... | @@ -2652,14 +2652,14 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): |
2652 | 2652 | self.config.t1 = int(_max) |
2653 | 2653 | |
2654 | 2654 | self.config.dlg_visible = True |
2655 | - self.dlg_ffill = dialogs.FFillSegmentationOptionsDialog(self.config) | |
2656 | - self.dlg_ffill.Show() | |
2655 | + self.config.dlg = dialogs.FFillSegmentationOptionsDialog(self.config) | |
2656 | + self.config.dlg.Show() | |
2657 | 2657 | |
2658 | 2658 | def CleanUp(self): |
2659 | - if (self.dlg_ffill is not None) and (self.config.dlg_visible): | |
2659 | + if (self.config.dlg is not None) and (self.config.dlg_visible): | |
2660 | 2660 | self.config.dlg_visible = False |
2661 | - self.dlg_ffill.Destroy() | |
2662 | - self.dlg_ffill = None | |
2661 | + self.config.dlg.Destroy() | |
2662 | + self.config.dlg = None | |
2663 | 2663 | |
2664 | 2664 | def OnFFClick(self, obj, evt): |
2665 | 2665 | if (self.viewer.slice_.buffer_slices[self.orientation].mask is None): |
... | ... | @@ -2787,22 +2787,28 @@ class FloodFillSegmentInteractorStyle(DefaultInteractorStyle): |
2787 | 2787 | with futures.ThreadPoolExecutor(max_workers=1) as executor: |
2788 | 2788 | future = executor.submit(self.do_rg_confidence, image, mask, (x, y, z), bstruct) |
2789 | 2789 | |
2790 | - dlg = wx.ProgressDialog(self._progr_title, self._progr_msg, parent=wx.GetApp().GetTopWindow(), style=wx.PD_APP_MODAL|wx.PD_AUTO_HIDE) | |
2790 | + self.config.dlg.panel_ffill_progress.Enable() | |
2791 | + self.config.dlg.panel_ffill_progress.StartTimer() | |
2791 | 2792 | while not future.done(): |
2792 | - dlg.Pulse() | |
2793 | + self.config.dlg.panel_ffill_progress.Pulse() | |
2794 | + self.config.dlg.Update() | |
2793 | 2795 | time.sleep(0.1) |
2794 | - dlg.Destroy() | |
2796 | + self.config.dlg.panel_ffill_progress.StopTimer() | |
2797 | + self.config.dlg.panel_ffill_progress.Disable() | |
2795 | 2798 | out_mask = future.result() |
2796 | 2799 | else: |
2797 | 2800 | out_mask = np.zeros_like(mask) |
2798 | 2801 | with futures.ThreadPoolExecutor(max_workers=1) as executor: |
2799 | 2802 | future = executor.submit(floodfill.floodfill_threshold, image, [[x, y, z]], t0, t1, 1, bstruct, out_mask) |
2800 | 2803 | |
2801 | - dlg = wx.ProgressDialog(self._progr_title, self._progr_msg, parent=wx.GetApp().GetTopWindow(), style=wx.PD_APP_MODAL|wx.PD_AUTO_HIDE) | |
2804 | + self.config.dlg.panel_ffill_progress.Enable() | |
2805 | + self.config.dlg.panel_ffill_progress.StartTimer() | |
2802 | 2806 | while not future.done(): |
2803 | - dlg.Pulse() | |
2807 | + self.config.dlg.panel_ffill_progress.Pulse() | |
2808 | + self.config.dlg.Update() | |
2804 | 2809 | time.sleep(0.1) |
2805 | - dlg.Destroy() | |
2810 | + self.config.dlg.panel_ffill_progress.StopTimer() | |
2811 | + self.config.dlg.panel_ffill_progress.Disable() | |
2806 | 2812 | |
2807 | 2813 | mask[out_mask.astype('bool')] = self.config.fill_value |
2808 | 2814 | ... | ... |
invesalius/gui/dialogs.py
... | ... | @@ -2560,6 +2560,41 @@ class PanelFFillConfidence(wx.Panel): |
2560 | 2560 | self.config.confid_iters = self.spin_iters.GetValue() |
2561 | 2561 | |
2562 | 2562 | |
2563 | +class PanelFFillProgress(wx.Panel): | |
2564 | + def __init__(self, parent, ID=-1, style=wx.TAB_TRAVERSAL|wx.NO_BORDER): | |
2565 | + wx.Panel.__init__(self, parent, ID, style=style) | |
2566 | + self._init_gui() | |
2567 | + | |
2568 | + def _init_gui(self): | |
2569 | + self.progress = wx.Gauge(self, -1) | |
2570 | + self.lbl_progress_caption = wx.StaticText(self, -1, _("Elapsed time:")) | |
2571 | + self.lbl_time = wx.StaticText(self, -1, _("00:00:00")) | |
2572 | + | |
2573 | + main_sizer = wx.BoxSizer(wx.VERTICAL) | |
2574 | + main_sizer.Add(self.progress, 0, wx.EXPAND | wx.ALL, 5) | |
2575 | + time_sizer = wx.BoxSizer(wx.HORIZONTAL) | |
2576 | + time_sizer.Add(self.lbl_progress_caption, 0, wx.EXPAND, 0) | |
2577 | + time_sizer.Add(self.lbl_time, 1, wx.EXPAND | wx.LEFT, 5) | |
2578 | + main_sizer.Add(time_sizer, 0, wx.EXPAND | wx.ALL, 5) | |
2579 | + | |
2580 | + self.SetSizer(main_sizer) | |
2581 | + main_sizer.Fit(self) | |
2582 | + main_sizer.SetSizeHints(self) | |
2583 | + | |
2584 | + def StartTimer(self): | |
2585 | + self.t0 = time.time() | |
2586 | + | |
2587 | + def StopTimer(self): | |
2588 | + fmt = "%H:%M:%S" | |
2589 | + self.lbl_time.SetLabel(time.strftime(fmt, time.gmtime(time.time() - self.t0))) | |
2590 | + self.progress.SetValue(0) | |
2591 | + | |
2592 | + def Pulse(self): | |
2593 | + fmt = "%H:%M:%S" | |
2594 | + self.lbl_time.SetLabel(time.strftime(fmt, time.gmtime(time.time() - self.t0))) | |
2595 | + self.progress.Pulse() | |
2596 | + | |
2597 | + | |
2563 | 2598 | class FFillOptionsDialog(wx.Dialog): |
2564 | 2599 | def __init__(self, title, config): |
2565 | 2600 | 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): |
2817 | 2852 | self.panel_ffill_confidence.SetMinSize((250, -1)) |
2818 | 2853 | self.panel_ffill_confidence.Hide() |
2819 | 2854 | |
2855 | + self.panel_ffill_progress = PanelFFillProgress(self, -1, style=wx.TAB_TRAVERSAL) | |
2856 | + self.panel_ffill_progress.SetMinSize((250, -1)) | |
2857 | + # self.panel_ffill_progress.Hide() | |
2858 | + | |
2820 | 2859 | self.close_btn = wx.Button(self, wx.ID_CLOSE) |
2821 | 2860 | |
2822 | 2861 | # Sizer |
... | ... | @@ -2873,11 +2912,16 @@ class FFillSegmentationOptionsDialog(wx.Dialog): |
2873 | 2912 | sizer.Add(0, 0, (12, 0)) |
2874 | 2913 | except TypeError: |
2875 | 2914 | sizer.AddStretchSpacer((12, 0)) |
2876 | - sizer.Add(self.close_btn, (13, 0), (1, 6), flag=wx.ALIGN_RIGHT|wx.RIGHT, border=5) | |
2915 | + sizer.Add(self.panel_ffill_progress, (13, 0), (1, 6), flag=wx.ALIGN_RIGHT|wx.RIGHT, border=5) | |
2877 | 2916 | try: |
2878 | 2917 | sizer.Add(0, 0, (14, 0)) |
2879 | 2918 | except TypeError: |
2880 | 2919 | sizer.AddStretchSpacer((14, 0)) |
2920 | + sizer.Add(self.close_btn, (15, 0), (1, 6), flag=wx.ALIGN_RIGHT|wx.RIGHT, border=5) | |
2921 | + try: | |
2922 | + sizer.Add(0, 0, (16, 0)) | |
2923 | + except TypeError: | |
2924 | + sizer.AddStretchSpacer((16, 0)) | |
2881 | 2925 | |
2882 | 2926 | self.SetSizer(sizer) |
2883 | 2927 | sizer.Fit(self) | ... | ... |