def test_algorithm_categories_state_changes_correctly_when_bottom_level_box_clicked(
            self):
        # create a mock item with one parent
        parent_item = MockQTreeWidgetParentItem()
        child_item = parent_item.child()

        child_item.checkState = Mock(return_value=Qt.Checked)
        mock_view = MockCategoriesView()
        presenter = CategoriesSettings(None, mock_view)
        presenter.nested_box_clicked(child_item, 0)
        child_item.setCheckState.assert_called_once_with(0, Qt.Checked)
        parent_item.setCheckState.assert_called_once_with(0, Qt.Checked)
    def test_set_hidden_interface_string(self, mock_ConfigService):
        mock_view = MockCategoriesView()
        mock_ConfigService.getString = Mock(return_value='')
        presenter = CategoriesSettings(None, mock_view)
        hidden_interface_string = 'Indirect; Muon; Reflectometry'

        # reset any effects from the constructor
        mock_ConfigService.setString.reset_mock()
        presenter._create_hidden_categories_string = Mock(
            return_value=hidden_interface_string)
        presenter.set_hidden_interfaces_string(None)
        mock_ConfigService.setString.assert_called_once_with(
            presenter.HIDDEN_INTERFACES, ';'.join(hidden_interface_string))
    def test_set_hidden_algorithms_string(self, mock_ConfigService):
        mock_view = MockCategoriesView()
        presenter = CategoriesSettings(None, mock_view)
        hidden_algorthim_string = [
            i for i in sorted(algorithm_and_states.keys())
            if algorithm_and_states[i] is True
        ]
        presenter._create_hidden_categories_string = Mock(
            return_value=hidden_algorthim_string)
        # reset any effects from the constructor
        mock_ConfigService.setString.reset_mock()

        presenter.set_hidden_algorithms_string(None)
        mock_ConfigService.setString.assert_called_once_with(
            presenter.HIDDEN_ALGORITHMS, ';'.join(hidden_algorthim_string))
Пример #4
0
    def __init__(self,
                 parent,
                 view=None,
                 general_settings=None,
                 categories_settings=None,
                 plot_settings=None,
                 fitting_settings=None):
        self.view = view if view else SettingsView(parent, self)
        self.general_settings = general_settings if general_settings else GeneralSettings(
            parent)
        self.categories_settings = categories_settings if categories_settings else CategoriesSettings(
            parent)
        self.plot_settings = plot_settings if plot_settings else PlotSettings(
            parent)
        self.fitting_settings = fitting_settings if fitting_settings else FittingSettings(
            parent)
        self.parent = parent

        self.view.sections.addItems(list(self.SETTINGS_TABS.values()))
        self.current = self.general_settings.view
        self.view.container.addWidget(self.general_settings.view)
        self.view.container.addWidget(self.categories_settings.view)
        self.view.container.addWidget(self.plot_settings.view)
        self.view.container.addWidget(self.fitting_settings.view)

        self.view.help_button.clicked.connect(self.action_open_help_window)
        self.ask_before_close = False
    def test_algorithm_categories_partial_states_change_correctly_when_bottom_level_box_clicked(
            self):
        parent_item = MockQTreeWidgetParentItem()
        child_item1 = parent_item.child()
        child_item2 = MockQTreeWidgetChildItem(parent_item)
        parent_item.childCount = Mock(return_value=2)
        parent_item.child.side_effect = [child_item1, child_item2]

        child_item1.checkState = Mock(return_value=Qt.Checked)
        child_item2.checkState = Mock(return_value=Qt.Unchecked)

        mock_view = MockCategoriesView()
        presenter = CategoriesSettings(None, mock_view)
        presenter.nested_box_clicked(child_item1, 0)
        child_item1.setCheckState.assert_called_once_with(0, Qt.Checked)
        parent_item.setCheckState.assert_called_once_with(
            0, Qt.PartiallyChecked)
 def test_algorithm_state_correct_when_created(self):
     mock_view = MockCategoriesView()
     CategoriesSettings(None, mock_view)
     for category, state in algorithm_and_states.items():
         if "\\" in category:
             expected_calls = [
                 call(mock_view.algorithm_tree_widget,
                      category.split("\\")[-1], state, ANY)
             ]
         else:
             expected_calls = [
                 call(mock_view.algorithm_tree_widget,
                      category.split("\\")[-1], state)
             ]
         mock_view.add_checked_widget_item.assert_has_calls(expected_calls)
    def test_interface_state_correct_when_created(self, mock_ConfigService):
        mock_main_window = MockMainWindow()
        mock_view = MockCategoriesView()
        hidden_interfaces = 'Indirect; Muon; Reflectometry'
        mock_ConfigService.getString = Mock(return_value=hidden_interfaces)
        CategoriesSettings(mock_main_window, mock_view)

        expected_calls = []
        for category in mock_main_window.interface_list:
            is_hidden = False
            if category in hidden_interfaces.split(';'):
                is_hidden = True
            expected_calls.append(
                call(mock_view.interface_tree_widget, category, is_hidden))

        mock_view.add_checked_widget_item.assert_has_calls(expected_calls)
Пример #8
0
    def __init__(self,
                 parent,
                 view=None,
                 model=None,
                 general_settings=None,
                 categories_settings=None,
                 plot_settings=None,
                 fitting_settings=None):
        self.view = view if view else SettingsView(parent, self)
        self.model = model if model else SettingsModel()
        self.general_settings = general_settings if general_settings else GeneralSettings(
            parent, None, self)
        self.categories_settings = categories_settings if categories_settings else CategoriesSettings(
            parent)
        self.plot_settings = plot_settings if plot_settings else PlotSettings(
            parent)
        self.fitting_settings = fitting_settings if fitting_settings else FittingSettings(
            parent)
        self.parent = parent
        self.all_properties = []
        for properties in [
                CategoryProperties, FittingProperties, GeneralProperties,
                PlotProperties
        ]:
            self.all_properties += [prop.value for prop in properties]

        self.view.sections.addItems(list(self.SETTINGS_TABS.values()))
        self.current = self.general_settings.view
        self.view.container.addWidget(self.general_settings.view)
        self.view.container.addWidget(self.categories_settings.view)
        self.view.container.addWidget(self.plot_settings.view)
        self.view.container.addWidget(self.fitting_settings.view)

        self.view.save_file_button.clicked.connect(
            self.action_save_settings_to_file)
        self.view.load_file_button.clicked.connect(
            self.action_load_settings_from_file)
        self.view.help_button.clicked.connect(self.action_open_help_window)
        self.ask_before_close = False

        self.changes_that_need_restart = []