Commit c0b00a9c292c3bc5a7e9566762f2592c69cce8e6
1 parent
364be345
Exists in
master
and in
38 other branches
added a ok button to the dialog to config watershed
Showing
1 changed file
with
52 additions
and
42 deletions
Show diff stats
invesalius/gui/dialogs.py
@@ -104,7 +104,7 @@ class ResizeImageDialog(wx.Dialog): | @@ -104,7 +104,7 @@ class ResizeImageDialog(wx.Dialog): | ||
104 | pos=wx.DefaultPosition, | 104 | pos=wx.DefaultPosition, |
105 | style=wx.DEFAULT_DIALOG_STYLE) | 105 | style=wx.DEFAULT_DIALOG_STYLE) |
106 | self.PostCreate(pre) | 106 | self.PostCreate(pre) |
107 | - | 107 | + |
108 | lbl_message = wx.StaticText(self, -1, _("InVesalius is running on a 32-bit operating system or has insufficient memory. \nIf you want to work with 3D surfaces or volume rendering, \nit is recommended to reduce the medical images resolution.")) | 108 | lbl_message = wx.StaticText(self, -1, _("InVesalius is running on a 32-bit operating system or has insufficient memory. \nIf you want to work with 3D surfaces or volume rendering, \nit is recommended to reduce the medical images resolution.")) |
109 | icon = wx.ArtProvider.GetBitmap(wx.ART_WARNING, wx.ART_MESSAGE_BOX, (32,32)) | 109 | icon = wx.ArtProvider.GetBitmap(wx.ART_WARNING, wx.ART_MESSAGE_BOX, (32,32)) |
110 | bmp = wx.StaticBitmap(self, -1, icon) | 110 | bmp = wx.StaticBitmap(self, -1, icon) |
@@ -143,7 +143,7 @@ class ResizeImageDialog(wx.Dialog): | @@ -143,7 +143,7 @@ class ResizeImageDialog(wx.Dialog): | ||
143 | sizer_general.Fit(self) | 143 | sizer_general.Fit(self) |
144 | self.Layout() | 144 | self.Layout() |
145 | self.Centre() | 145 | self.Centre() |
146 | - | 146 | + |
147 | def SetValue(self, value): | 147 | def SetValue(self, value): |
148 | self.num_ctrl_porcent.SetValue(value) | 148 | self.num_ctrl_porcent.SetValue(value) |
149 | 149 | ||
@@ -611,7 +611,7 @@ class NewMask(wx.Dialog): | @@ -611,7 +611,7 @@ class NewMask(wx.Dialog): | ||
611 | thresh_min, thresh_max = project.threshold_modes[_("Bone")] | 611 | thresh_min, thresh_max = project.threshold_modes[_("Bone")] |
612 | original_colour = random.choice(const.MASK_COLOUR) | 612 | original_colour = random.choice(const.MASK_COLOUR) |
613 | self.colour = original_colour | 613 | self.colour = original_colour |
614 | - colour = [255*i for i in original_colour] | 614 | + colour = [255*i for i in original_colour] |
615 | colour.append(100) | 615 | colour.append(100) |
616 | gradient = grad.GradientSlider(self, -1, int(bound_min), | 616 | gradient = grad.GradientSlider(self, -1, int(bound_min), |
617 | int(bound_max), | 617 | int(bound_max), |
@@ -673,7 +673,7 @@ class NewMask(wx.Dialog): | @@ -673,7 +673,7 @@ class NewMask(wx.Dialog): | ||
673 | proj = prj.Project() | 673 | proj = prj.Project() |
674 | if thresh in proj.threshold_modes.values(): | 674 | if thresh in proj.threshold_modes.values(): |
675 | preset_name = proj.threshold_modes.get_key(thresh)[0] | 675 | preset_name = proj.threshold_modes.get_key(thresh)[0] |
676 | - index = self.thresh_list.index(preset_name) | 676 | + index = self.thresh_list.index(preset_name) |
677 | self.combo_thresh.SetSelection(index) | 677 | self.combo_thresh.SetSelection(index) |
678 | else: | 678 | else: |
679 | index = self.thresh_list.index(_("Custom")) | 679 | index = self.thresh_list.index(_("Custom")) |
@@ -797,7 +797,7 @@ def ShowAboutDialog(parent): | @@ -797,7 +797,7 @@ def ShowAboutDialog(parent): | ||
797 | "Sebastian Hilbert", | 797 | "Sebastian Hilbert", |
798 | "Semarang Pari"] | 798 | "Semarang Pari"] |
799 | 799 | ||
800 | - #info.DocWriters = ["Fabio Francisco da Silva (PT)"] | 800 | + #info.DocWriters = ["Fabio Francisco da Silva (PT)"] |
801 | 801 | ||
802 | info.Artists = ["Otavio Henrique Junqueira Amorim"] | 802 | info.Artists = ["Otavio Henrique Junqueira Amorim"] |
803 | 803 | ||
@@ -1101,7 +1101,7 @@ class SurfaceCreationOptionsPanel(wx.Panel): | @@ -1101,7 +1101,7 @@ class SurfaceCreationOptionsPanel(wx.Panel): | ||
1101 | import constants as const | 1101 | import constants as const |
1102 | import data.surface as surface | 1102 | import data.surface as surface |
1103 | import project as prj | 1103 | import project as prj |
1104 | - | 1104 | + |
1105 | wx.Panel.__init__(self, parent, ID) | 1105 | wx.Panel.__init__(self, parent, ID) |
1106 | 1106 | ||
1107 | # LINE 1: Surface name | 1107 | # LINE 1: Surface name |
@@ -1208,7 +1208,7 @@ class CAOptions(wx.Panel): | @@ -1208,7 +1208,7 @@ class CAOptions(wx.Panel): | ||
1208 | def __init__(self, parent): | 1208 | def __init__(self, parent): |
1209 | wx.Panel.__init__(self, parent, -1) | 1209 | wx.Panel.__init__(self, parent, -1) |
1210 | self._build_widgets() | 1210 | self._build_widgets() |
1211 | - | 1211 | + |
1212 | def _build_widgets(self): | 1212 | def _build_widgets(self): |
1213 | sb = wx.StaticBox(self, -1, _('Options')) | 1213 | sb = wx.StaticBox(self, -1, _('Options')) |
1214 | self.angle = floatspin.FloatSpin(self, -1, value=0.7, min_val=0.0, | 1214 | self.angle = floatspin.FloatSpin(self, -1, value=0.7, min_val=0.0, |
@@ -1222,7 +1222,7 @@ class CAOptions(wx.Panel): | @@ -1222,7 +1222,7 @@ class CAOptions(wx.Panel): | ||
1222 | self.min_weight = floatspin.FloatSpin(self, -1, value=0.2, min_val=0.0, | 1222 | self.min_weight = floatspin.FloatSpin(self, -1, value=0.2, min_val=0.0, |
1223 | max_val=1.0, increment=0.1, | 1223 | max_val=1.0, increment=0.1, |
1224 | digits=1) | 1224 | digits=1) |
1225 | - | 1225 | + |
1226 | self.steps = wx.SpinCtrl(self, -1, value='10', min=1, max=100) | 1226 | self.steps = wx.SpinCtrl(self, -1, value='10', min=1, max=100) |
1227 | 1227 | ||
1228 | layout_sizer = wx.FlexGridSizer(rows=4, cols=2, hgap=5, vgap=5) | 1228 | layout_sizer = wx.FlexGridSizer(rows=4, cols=2, hgap=5, vgap=5) |
@@ -1285,7 +1285,7 @@ class SurfaceMethodPanel(wx.Panel): | @@ -1285,7 +1285,7 @@ class SurfaceMethodPanel(wx.Panel): | ||
1285 | self.SetSizer(self.main_sizer) | 1285 | self.SetSizer(self.main_sizer) |
1286 | self.Layout() | 1286 | self.Layout() |
1287 | self.Fit() | 1287 | self.Fit() |
1288 | - | 1288 | + |
1289 | if self.mask_edited: | 1289 | if self.mask_edited: |
1290 | self.cb_types.SetValue(_(u'Context aware smoothing')) | 1290 | self.cb_types.SetValue(_(u'Context aware smoothing')) |
1291 | self.ca_options.Enable() | 1291 | self.ca_options.Enable() |
@@ -1324,9 +1324,9 @@ class SurfaceMethodPanel(wx.Panel): | @@ -1324,9 +1324,9 @@ class SurfaceMethodPanel(wx.Panel): | ||
1324 | algorithm = self.GetAlgorithmSelected() | 1324 | algorithm = self.GetAlgorithmSelected() |
1325 | options = self.GetOptions() | 1325 | options = self.GetOptions() |
1326 | 1326 | ||
1327 | - return {"algorithm": algorithm, | 1327 | + return {"algorithm": algorithm, |
1328 | "options": options} | 1328 | "options": options} |
1329 | - | 1329 | + |
1330 | def ReloadMethodsOptions(self): | 1330 | def ReloadMethodsOptions(self): |
1331 | self.cb_types.Clear() | 1331 | self.cb_types.Clear() |
1332 | self.cb_types.AppendItems([i for i in sorted(self.alg_types) | 1332 | self.cb_types.AppendItems([i for i in sorted(self.alg_types) |
@@ -1388,32 +1388,37 @@ class ClutImagedataDialog(wx.Dialog): | @@ -1388,32 +1388,37 @@ class ClutImagedataDialog(wx.Dialog): | ||
1388 | if gen_evt: | 1388 | if gen_evt: |
1389 | self.clut_widget._generate_event() | 1389 | self.clut_widget._generate_event() |
1390 | 1390 | ||
1391 | - | ||
1392 | -class WatershedOptions(wx.Panel): | ||
1393 | - def __init__(self, parent): | 1391 | + |
1392 | +class WatershedOptionsPanel(wx.Panel): | ||
1393 | + def __init__(self, parent, config): | ||
1394 | wx.Panel.__init__(self, parent) | 1394 | wx.Panel.__init__(self, parent) |
1395 | - | 1395 | + |
1396 | self.algorithms = ("Watershed", "Watershed IFT") | 1396 | self.algorithms = ("Watershed", "Watershed IFT") |
1397 | self.con2d_choices = (4, 8) | 1397 | self.con2d_choices = (4, 8) |
1398 | self.con3d_choices = (6, 18, 26) | 1398 | self.con3d_choices = (6, 18, 26) |
1399 | 1399 | ||
1400 | + self.config = config | ||
1401 | + | ||
1400 | self._init_gui() | 1402 | self._init_gui() |
1401 | - self._bind_events() | ||
1402 | 1403 | ||
1403 | def _init_gui(self): | 1404 | def _init_gui(self): |
1404 | self.choice_algorithm = wx.RadioBox(self, -1, "Algorithm", | 1405 | self.choice_algorithm = wx.RadioBox(self, -1, "Algorithm", |
1405 | - choices=("Watershed", "Watershed IFT"), | 1406 | + choices=self.algorithms, |
1406 | style=wx.NO_BORDER | wx.HORIZONTAL) | 1407 | style=wx.NO_BORDER | wx.HORIZONTAL) |
1408 | + self.choice_algorithm.SetSelection(self.algorithms.index(self.config.algorithm)) | ||
1407 | 1409 | ||
1408 | self.choice_2dcon = wx.RadioBox(self, -1, "2D", | 1410 | self.choice_2dcon = wx.RadioBox(self, -1, "2D", |
1409 | choices=[str(i) for i in self.con2d_choices], | 1411 | choices=[str(i) for i in self.con2d_choices], |
1410 | style=wx.NO_BORDER | wx.HORIZONTAL) | 1412 | style=wx.NO_BORDER | wx.HORIZONTAL) |
1413 | + self.choice_2dcon.SetSelection(self.con2d_choices.index(self.config.con_2d)) | ||
1411 | 1414 | ||
1412 | self.choice_3dcon = wx.RadioBox(self, -1, "3D", | 1415 | self.choice_3dcon = wx.RadioBox(self, -1, "3D", |
1413 | choices=[str(i) for i in self.con3d_choices], | 1416 | choices=[str(i) for i in self.con3d_choices], |
1414 | style=wx.NO_BORDER | wx.HORIZONTAL) | 1417 | style=wx.NO_BORDER | wx.HORIZONTAL) |
1418 | + self.choice_3dcon.SetSelection(self.con3d_choices.index(self.config.con_3d)) | ||
1415 | 1419 | ||
1416 | self.gaussian_size = wx.SpinCtrl(self, -1, "", min=1, max=10) | 1420 | self.gaussian_size = wx.SpinCtrl(self, -1, "", min=1, max=10) |
1421 | + self.gaussian_size.SetValue(self.config.mg_size) | ||
1417 | 1422 | ||
1418 | box_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Conectivity"), wx.VERTICAL) | 1423 | box_sizer = wx.StaticBoxSizer(wx.StaticBox(self, -1, "Conectivity"), wx.VERTICAL) |
1419 | box_sizer.Add(self.choice_2dcon, 0, wx.ALIGN_CENTER_VERTICAL,2) | 1424 | box_sizer.Add(self.choice_2dcon, 0, wx.ALIGN_CENTER_VERTICAL,2) |
@@ -1432,47 +1437,52 @@ class WatershedOptions(wx.Panel): | @@ -1432,47 +1437,52 @@ class WatershedOptions(wx.Panel): | ||
1432 | sizer.Fit(self) | 1437 | sizer.Fit(self) |
1433 | self.Layout() | 1438 | self.Layout() |
1434 | 1439 | ||
1435 | - def _bind_events(self): | ||
1436 | - self.choice_algorithm.Bind(wx.EVT_RADIOBOX, self.OnSetAlgorithm) | ||
1437 | - self.gaussian_size.Bind(wx.EVT_SPINCTRL, self.OnSetGaussianSize) | ||
1438 | - self.choice_2dcon.Bind(wx.EVT_RADIOBOX, self.OnSetCon2D) | ||
1439 | - self.choice_3dcon.Bind(wx.EVT_RADIOBOX, self.OnSetCon3D) | ||
1440 | - | ||
1441 | - def OnSetAlgorithm(self, evt): | ||
1442 | - v = self.algorithms[evt.GetInt()] | ||
1443 | - Publisher.sendMessage("Set watershed algorithm", v) | ||
1444 | - | ||
1445 | - def OnSetGaussianSize(self, evt): | ||
1446 | - v = self.gaussian_size.GetValue() | ||
1447 | - Publisher.sendMessage("Set watershed gaussian size", v) | ||
1448 | - | ||
1449 | - def OnSetCon2D(self, evt): | ||
1450 | - v = self.con2d_choices[evt.GetInt()] | ||
1451 | - Publisher.sendMessage("Set watershed 2d con", v) | ||
1452 | - | ||
1453 | - def OnSetCon3D(self, evt): | ||
1454 | - v = self.con3d_choices[evt.GetInt()] | ||
1455 | - Publisher.sendMessage("Set watershed 3d con", v) | 1440 | + def apply_options(self): |
1441 | + self.config.algorithm = self.algorithms[self.choice_algorithm.GetSelection()] | ||
1442 | + self.config.con_2d = self.con2d_choices[self.choice_2dcon.GetSelection()] | ||
1443 | + self.config.con_3d = self.con3d_choices[self.choice_3dcon.GetSelection()] | ||
1444 | + self.config.mg_size = self.gaussian_size.GetValue() | ||
1456 | 1445 | ||
1457 | 1446 | ||
1458 | class WatershedOptionsDialog(wx.Dialog): | 1447 | class WatershedOptionsDialog(wx.Dialog): |
1459 | - def __init__(self): | 1448 | + def __init__(self, config): |
1460 | pre = wx.PreDialog() | 1449 | pre = wx.PreDialog() |
1461 | pre.Create(wx.GetApp().GetTopWindow(), -1, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | 1450 | pre.Create(wx.GetApp().GetTopWindow(), -1, style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) |
1462 | self.PostCreate(pre) | 1451 | self.PostCreate(pre) |
1463 | 1452 | ||
1453 | + self.config = config | ||
1454 | + | ||
1464 | self._init_gui() | 1455 | self._init_gui() |
1465 | 1456 | ||
1466 | def _init_gui(self): | 1457 | def _init_gui(self): |
1467 | - wop = WatershedOptions(self) | 1458 | + wop = WatershedOptionsPanel(self, self.config) |
1459 | + self.wop = wop | ||
1460 | + | ||
1461 | + sizer = wx.BoxSizer(wx.VERTICAL) | ||
1462 | + | ||
1463 | + btn_ok = wx.Button(self, wx.ID_OK) | ||
1464 | + btn_ok.SetDefault() | ||
1465 | + | ||
1466 | + btn_cancel = wx.Button(self, wx.ID_CANCEL) | ||
1467 | + | ||
1468 | + btnsizer = wx.StdDialogButtonSizer() | ||
1469 | + btnsizer.AddButton(btn_ok) | ||
1470 | + btnsizer.AddButton(btn_cancel) | ||
1471 | + btnsizer.Realize() | ||
1468 | 1472 | ||
1469 | - sizer = wx.BoxSizer(wx.VERTICAL) | ||
1470 | sizer.Add(wop, 0, wx.EXPAND) | 1473 | sizer.Add(wop, 0, wx.EXPAND) |
1474 | + sizer.Add(btnsizer, 0, wx.EXPAND) | ||
1475 | + sizer.AddSpacer(5) | ||
1471 | 1476 | ||
1472 | self.SetSizer(sizer) | 1477 | self.SetSizer(sizer) |
1473 | sizer.Fit(self) | 1478 | sizer.Fit(self) |
1474 | self.Layout() | 1479 | self.Layout() |
1475 | 1480 | ||
1481 | + btn_ok.Bind(wx.EVT_BUTTON, self.OnOk) | ||
1482 | + | ||
1483 | + def OnOk(self, evt): | ||
1484 | + self.wop.apply_options() | ||
1485 | + evt.Skip() | ||
1476 | 1486 | ||
1477 | class MaskBooleanDialog(wx.Dialog): | 1487 | class MaskBooleanDialog(wx.Dialog): |
1478 | def __init__(self, masks): | 1488 | def __init__(self, masks): |
@@ -1500,7 +1510,7 @@ class MaskBooleanDialog(wx.Dialog): | @@ -1500,7 +1510,7 @@ class MaskBooleanDialog(wx.Dialog): | ||
1500 | 1510 | ||
1501 | icon_folder = '../icons/' | 1511 | icon_folder = '../icons/' |
1502 | op_choices = ((_(u"Union"), const.BOOLEAN_UNION, 'bool_union.png'), | 1512 | op_choices = ((_(u"Union"), const.BOOLEAN_UNION, 'bool_union.png'), |
1503 | - (_(u"Difference"), const.BOOLEAN_DIFF, 'bool_difference.png'), | 1513 | + (_(u"Difference"), const.BOOLEAN_DIFF, 'bool_difference.png'), |
1504 | (_(u"Intersection"), const.BOOLEAN_AND, 'bool_intersection.png'), | 1514 | (_(u"Intersection"), const.BOOLEAN_AND, 'bool_intersection.png'), |
1505 | (_(u"Exclusive disjunction"), const.BOOLEAN_XOR, 'bool_disjunction.png')) | 1515 | (_(u"Exclusive disjunction"), const.BOOLEAN_XOR, 'bool_disjunction.png')) |
1506 | self.op_boolean = wx.combo.BitmapComboBox(self, -1, op_choices[0][0], choices=[]) | 1516 | self.op_boolean = wx.combo.BitmapComboBox(self, -1, op_choices[0][0], choices=[]) |