Commit 1e982e1666e36c626e0ce8dd3a01257c309ca39d
1 parent
6b90198b
Exists in
master
Created a dialog to show error and using it in brain segmentation errors
Showing
2 changed files
with
35 additions
and
7 deletions
Show diff stats
invesalius/gui/brain_seg_dialog.py
@@ -16,6 +16,7 @@ from pubsub import pub as Publisher | @@ -16,6 +16,7 @@ from pubsub import pub as Publisher | ||
16 | 16 | ||
17 | import invesalius.data.slice_ as slc | 17 | import invesalius.data.slice_ as slc |
18 | from invesalius.segmentation.brain import segment, utils | 18 | from invesalius.segmentation.brain import segment, utils |
19 | +from invesalius.gui import dialogs | ||
19 | 20 | ||
20 | HAS_THEANO = bool(importlib.util.find_spec("theano")) | 21 | HAS_THEANO = bool(importlib.util.find_spec("theano")) |
21 | HAS_PLAIDML = bool(importlib.util.find_spec("plaidml")) | 22 | HAS_PLAIDML = bool(importlib.util.find_spec("plaidml")) |
@@ -237,13 +238,13 @@ class BrainSegmenterDialog(wx.Dialog): | @@ -237,13 +238,13 @@ class BrainSegmenterDialog(wx.Dialog): | ||
237 | except (multiprocessing.ProcessError, OSError, ValueError) as err: | 238 | except (multiprocessing.ProcessError, OSError, ValueError) as err: |
238 | self.OnStop(None) | 239 | self.OnStop(None) |
239 | self.HideProgress() | 240 | self.HideProgress() |
240 | - dlg = wx.MessageDialog( | 241 | + dlg = dialogs.ErrorMessageBox( |
241 | None, | 242 | None, |
242 | "It was not possible to start brain segmentation because:" | 243 | "It was not possible to start brain segmentation because:" |
243 | + "\n" | 244 | + "\n" |
244 | + str(err), | 245 | + str(err), |
245 | "Brain segmentation error", | 246 | "Brain segmentation error", |
246 | - wx.ICON_ERROR | wx.OK, | 247 | + # wx.ICON_ERROR | wx.OK, |
247 | ) | 248 | ) |
248 | dlg.ShowModal() | 249 | dlg.ShowModal() |
249 | 250 | ||
@@ -280,15 +281,15 @@ class BrainSegmenterDialog(wx.Dialog): | @@ -280,15 +281,15 @@ class BrainSegmenterDialog(wx.Dialog): | ||
280 | error, traceback = self.ps.exception | 281 | error, traceback = self.ps.exception |
281 | self.OnStop(None) | 282 | self.OnStop(None) |
282 | self.HideProgress() | 283 | self.HideProgress() |
283 | - dlg = wx.MessageDialog( | 284 | + dlg = dialogs.ErrorMessageBox( |
284 | None, | 285 | None, |
286 | + "Brain segmentation error", | ||
285 | "It was not possible to use brain segmentation because:" | 287 | "It was not possible to use brain segmentation because:" |
286 | + "\n" | 288 | + "\n" |
287 | + str(error) | 289 | + str(error) |
288 | + "\n" | 290 | + "\n" |
289 | + traceback, | 291 | + traceback, |
290 | - "Brain segmentation error", | ||
291 | - wx.ICON_ERROR | wx.OK, | 292 | + # wx.ICON_ERROR | wx.OK, |
292 | ) | 293 | ) |
293 | dlg.ShowModal() | 294 | dlg.ShowModal() |
294 | return | 295 | return |
invesalius/gui/dialogs.py
@@ -665,8 +665,8 @@ class MessageBox(wx.Dialog): | @@ -665,8 +665,8 @@ class MessageBox(wx.Dialog): | ||
665 | btnsizer.Realize() | 665 | btnsizer.Realize() |
666 | 666 | ||
667 | sizer = wx.BoxSizer(wx.VERTICAL) | 667 | sizer = wx.BoxSizer(wx.VERTICAL) |
668 | - sizer.Add(title_label, 0, wx.ALIGN_CENTRE|wx.ALL|wx.EXPAND, 5) | ||
669 | - sizer.Add(text, 1, wx.ALIGN_CENTRE|wx.ALL|wx.EXPAND, 5) | 668 | + sizer.Add(title_label, 0, wx.ALL | wx.EXPAND, 5) |
669 | + sizer.Add(text, 1, wx.ALL | wx.EXPAND, 5) | ||
670 | sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.EXPAND|wx.ALL, 5) | 670 | sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.EXPAND|wx.ALL, 5) |
671 | self.SetSizer(sizer) | 671 | self.SetSizer(sizer) |
672 | sizer.Fit(self) | 672 | sizer.Fit(self) |
@@ -674,6 +674,33 @@ class MessageBox(wx.Dialog): | @@ -674,6 +674,33 @@ class MessageBox(wx.Dialog): | ||
674 | self.ShowModal() | 674 | self.ShowModal() |
675 | 675 | ||
676 | 676 | ||
677 | +class ErrorMessageBox(wx.Dialog): | ||
678 | + def __init__(self, parent, title, message, caption="InVesalius3 Error"): | ||
679 | + wx.Dialog.__init__(self, parent, title=caption, style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER) | ||
680 | + | ||
681 | + title_label = wx.StaticText(self, -1, title) | ||
682 | + | ||
683 | + text = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_READONLY|wx.BORDER_NONE) | ||
684 | + text.SetValue(message) | ||
685 | + text.SetBackgroundColour(wx.SystemSettings.GetColour(4)) | ||
686 | + | ||
687 | + width, height = text.GetTextExtent("M"*60) | ||
688 | + text.SetMinSize((width, -1)) | ||
689 | + | ||
690 | + btn_ok = wx.Button(self, wx.ID_OK) | ||
691 | + btnsizer = wx.StdDialogButtonSizer() | ||
692 | + btnsizer.AddButton(btn_ok) | ||
693 | + btnsizer.Realize() | ||
694 | + | ||
695 | + sizer = wx.BoxSizer(wx.VERTICAL) | ||
696 | + sizer.Add(title_label, 0, wx.ALL | wx.EXPAND, 5) | ||
697 | + sizer.Add(text, 1, wx.ALL | wx.EXPAND, 5) | ||
698 | + sizer.Add(btnsizer, 0, wx.EXPAND | wx.ALL, 5) | ||
699 | + self.SetSizer(sizer) | ||
700 | + sizer.Fit(self) | ||
701 | + self.Center() | ||
702 | + | ||
703 | + | ||
677 | def SaveChangesDialog__Old(filename): | 704 | def SaveChangesDialog__Old(filename): |
678 | message = _("The project %s has been modified.\nSave changes?")%filename | 705 | message = _("The project %s has been modified.\nSave changes?")%filename |
679 | dlg = MessageDialog(message) | 706 | dlg = MessageDialog(message) |