def validate_input_ranges(self):
        """Validates input ranges specified by the input widgets.

        This method uses CellProfiler's validate methods on settings to test
        whether the ranges specified on the UI are acceptable. When these do
        not validate, the user is shown an error message that lists all
        violations as well as the error message received back from CellProfiler.
        """
        # First, test whether selected parameters are valid
        message = ''
        for i, checkbox in enumerate(self.__check_box_list):
            if checkbox.IsChecked():
                setting = self.__module.setting(self.__parameters_list[i][1])
                input_size = self.get_parameter_input_size(setting)
                if input_size == 1:
                    widget_idx = self.__parameters_to_widgets_list[i][0]
                    lower_value = self.__lower_bound_spin_ctrl_list[
                        widget_idx].GetValue()
                    upper_value = self.__upper_bound_spin_ctrl_list[
                        widget_idx].GetValue()
                elif input_size == 2:
                    widget_idx = self.__parameters_to_widgets_list[i][0]
                    lower_value = (
                        self.__lower_bound_spin_ctrl_list[widget_idx].GetValue(
                        ), self.__lower_bound_spin_ctrl_list[widget_idx +
                                                             1].GetValue())
                    upper_value = (
                        self.__upper_bound_spin_ctrl_list[widget_idx].GetValue(
                        ), self.__upper_bound_spin_ctrl_list[widget_idx +
                                                             1].GetValue())

                old_value = setting.get_value()
                try:
                    setting.set_value(lower_value)
                    setting.test_valid(self.__pipeline)
                except cellprofiler.setting.ValidationError as instance:
                    message += '\'' + str(setting.get_text()) + \
                               '\': lower bound invalid, ' + \
                               '\n\t' + str(instance.message) + '\n'
                try:
                    setting.set_value(upper_value)
                    setting.test_valid(self.__pipeline)
                except cellprofiler.setting.ValidationError as instance:
                    message += '\'' + str(setting.get_text()) + \
                               '\': upper bound invalid, ' + \
                               '\n\t' + str(instance.message) + '\n'
                setting.set_value(old_value)

        # Second, if there are invalid parameters, tell the user
        if len(message) > 0:
            message = 'Invalid sample settings:\n\n' + message
            dialog = wx.MessageDialog(self,
                                      message,
                                      caption='Sample settings error',
                                      style=wx.ICON_ERROR | wx.OK)
            dialog.ShowModal()
            raise Exception(message)
    def validate_input_ranges(self):
        """Validates input ranges specified by the input widgets.

        This method uses CellProfiler's validate methods on settings to test
        whether the ranges specified on the UI are acceptable. When these do
        not validate, the user is shown an error message that lists all
        violations as well as the error message received back from CellProfiler.
        """
        # First, test whether selected parameters are valid
        message = ''
        for i, checkbox in enumerate(self.__check_box_list):
            if checkbox.IsChecked():
                setting = self.__module.setting(self.__parameters_list[i][1])
                input_size = self.get_parameter_input_size(setting)
                if input_size == 1:
                    widget_idx = self.__parameters_to_widgets_list[i][0]
                    lower_value = self.__lower_bound_spin_ctrl_list[widget_idx].GetValue()
                    upper_value = self.__upper_bound_spin_ctrl_list[widget_idx].GetValue()
                elif input_size == 2:
                    widget_idx = self.__parameters_to_widgets_list[i][0]
                    lower_value = (self.__lower_bound_spin_ctrl_list[widget_idx].GetValue(),
                                   self.__lower_bound_spin_ctrl_list[widget_idx + 1].GetValue())
                    upper_value = (self.__upper_bound_spin_ctrl_list[widget_idx].GetValue(),
                                   self.__upper_bound_spin_ctrl_list[widget_idx + 1].GetValue())

                old_value = setting.get_value()
                try:
                    setting.set_value(lower_value)
                    setting.test_valid(self.__pipeline)
                except cellprofiler.setting.ValidationError as instance:
                    message += '\'' + str(setting.get_text()) + \
                               '\': lower bound invalid, ' + \
                               '\n\t' + str(instance.message) + '\n'
                try:
                    setting.set_value(upper_value)
                    setting.test_valid(self.__pipeline)
                except cellprofiler.setting.ValidationError as instance:
                    message += '\'' + str(setting.get_text()) + \
                               '\': upper bound invalid, ' + \
                               '\n\t' + str(instance.message) + '\n'
                setting.set_value(old_value)

        # Second, if there are invalid parameters, tell the user
        if len(message) > 0:
            message = 'Invalid sample settings:\n\n' + message
            dialog = wx.MessageDialog(
                    self, message, caption='Sample settings error',
                    style=wx.ICON_ERROR | wx.OK)
            dialog.ShowModal()
            raise Exception(message)
예제 #3
0
    def test_valid(self, pipeline):
        """Test to see if the module is in a valid state to run

        Throw a ValidationError exception with an explanation if a module is not valid.
        """
        try:
            for setting in self.visible_settings():
                setting.test_valid(pipeline)
            self.validate_module(pipeline)
        except cellprofiler.setting.ValidationError as instance:
            raise instance
        except Exception as e:
            raise cellprofiler.setting.ValidationError(
                "Exception in cpmodule.test_valid %s" % e, self.visible_settings()[0]
            )