From fc5829b6f2e79e1aa95f3b74c45281f846606fda Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Sat, 21 Mar 2020 18:23:34 -0300 Subject: [PATCH] Not using wx.ProgressDialog in brain segmenter gui --- invesalius/gui/brain_seg_dialog.py | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/invesalius/gui/brain_seg_dialog.py b/invesalius/gui/brain_seg_dialog.py index c201092..3d6df91 100644 --- a/invesalius/gui/brain_seg_dialog.py +++ b/invesalius/gui/brain_seg_dialog.py @@ -48,7 +48,7 @@ class BrainSegmenterDialog(wx.Dialog): if HAS_THEANO: backends.append("Theano") self.segmenter = segment.BrainSegmenter() - self.pg_dialog = None + # self.pg_dialog = None self.cb_backends = wx.ComboBox(self, wx.ID_ANY, choices=backends, value=backends[0], style=wx.CB_DROPDOWN | wx.CB_READONLY) w, h = self.CalcSizeFromTextSize("MM" * (1 + max(len(i) for i in backends))) @@ -60,10 +60,10 @@ class BrainSegmenterDialog(wx.Dialog): self.txt_threshold = wx.TextCtrl(self, wx.ID_ANY, "") w, h = self.CalcSizeFromTextSize("MMMMM") self.txt_threshold.SetMinClientSize((w, -1)) - # self.progress = wx.Gauge(self, -1) + self.progress = wx.Gauge(self, -1) self.btn_segment = wx.Button(self, wx.ID_ANY, _("Segment")) - # self.btn_stop = wx.Button(self, wx.ID_ANY, _("Stop")) - # self.btn_stop.Disable() + self.btn_stop = wx.Button(self, wx.ID_ANY, _("Stop")) + self.btn_stop.Disable() self.txt_threshold.SetValue("{:3d}%".format(self.sld_threshold.GetValue())) @@ -84,9 +84,9 @@ class BrainSegmenterDialog(wx.Dialog): sizer_3.Add(self.sld_threshold, 1, wx.ALIGN_CENTER | wx.BOTTOM | wx.EXPAND | wx.LEFT | wx.RIGHT, 5) sizer_3.Add(self.txt_threshold, 0, wx.ALL, 5) main_sizer.Add(sizer_3, 0, wx.EXPAND, 0) - # main_sizer.Add(self.progress, 0, wx.EXPAND | wx.ALL, 5) + main_sizer.Add(self.progress, 0, wx.EXPAND | wx.ALL, 5) sizer_buttons = wx.BoxSizer(wx.HORIZONTAL) - # sizer_buttons.Add(self.btn_stop, 0, wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT | wx.ALL, 5) + sizer_buttons.Add(self.btn_stop, 0, wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT | wx.ALL, 5) sizer_buttons.Add(self.btn_segment, 0, wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT | wx.ALL, 5) main_sizer.Add(sizer_buttons, 0, wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT | wx.ALL, 0) self.SetSizer(main_sizer) @@ -99,7 +99,7 @@ class BrainSegmenterDialog(wx.Dialog): self.sld_threshold.Bind(wx.EVT_SCROLL, self.OnScrollThreshold) self.txt_threshold.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) self.btn_segment.Bind(wx.EVT_BUTTON, self.OnSegment) - # self.btn_stop.Bind(wx.EVT_BUTTON, self.OnStop) + self.btn_stop.Bind(wx.EVT_BUTTON, self.OnStop) self.Bind(wx.EVT_CLOSE, self.OnClose) def CalcSizeFromTextSize(self, text): @@ -138,18 +138,18 @@ class BrainSegmenterDialog(wx.Dialog): backend = self.cb_backends.GetValue() use_gpu = self.chk_use_gpu.GetValue() prob_threshold = self.sld_threshold.GetValue() / 100.0 - # self.btn_stop.Enable() + self.btn_stop.Enable() self.btn_segment.Disable() - self.pg_dialog = wx.ProgressDialog(_("Brain segmenter"), _("Segmenting brain"), parent=self, style= wx.FRAME_FLOAT_ON_PARENT | wx.PD_CAN_ABORT | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME) - self.pg_dialog.Bind(wx.EVT_BUTTON, self.OnStop) - self.pg_dialog.Show() + # self.pg_dialog = wx.ProgressDialog(_("Brain segmenter"), _("Segmenting brain"), parent=self, style= wx.FRAME_FLOAT_ON_PARENT | wx.PD_CAN_ABORT | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME) + # self.pg_dialog.Bind(wx.EVT_BUTTON, self.OnStop) + # self.pg_dialog.Show() self.segmenter.segment(image, prob_threshold, backend, use_gpu, self.SetProgress, self.AfterSegment) def OnStop(self, evt): self.segmenter.stop = True - # self.btn_stop.Disable() - self.pg_dialog.Hide() - self.pg_dialog = None + self.btn_stop.Disable() + # self.pg_dialog.Hide() + # self.pg_dialog = None self.btn_segment.Enable() evt.Skip() @@ -157,17 +157,15 @@ class BrainSegmenterDialog(wx.Dialog): Publisher.sendMessage('Reload actual slice') def SetProgress(self, progress): - # self.progress.SetValue(progress * 100) - self.pg_dialog.Update(progress * 100) + self.progress.SetValue(progress * 100) + # self.pg_dialog.Update(progress * 100) wx.GetApp().Yield() def OnClose(self, evt): self.segmenter.stop = True - # self.btn_stop.Disable() + self.btn_stop.Disable() self.btn_segment.Enable() - # self.progress.SetValue(0) - if self.pg_dialog is not None: - self.pg_dialog.Destroy() + self.progress.SetValue(0) self.Destroy() -- libgit2 0.21.2