Commit 1e982e1666e36c626e0ce8dd3a01257c309ca39d

Authored by Thiago Franco de Moraes
1 parent 6b90198b
Exists in master

Created a dialog to show error and using it in brain segmentation errors

invesalius/gui/brain_seg_dialog.py
... ... @@ -16,6 +16,7 @@ from pubsub import pub as Publisher
16 16  
17 17 import invesalius.data.slice_ as slc
18 18 from invesalius.segmentation.brain import segment, utils
  19 +from invesalius.gui import dialogs
19 20  
20 21 HAS_THEANO = bool(importlib.util.find_spec("theano"))
21 22 HAS_PLAIDML = bool(importlib.util.find_spec("plaidml"))
... ... @@ -237,13 +238,13 @@ class BrainSegmenterDialog(wx.Dialog):
237 238 except (multiprocessing.ProcessError, OSError, ValueError) as err:
238 239 self.OnStop(None)
239 240 self.HideProgress()
240   - dlg = wx.MessageDialog(
  241 + dlg = dialogs.ErrorMessageBox(
241 242 None,
242 243 "It was not possible to start brain segmentation because:"
243 244 + "\n"
244 245 + str(err),
245 246 "Brain segmentation error",
246   - wx.ICON_ERROR | wx.OK,
  247 + # wx.ICON_ERROR | wx.OK,
247 248 )
248 249 dlg.ShowModal()
249 250  
... ... @@ -280,15 +281,15 @@ class BrainSegmenterDialog(wx.Dialog):
280 281 error, traceback = self.ps.exception
281 282 self.OnStop(None)
282 283 self.HideProgress()
283   - dlg = wx.MessageDialog(
  284 + dlg = dialogs.ErrorMessageBox(
284 285 None,
  286 + "Brain segmentation error",
285 287 "It was not possible to use brain segmentation because:"
286 288 + "\n"
287 289 + str(error)
288 290 + "\n"
289 291 + traceback,
290   - "Brain segmentation error",
291   - wx.ICON_ERROR | wx.OK,
  292 + # wx.ICON_ERROR | wx.OK,
292 293 )
293 294 dlg.ShowModal()
294 295 return
... ...
invesalius/gui/dialogs.py
... ... @@ -665,8 +665,8 @@ class MessageBox(wx.Dialog):
665 665 btnsizer.Realize()
666 666  
667 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 670 sizer.Add(btnsizer, 0, wx.ALIGN_CENTER_VERTICAL|wx.EXPAND|wx.ALL, 5)
671 671 self.SetSizer(sizer)
672 672 sizer.Fit(self)
... ... @@ -674,6 +674,33 @@ class MessageBox(wx.Dialog):
674 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 704 def SaveChangesDialog__Old(filename):
678 705 message = _("The project %s has been modified.\nSave changes?")%filename
679 706 dlg = MessageDialog(message)
... ...