Example #1
0
    def show_options(self):
        """Show the options dialog."""
        # import here only so that it is AFTER i18n set up
        from safe.gui.tools.options_dialog import OptionsDialog

        dialog = OptionsDialog(self.iface, self.dock_widget, self.iface.mainWindow())
        dialog.exec_()  # modal
Example #2
0
    def show_welcome_message(self):
        """Show the welcome message."""
        # import here only so that it is AFTER i18n set up
        from safe.gui.tools.options_dialog import OptionsDialog

        # Do not show by default
        show_message = False

        previous_version = StrictVersion(setting('previous_version'))
        current_version = StrictVersion(inasafe_version)

        # Set previous_version to the current inasafe_version
        set_setting('previous_version', inasafe_version)

        if setting('always_show_welcome_message', expected_type=bool):
            # Show if it the setting said so
            show_message = True
        elif previous_version < current_version:
            # Always show if the user installed new version
            show_message = True

        # Allow to disable welcome message when running automated tests
        if os.environ.get('INASAFE_DISABLE_WELCOME_MESSAGE', False):
            show_message = False

        if show_message:
            dialog = OptionsDialog(iface=self.iface,
                                   parent=self.iface.mainWindow())
            dialog.show_welcome_dialog()
            if dialog.exec_():  # modal
                self.dock_widget.read_settings()
Example #3
0
    def show_options(self):
        """Show the options dialog."""
        # import here only so that it is AFTER i18n set up
        from safe.gui.tools.options_dialog import OptionsDialog

        dialog = OptionsDialog(self.iface, self.dock_widget,
                               self.iface.mainWindow())
        dialog.exec_()  # modal
Example #4
0
    def show_options(self):
        """Show the options dialog."""
        # import here only so that it is AFTER i18n set up
        from safe.gui.tools.options_dialog import OptionsDialog

        dialog = OptionsDialog(iface=self.iface,
                               parent=self.iface.mainWindow())
        if dialog.exec_():  # modal
            self.dock_widget.read_settings()
Example #5
0
    def show_options(self):
        """Show the options dialog."""
        # import here only so that it is AFTER i18n set up
        from safe.gui.tools.options_dialog import OptionsDialog

        dialog = OptionsDialog(
            iface=self.iface,
            parent=self.iface.mainWindow())
        if dialog.exec_():  # modal
            self.dock_widget.read_settings()
Example #6
0
    def show_options(self):
        """Show the options dialog."""
        # import here only so that it is AFTER i18n set up
        from safe.gui.tools.options_dialog import OptionsDialog

        dialog = OptionsDialog(iface=self.iface,
                               parent=self.iface.mainWindow())
        dialog.show_option_dialog()
        if dialog.exec_():  # modal
            self.dock_widget.read_settings()
            from safe.gui.widgets.message import getting_started_message
            send_static_message(self.dock_widget, getting_started_message())
            # Issue #4734, make sure to update the combobox after update the
            # InaSAFE option
            self.dock_widget.get_layers()
    def test_setup_dialog(self):
        """Test Setup Options Dialog."""
        dialog = OptionsDialog(
            parent=PARENT, iface=IFACE, qsetting='InaSAFETest')
        self.assertIsNotNone(dialog)

        # Check default values
        self.assertEqual(
            dialog.cbxVisibleLayersOnly.isChecked(),
            inasafe_default_settings['visibleLayersOnlyFlag'])
        self.assertEqual(
            dialog.cbxSetLayerNameFromTitle.isChecked(),
            inasafe_default_settings['set_layer_from_title_flag'])
        self.assertEqual(
            dialog.cbxZoomToImpact.isChecked(),
            inasafe_default_settings['setZoomToImpactFlag'])
        self.assertEqual(
            dialog.cbxHideExposure.isChecked(),
            inasafe_default_settings['setHideExposureFlag'])
        self.assertEqual(
            dialog.cbxUseSelectedFeaturesOnly.isChecked(),
            inasafe_default_settings['useSelectedFeaturesOnly'])
        self.assertEqual(
            dialog.leKeywordCachePath.text(),
            inasafe_default_settings['keywordCachePath'])
        self.assertEqual(
            dialog.template_warning_checkbox.isChecked(),
            inasafe_default_settings['template_warning_verbose'])
        self.assertEqual(
            dialog.organisation_on_dock_checkbox.isChecked(),
            inasafe_default_settings['showOrganisationLogoInDockFlag'])
        self.assertEqual(
            dialog.cbxDevMode.isChecked(),
            inasafe_default_settings['developer_mode'])

        self.assertEqual(
            dialog.leNorthArrowPath.text(), default_north_arrow_path())
        self.assertEqual(
            dialog.leOrganisationLogoPath.text(), supporters_logo_path())
        self.assertEqual(dialog.leReportTemplatePath.text(), '')
        self.assertEqual(dialog.txtDisclaimer.toPlainText(), disclaimer())
        self.assertEqual(
            dialog.leUserDirectoryPath.text(), temp_dir('impacts'))

        self.assertEqual(
            dialog.iso19115_organization_le.text(),
            inasafe_default_settings['ISO19115_ORGANIZATION'])
        self.assertEqual(
            dialog.iso19115_url_le.text(),
            inasafe_default_settings['ISO19115_URL'])
        self.assertEqual(
            dialog.iso19115_email_le.text(),
            inasafe_default_settings['ISO19115_EMAIL'])
        self.assertEqual(
            dialog.iso19115_title_le.text(),
            inasafe_default_settings['ISO19115_TITLE'])
        self.assertEqual(
            dialog.iso19115_license_le.text(),
            inasafe_default_settings['ISO19115_LICENSE'])
    def test_mode(self):
        """Test for checking that the state is correct for the mode.

        If your test is failed, perhaps one the following is the cause:
        1. You add / remove tab in the options.
        2. You rename the tab's name.
        3. The function show_welcome_dialog or show_option_dialog is changed
        """
        # Welcome mode
        dialog = OptionsDialog(parent=PARENT, iface=IFACE)
        dialog.show_welcome_dialog()

        expected_tabs = [
            dialog.welcome_tab, dialog.organisation_profile_tab,
            dialog.preference_tab
        ]

        message = 'Tab count should be %d in welcome dialog.' % len(
            expected_tabs)
        self.assertEqual(dialog.tabWidget.count(), len(expected_tabs), message)

        message = 'Current tab index should be 0.'
        self.assertEqual(dialog.tabWidget.currentIndex(), 0, message)

        for index, expected_tab in enumerate(expected_tabs):
            dialog.tabWidget.setCurrentIndex(index)
            message = 'Current tab should be %s.' % expected_tab.objectName()
            current_tab = dialog.tabWidget.currentWidget()
            self.assertEqual(current_tab, expected_tab, message)

        # Usual option mode
        dialog = OptionsDialog(parent=PARENT, iface=IFACE)
        dialog.show_option_dialog()

        expected_tabs = [
            dialog.organisation_profile_tab, dialog.preference_tab,
            dialog.gis_environment_tab, dialog.earthquake_tab,
            dialog.template_option_tab, dialog.demographic_defaults_tab,
            dialog.advanced_tab
        ]

        message = 'Tab count should be %d in welcome dialog.' % len(
            expected_tabs)
        self.assertEqual(dialog.tabWidget.count(), len(expected_tabs), message)

        message = 'Current tab index should be 0.'
        self.assertEqual(dialog.tabWidget.currentIndex(), 0, message)

        for index, expected_tab in enumerate(expected_tabs):
            dialog.tabWidget.setCurrentIndex(index)
            message = 'Current tab should be %s.' % expected_tab.objectName()
            current_tab = dialog.tabWidget.currentWidget()
            self.assertEqual(current_tab, expected_tab, message)
    def test_update_settings(self):
        """Test update InaSAFE Option works."""
        # Create new option dialog
        dialog = OptionsDialog(
            parent=PARENT, iface=IFACE, qsetting='InaSAFETest')

        # Update some state
        new_state = not inasafe_default_settings['visibleLayersOnlyFlag']
        dialog.cbxVisibleLayersOnly.setChecked(new_state)

        new_organization = 'Super Organization'
        dialog.iso19115_organization_le.setText(new_organization)

        # Accept the dialog
        dialog.accept()

        # Check the value in QSettings
        # Next two lines a hack because windows qsettings returns a string
        # rather than a bool...TS
        value = self.qsetting.value('inasafe/visibleLayersOnlyFlag')
        if value == u'false':
            value = False
        if value == u'true':
            value = True
        self.assertEquals(
            new_state, value)
        self.assertEqual(
            new_organization,
            self.qsetting.value('inasafe/ISO19115_ORGANIZATION'))

        # Open the options dialog
        dialog = OptionsDialog(
            iface=IFACE, parent=PARENT, qsetting='InaSAFETest')

        # Check the state of the dialog after save the settings
        self.assertEqual(new_state, dialog.cbxVisibleLayersOnly.isChecked())
        self.assertEqual(
            new_organization, dialog.iso19115_organization_le.text())
Example #10
0
    def test_mode(self):
        """Test for checking that the state is correct for the mode.

        If your test is failed, perhaps one the following is the cause:
        1. You add / remove tab in the options.
        2. You rename the tab's name.
        3. The function show_welcome_dialog or show_option_dialog is changed
        """
        # Welcome mode
        dialog = OptionsDialog(parent=PARENT, iface=IFACE)
        dialog.show_welcome_dialog()

        expected_tabs = [
            dialog.welcome_tab,
            dialog.organisation_profile_tab,
            dialog.preference_tab
        ]

        message = 'Tab count should be %d in welcome dialog.' % len(
            expected_tabs)
        self.assertEqual(dialog.tabWidget.count(), len(expected_tabs), message)

        message = 'Current tab index should be 0.'
        self.assertEqual(dialog.tabWidget.currentIndex(), 0, message)

        for index, expected_tab in enumerate(expected_tabs):
            dialog.tabWidget.setCurrentIndex(index)
            message = 'Current tab should be %s.' % expected_tab.objectName()
            current_tab = dialog.tabWidget.currentWidget()
            self.assertEqual(current_tab, expected_tab, message)

        # Usual option mode
        dialog = OptionsDialog(parent=PARENT, iface=IFACE)
        dialog.show_option_dialog()

        expected_tabs = [
            dialog.organisation_profile_tab,
            dialog.preference_tab,
            dialog.gis_environment_tab,
            dialog.earthquake_tab,
            dialog.template_option_tab,
            dialog.demographic_defaults_tab,
            dialog.advanced_tab
        ]

        message = 'Tab count should be %d in welcome dialog.' % len(
            expected_tabs)
        self.assertEqual(dialog.tabWidget.count(), len(expected_tabs), message)

        message = 'Current tab index should be 0.'
        self.assertEqual(dialog.tabWidget.currentIndex(), 0, message)

        for index, expected_tab in enumerate(expected_tabs):
            dialog.tabWidget.setCurrentIndex(index)
            message = 'Current tab should be %s.' % expected_tab.objectName()
            current_tab = dialog.tabWidget.currentWidget()
            self.assertEqual(current_tab, expected_tab, message)
Example #11
0
    def test_update_settings(self):
        """Test update InaSAFE Option works."""
        # Create new option dialog
        dialog = OptionsDialog(parent=PARENT,
                               iface=IFACE,
                               qsetting='InaSAFETest')

        # Update some state
        new_state = not inasafe_default_settings['visibleLayersOnlyFlag']
        dialog.cbxVisibleLayersOnly.setChecked(new_state)

        new_organization = 'Super Organization'
        dialog.iso19115_organization_le.setText(new_organization)

        # Accept the dialog
        dialog.accept()

        # Check the value in QSettings
        # Next two lines a hack because windows qsettings returns a string
        # rather than a bool...TS
        value = self.qsetting.value('inasafe/visibleLayersOnlyFlag')
        if value == u'false':
            value = False
        if value == u'true':
            value = True
        self.assertEquals(new_state, value)
        self.assertEqual(new_organization,
                         self.qsetting.value('inasafe/ISO19115_ORGANIZATION'))

        # Open the options dialog
        dialog = OptionsDialog(iface=IFACE,
                               parent=PARENT,
                               qsetting='InaSAFETest')

        # Check the state of the dialog after save the settings
        self.assertEqual(new_state, dialog.cbxVisibleLayersOnly.isChecked())
        self.assertEqual(new_organization,
                         dialog.iso19115_organization_le.text())