Commit 4678f3c8d894a28da3c76bc5044e352709be3091
1 parent
5a6cf097
Exists in
master
Added an label showing the time in brain segmenter dialog
Showing
1 changed file
with
34 additions
and
1 deletions
Show diff stats
invesalius/gui/brain_seg_dialog.py
| ... | ... | @@ -5,6 +5,7 @@ import importlib |
| 5 | 5 | import os |
| 6 | 6 | import pathlib |
| 7 | 7 | import sys |
| 8 | +import time | |
| 8 | 9 | |
| 9 | 10 | import wx |
| 10 | 11 | from wx.lib.pubsub import pub as Publisher |
| ... | ... | @@ -72,6 +73,8 @@ class BrainSegmenterDialog(wx.Dialog): |
| 72 | 73 | w, h = self.CalcSizeFromTextSize("MMMMM") |
| 73 | 74 | self.txt_threshold.SetMinClientSize((w, -1)) |
| 74 | 75 | self.progress = wx.Gauge(self, -1) |
| 76 | + self.lbl_progress_caption = wx.StaticText(self, -1, _("Elapsed time:")) | |
| 77 | + self.lbl_time = wx.StaticText(self, -1, _("00:00:00")) | |
| 75 | 78 | self.btn_segment = wx.Button(self, wx.ID_ANY, _("Segment")) |
| 76 | 79 | self.btn_stop = wx.Button(self, wx.ID_ANY, _("Stop")) |
| 77 | 80 | self.btn_stop.Disable() |
| ... | ... | @@ -79,6 +82,8 @@ class BrainSegmenterDialog(wx.Dialog): |
| 79 | 82 | |
| 80 | 83 | self.txt_threshold.SetValue("{:3d}%".format(self.sld_threshold.GetValue())) |
| 81 | 84 | |
| 85 | + self.elapsed_time_timer = wx.Timer() | |
| 86 | + | |
| 82 | 87 | self.__do_layout() |
| 83 | 88 | self.__set_events() |
| 84 | 89 | |
| ... | ... | @@ -102,6 +107,10 @@ class BrainSegmenterDialog(wx.Dialog): |
| 102 | 107 | sizer_3.Add(self.txt_threshold, 0, wx.ALL, 5) |
| 103 | 108 | main_sizer.Add(sizer_3, 0, wx.EXPAND, 0) |
| 104 | 109 | main_sizer.Add(self.progress, 0, wx.EXPAND | wx.ALL, 5) |
| 110 | + time_sizer = wx.BoxSizer(wx.HORIZONTAL) | |
| 111 | + time_sizer.Add(self.lbl_progress_caption, 0, wx.EXPAND, 0) | |
| 112 | + time_sizer.Add(self.lbl_time, 1, wx.EXPAND | wx.LEFT, 5) | |
| 113 | + main_sizer.Add(time_sizer, 0, wx.EXPAND | wx.ALL, 5) | |
| 105 | 114 | sizer_buttons = wx.BoxSizer(wx.HORIZONTAL) |
| 106 | 115 | sizer_buttons.Add(self.btn_close, 0, wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT | wx.ALL, 5) |
| 107 | 116 | sizer_buttons.Add(self.btn_stop, 0, wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT | wx.ALL, 5) |
| ... | ... | @@ -114,6 +123,7 @@ class BrainSegmenterDialog(wx.Dialog): |
| 114 | 123 | self.main_sizer = main_sizer |
| 115 | 124 | |
| 116 | 125 | self.OnSetBackend() |
| 126 | + self.HideProgress() | |
| 117 | 127 | |
| 118 | 128 | self.Layout() |
| 119 | 129 | self.Centre() |
| ... | ... | @@ -125,6 +135,7 @@ class BrainSegmenterDialog(wx.Dialog): |
| 125 | 135 | self.btn_segment.Bind(wx.EVT_BUTTON, self.OnSegment) |
| 126 | 136 | self.btn_stop.Bind(wx.EVT_BUTTON, self.OnStop) |
| 127 | 137 | self.btn_close.Bind(wx.EVT_BUTTON, self.OnBtnClose) |
| 138 | + self.elapsed_time_timer.Bind(wx.EVT_TIMER, self.OnTickTimer) | |
| 128 | 139 | self.Bind(wx.EVT_CLOSE, self.OnClose) |
| 129 | 140 | |
| 130 | 141 | def CalcSizeFromTextSize(self, text): |
| ... | ... | @@ -174,6 +185,9 @@ class BrainSegmenterDialog(wx.Dialog): |
| 174 | 185 | Publisher.sendMessage('Reload actual slice') |
| 175 | 186 | |
| 176 | 187 | def OnSegment(self, evt): |
| 188 | + self.ShowProgress() | |
| 189 | + self.t0 = time.time() | |
| 190 | + self.elapsed_time_timer.Start(1000) | |
| 177 | 191 | image = slc.Slice().matrix |
| 178 | 192 | backend = self.cb_backends.GetValue() |
| 179 | 193 | try: |
| ... | ... | @@ -192,6 +206,7 @@ class BrainSegmenterDialog(wx.Dialog): |
| 192 | 206 | self.btn_close.Enable() |
| 193 | 207 | self.btn_stop.Disable() |
| 194 | 208 | self.btn_segment.Enable() |
| 209 | + self.elapsed_time_timer.Stop() | |
| 195 | 210 | evt.Skip() |
| 196 | 211 | |
| 197 | 212 | def OnBtnClose(self, evt): |
| ... | ... | @@ -202,12 +217,16 @@ class BrainSegmenterDialog(wx.Dialog): |
| 202 | 217 | self.btn_stop.Disable() |
| 203 | 218 | self.btn_segment.Disable() |
| 204 | 219 | Publisher.sendMessage('Reload actual slice') |
| 220 | + self.elapsed_time_timer.Stop() | |
| 205 | 221 | |
| 206 | 222 | def SetProgress(self, progress): |
| 207 | 223 | self.progress.SetValue(progress * 100) |
| 208 | - # self.pg_dialog.Update(progress * 100) | |
| 209 | 224 | wx.GetApp().Yield() |
| 210 | 225 | |
| 226 | + def OnTickTimer(self, evt): | |
| 227 | + fmt='%H:%M:%S' | |
| 228 | + self.lbl_time.SetLabel(time.strftime(fmt, time.gmtime(time.time()-self.t0))) | |
| 229 | + | |
| 211 | 230 | def OnClose(self, evt): |
| 212 | 231 | self.segmenter.stop = True |
| 213 | 232 | self.btn_stop.Disable() |
| ... | ... | @@ -215,6 +234,20 @@ class BrainSegmenterDialog(wx.Dialog): |
| 215 | 234 | self.progress.SetValue(0) |
| 216 | 235 | self.Destroy() |
| 217 | 236 | |
| 237 | + def HideProgress(self): | |
| 238 | + self.progress.Hide() | |
| 239 | + self.lbl_progress_caption.Hide() | |
| 240 | + self.lbl_time.Hide() | |
| 241 | + self.main_sizer.Fit(self) | |
| 242 | + self.main_sizer.SetSizeHints(self) | |
| 243 | + | |
| 244 | + def ShowProgress(self): | |
| 245 | + self.progress.Show() | |
| 246 | + self.lbl_progress_caption.Show() | |
| 247 | + self.lbl_time.Show() | |
| 248 | + self.main_sizer.Fit(self) | |
| 249 | + self.main_sizer.SetSizeHints(self) | |
| 250 | + | |
| 218 | 251 | |
| 219 | 252 | class MyApp(wx.App): |
| 220 | 253 | def OnInit(self): | ... | ... |