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,6 +5,7 @@ import importlib | ||
5 | import os | 5 | import os |
6 | import pathlib | 6 | import pathlib |
7 | import sys | 7 | import sys |
8 | +import time | ||
8 | 9 | ||
9 | import wx | 10 | import wx |
10 | from wx.lib.pubsub import pub as Publisher | 11 | from wx.lib.pubsub import pub as Publisher |
@@ -72,6 +73,8 @@ class BrainSegmenterDialog(wx.Dialog): | @@ -72,6 +73,8 @@ class BrainSegmenterDialog(wx.Dialog): | ||
72 | w, h = self.CalcSizeFromTextSize("MMMMM") | 73 | w, h = self.CalcSizeFromTextSize("MMMMM") |
73 | self.txt_threshold.SetMinClientSize((w, -1)) | 74 | self.txt_threshold.SetMinClientSize((w, -1)) |
74 | self.progress = wx.Gauge(self, -1) | 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 | self.btn_segment = wx.Button(self, wx.ID_ANY, _("Segment")) | 78 | self.btn_segment = wx.Button(self, wx.ID_ANY, _("Segment")) |
76 | self.btn_stop = wx.Button(self, wx.ID_ANY, _("Stop")) | 79 | self.btn_stop = wx.Button(self, wx.ID_ANY, _("Stop")) |
77 | self.btn_stop.Disable() | 80 | self.btn_stop.Disable() |
@@ -79,6 +82,8 @@ class BrainSegmenterDialog(wx.Dialog): | @@ -79,6 +82,8 @@ class BrainSegmenterDialog(wx.Dialog): | ||
79 | 82 | ||
80 | self.txt_threshold.SetValue("{:3d}%".format(self.sld_threshold.GetValue())) | 83 | self.txt_threshold.SetValue("{:3d}%".format(self.sld_threshold.GetValue())) |
81 | 84 | ||
85 | + self.elapsed_time_timer = wx.Timer() | ||
86 | + | ||
82 | self.__do_layout() | 87 | self.__do_layout() |
83 | self.__set_events() | 88 | self.__set_events() |
84 | 89 | ||
@@ -102,6 +107,10 @@ class BrainSegmenterDialog(wx.Dialog): | @@ -102,6 +107,10 @@ class BrainSegmenterDialog(wx.Dialog): | ||
102 | sizer_3.Add(self.txt_threshold, 0, wx.ALL, 5) | 107 | sizer_3.Add(self.txt_threshold, 0, wx.ALL, 5) |
103 | main_sizer.Add(sizer_3, 0, wx.EXPAND, 0) | 108 | main_sizer.Add(sizer_3, 0, wx.EXPAND, 0) |
104 | main_sizer.Add(self.progress, 0, wx.EXPAND | wx.ALL, 5) | 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 | sizer_buttons = wx.BoxSizer(wx.HORIZONTAL) | 114 | sizer_buttons = wx.BoxSizer(wx.HORIZONTAL) |
106 | sizer_buttons.Add(self.btn_close, 0, wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT | wx.ALL, 5) | 115 | sizer_buttons.Add(self.btn_close, 0, wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT | wx.ALL, 5) |
107 | sizer_buttons.Add(self.btn_stop, 0, wx.ALIGN_BOTTOM | wx.ALIGN_RIGHT | wx.ALL, 5) | 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,6 +123,7 @@ class BrainSegmenterDialog(wx.Dialog): | ||
114 | self.main_sizer = main_sizer | 123 | self.main_sizer = main_sizer |
115 | 124 | ||
116 | self.OnSetBackend() | 125 | self.OnSetBackend() |
126 | + self.HideProgress() | ||
117 | 127 | ||
118 | self.Layout() | 128 | self.Layout() |
119 | self.Centre() | 129 | self.Centre() |
@@ -125,6 +135,7 @@ class BrainSegmenterDialog(wx.Dialog): | @@ -125,6 +135,7 @@ class BrainSegmenterDialog(wx.Dialog): | ||
125 | self.btn_segment.Bind(wx.EVT_BUTTON, self.OnSegment) | 135 | self.btn_segment.Bind(wx.EVT_BUTTON, self.OnSegment) |
126 | self.btn_stop.Bind(wx.EVT_BUTTON, self.OnStop) | 136 | self.btn_stop.Bind(wx.EVT_BUTTON, self.OnStop) |
127 | self.btn_close.Bind(wx.EVT_BUTTON, self.OnBtnClose) | 137 | self.btn_close.Bind(wx.EVT_BUTTON, self.OnBtnClose) |
138 | + self.elapsed_time_timer.Bind(wx.EVT_TIMER, self.OnTickTimer) | ||
128 | self.Bind(wx.EVT_CLOSE, self.OnClose) | 139 | self.Bind(wx.EVT_CLOSE, self.OnClose) |
129 | 140 | ||
130 | def CalcSizeFromTextSize(self, text): | 141 | def CalcSizeFromTextSize(self, text): |
@@ -174,6 +185,9 @@ class BrainSegmenterDialog(wx.Dialog): | @@ -174,6 +185,9 @@ class BrainSegmenterDialog(wx.Dialog): | ||
174 | Publisher.sendMessage('Reload actual slice') | 185 | Publisher.sendMessage('Reload actual slice') |
175 | 186 | ||
176 | def OnSegment(self, evt): | 187 | def OnSegment(self, evt): |
188 | + self.ShowProgress() | ||
189 | + self.t0 = time.time() | ||
190 | + self.elapsed_time_timer.Start(1000) | ||
177 | image = slc.Slice().matrix | 191 | image = slc.Slice().matrix |
178 | backend = self.cb_backends.GetValue() | 192 | backend = self.cb_backends.GetValue() |
179 | try: | 193 | try: |
@@ -192,6 +206,7 @@ class BrainSegmenterDialog(wx.Dialog): | @@ -192,6 +206,7 @@ class BrainSegmenterDialog(wx.Dialog): | ||
192 | self.btn_close.Enable() | 206 | self.btn_close.Enable() |
193 | self.btn_stop.Disable() | 207 | self.btn_stop.Disable() |
194 | self.btn_segment.Enable() | 208 | self.btn_segment.Enable() |
209 | + self.elapsed_time_timer.Stop() | ||
195 | evt.Skip() | 210 | evt.Skip() |
196 | 211 | ||
197 | def OnBtnClose(self, evt): | 212 | def OnBtnClose(self, evt): |
@@ -202,12 +217,16 @@ class BrainSegmenterDialog(wx.Dialog): | @@ -202,12 +217,16 @@ class BrainSegmenterDialog(wx.Dialog): | ||
202 | self.btn_stop.Disable() | 217 | self.btn_stop.Disable() |
203 | self.btn_segment.Disable() | 218 | self.btn_segment.Disable() |
204 | Publisher.sendMessage('Reload actual slice') | 219 | Publisher.sendMessage('Reload actual slice') |
220 | + self.elapsed_time_timer.Stop() | ||
205 | 221 | ||
206 | def SetProgress(self, progress): | 222 | def SetProgress(self, progress): |
207 | self.progress.SetValue(progress * 100) | 223 | self.progress.SetValue(progress * 100) |
208 | - # self.pg_dialog.Update(progress * 100) | ||
209 | wx.GetApp().Yield() | 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 | def OnClose(self, evt): | 230 | def OnClose(self, evt): |
212 | self.segmenter.stop = True | 231 | self.segmenter.stop = True |
213 | self.btn_stop.Disable() | 232 | self.btn_stop.Disable() |
@@ -215,6 +234,20 @@ class BrainSegmenterDialog(wx.Dialog): | @@ -215,6 +234,20 @@ class BrainSegmenterDialog(wx.Dialog): | ||
215 | self.progress.SetValue(0) | 234 | self.progress.SetValue(0) |
216 | self.Destroy() | 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 | class MyApp(wx.App): | 252 | class MyApp(wx.App): |
220 | def OnInit(self): | 253 | def OnInit(self): |