Commit 8ebf6adfe3e3dc5b55bdeb770ff0b3f8c2eb03c0
1 parent
138dc42c
Exists in
master
and in
2 other branches
Better watershed progress dialog
Showing
1 changed file
with
19 additions
and
35 deletions
Show diff stats
invesalius/data/styles.py
... | ... | @@ -819,41 +819,29 @@ class EditorInteractorStyle(DefaultInteractorStyle): |
819 | 819 | return x, y, z |
820 | 820 | |
821 | 821 | |
822 | -class WatershedProgressWindow(wx.Frame): | |
823 | - def __init__(self, process, parent=None): | |
824 | - wx.Frame.__init__(self, parent, -1) | |
822 | +class WatershedProgressWindow(object): | |
823 | + def __init__(self, process): | |
825 | 824 | self.process = process |
826 | - self._build_gui() | |
827 | - self._bind_wx_events() | |
828 | - self.timer = wx.Timer(self) | |
829 | - self.timer.Start(1000) | |
830 | - | |
831 | - def _build_gui(self): | |
832 | - self.gauge = wx.Gauge(self, -1, 100) | |
833 | - self.btn_cancel = wx.Button(self, wx.ID_CANCEL) | |
834 | - | |
835 | - sizer = wx.BoxSizer(wx.VERTICAL) | |
836 | - sizer.Add(wx.StaticText(self, -1, _("Applying watershed"))) | |
837 | - sizer.Add(self.gauge, 0, wx.EXPAND) | |
838 | - sizer.Add(self.btn_cancel, 0, wx.ALIGN_LEFT) | |
839 | - | |
840 | - self.SetSizer(sizer) | |
841 | - sizer.Fit(self) | |
842 | - self.Layout() | |
825 | + self.title = "InVesalius 3" | |
826 | + self.msg = _("Applying watershed ...") | |
827 | + self.style = wx.PD_APP_MODAL | wx.PD_APP_MODAL | wx.PD_CAN_ABORT | |
843 | 828 | |
844 | - def __del__(self): | |
845 | - self.timer.Stop() | |
829 | + self.dlg = wx.ProgressDialog(self.title, | |
830 | + self.msg, | |
831 | + parent = None, | |
832 | + style = self.style) | |
846 | 833 | |
847 | - def _bind_wx_events(self): | |
848 | - self.Bind(wx.EVT_TIMER, self.TimeHandler) | |
849 | - self.btn_cancel.Bind(wx.EVT_BUTTON, self.on_cancel) | |
834 | + self.dlg.Bind(wx.EVT_BUTTON, self.Cancel) | |
835 | + self.dlg.Show() | |
850 | 836 | |
851 | - def on_cancel(self, evt): | |
852 | - self.timer.Stop() | |
837 | + def Cancel(self, evt): | |
853 | 838 | self.process.terminate() |
854 | 839 | |
855 | - def TimeHandler(self, evt): | |
856 | - self.gauge.Pulse() | |
840 | + def Update(self): | |
841 | + self.dlg.Pulse() | |
842 | + | |
843 | + def Close(self): | |
844 | + self.dlg.Destroy() | |
857 | 845 | |
858 | 846 | |
859 | 847 | class WatershedConfig(object): |
... | ... | @@ -1338,18 +1326,14 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): |
1338 | 1326 | self.config.use_ww_wl, wl, ww, q)) |
1339 | 1327 | |
1340 | 1328 | wp = WatershedProgressWindow(p) |
1341 | - wp.Center(wx.BOTH) | |
1342 | - wp.Show() | |
1343 | - wp.MakeModal() | |
1344 | - | |
1345 | 1329 | p.start() |
1346 | 1330 | |
1347 | 1331 | while q.empty() and p.is_alive(): |
1348 | 1332 | time.sleep(0.5) |
1333 | + wp.Update() | |
1349 | 1334 | wx.Yield() |
1350 | 1335 | |
1351 | - wp.MakeModal(False) | |
1352 | - wp.Destroy() | |
1336 | + wp.Close() | |
1353 | 1337 | del wp |
1354 | 1338 | |
1355 | 1339 | if q.empty(): | ... | ... |