Ejemplo n.º 1
0
    def exit_application(self, widget, event):
        strtrue = str(True)

        save_vocables = AppSettings.get_setting_by_name(
            AppSettings.SAVE_VOCABLES_ON_EXIT_SETTING_NAME) == strtrue
        show_dialog = AppSettings.get_setting_by_name(
            AppSettings.DIALOG_SHOW_SAVE_VOCABLES_CONFIRMATION_SETTING_NAME
        ) == strtrue

        if show_dialog and VocableManager.vocables_changed:
            save_vocables_confirmation_dialog = SaveVocablesBeforeExitConfirmationDialog(
                self)
            save_vocables = save_vocables_confirmation_dialog.run(
            ) == Gtk.ResponseType.YES
            AppSettings.change_setting_by_name(
                AppSettings.SAVE_VOCABLES_ON_EXIT_SETTING_NAME, save_vocables)
            save_vocables_confirmation_dialog.destroy()

        if save_vocables:
            VocableManager.save_vocables(VocableManager.vocables)

        exit_on_exit_confirmation = AppSettings.get_setting_by_name(
            AppSettings.EXIT_ON_EXIT_SETTING_NAME) == strtrue
        show_exit_confirmation = AppSettings.get_setting_by_name(
            AppSettings.DIALOG_SHOW_EXIT_CONFIRMATION_SETTING_NAME)

        if show_exit_confirmation == strtrue:
            ExitConfirmationDialog.__init__ = timefunction(
                ExitConfirmationDialog.__init__)  # decoration
            exit_confirmation_dialog = ExitConfirmationDialog(self)
            exit_confirmation_dialog.run = timefunction(
                exit_confirmation_dialog.run)  # decoration
            exit_on_exit_confirmation = exit_confirmation_dialog.run(
            ) == Gtk.ResponseType.YES
            AppSettings.change_setting_by_name(
                AppSettings.EXIT_ON_EXIT_SETTING_NAME,
                exit_on_exit_confirmation)
            exit_confirmation_dialog.destroy()

        if exit_on_exit_confirmation:
            # print("Clicked YES")
            AppSettings.save_settings()
            Gtk.main_quit()
            sys.exit()
        else:
            # print("Clicked NO")
            pass

        return GTKSignal.DO_NOT_PROPAGATE
Ejemplo n.º 2
0
    def exit_application(self, widget, event):
        strtrue = str(True)

        save_vocables = AppSettings.get_setting_by_name(AppSettings.SAVE_VOCABLES_ON_EXIT_SETTING_NAME) == strtrue
        show_dialog = AppSettings.get_setting_by_name(
            AppSettings.DIALOG_SHOW_SAVE_VOCABLES_CONFIRMATION_SETTING_NAME
        ) == strtrue

        if show_dialog and VocableManager.vocables_changed:
            save_vocables_confirmation_dialog = SaveVocablesBeforeExitConfirmationDialog(self)
            save_vocables = save_vocables_confirmation_dialog.run() == Gtk.ResponseType.YES
            AppSettings.change_setting_by_name(AppSettings.SAVE_VOCABLES_ON_EXIT_SETTING_NAME, save_vocables)
            save_vocables_confirmation_dialog.destroy()

        if save_vocables:
            VocableManager.save_vocables(VocableManager.vocables)

        exit_on_exit_confirmation = AppSettings.get_setting_by_name(AppSettings.EXIT_ON_EXIT_SETTING_NAME) == strtrue
        show_exit_confirmation = AppSettings.get_setting_by_name(AppSettings.DIALOG_SHOW_EXIT_CONFIRMATION_SETTING_NAME)

        if show_exit_confirmation == strtrue:
            ExitConfirmationDialog.__init__ = timefunction(ExitConfirmationDialog.__init__)  # decoration
            exit_confirmation_dialog = ExitConfirmationDialog(self)
            exit_confirmation_dialog.run = timefunction(exit_confirmation_dialog.run)  # decoration
            exit_on_exit_confirmation = exit_confirmation_dialog.run() == Gtk.ResponseType.YES
            AppSettings.change_setting_by_name(AppSettings.EXIT_ON_EXIT_SETTING_NAME, exit_on_exit_confirmation)
            exit_confirmation_dialog.destroy()

        if exit_on_exit_confirmation:
            # print("Clicked YES")
            AppSettings.save_settings()
            Gtk.main_quit()
            sys.exit()
        else:
            # print("Clicked NO")
            pass

        return GTKSignal.DO_NOT_PROPAGATE
Ejemplo n.º 3
0
    def test_change_setting_by_name(self):
        """
        To test the method AppSettings.change_setting_by_name, we have to assert the following:
        1.Trying to change a setting, which does not exist should throw a SettingUnknownException.
        2.Trying to change a setting, which does exist, should result in the setting having the changed value.
        """
        # make sure we have a string, which is not a key in the dictionary
        random_word_length = 10
        random_word = RandomStringCreator.randomword(random_word_length)
        while random_word in AppSettings.settings:
            random_word_length += 1
            random_word = RandomStringCreator.randomword(random_word_length)

        # check for 1. (Does the method throw the correct exception?)
        try:
            AppSettings.change_setting_by_name(random_word, 'abc')
            assert False, 'Could change a not existing setting.'
        except SettingUnknownException:
            assert random_word not in AppSettings.settings, \
                'The method AppSettings.change_setting_by_name falsely throws exception SettingUnknownException.'

        # check for 2. (Does the method set the correct value for the setting?)
        if len(AppSettings.settings.keys()) == 0:
            test_setting_name = 'test_setting_name'
            test_setting_value = 'test_setting_value'
            new_value = test_setting_value + '_1'
            AppSettings.add_setting_by_name(test_setting_name,
                                            test_setting_value)
            AppSettings.change_setting_by_name(test_setting_name, new_value)
            assert AppSettings.get_setting_by_name(test_setting_name) == new_value, \
                'The method AppSettings.change_setting_by_name not set the correct value.'
        else:
            existing_dictionary_key = list(AppSettings.settings.keys())[0]
            try:
                old_value = AppSettings.get_setting_by_name(
                    existing_dictionary_key)
                new_value = old_value + '_1'
                AppSettings.change_setting_by_name(existing_dictionary_key,
                                                   new_value)
                assert AppSettings.get_setting_by_name(existing_dictionary_key) == new_value, \
                    'The method AppSettings.change_setting_by_name does change to the correct value.'
            except SettingUnknownException:
                assert False, 'AppSettings.change_setting_by_name a SettingUnknownException, ' \
                              'although the accessed key existed in the settings dictionary.'
Ejemplo n.º 4
0
    def test_change_setting_by_name(self):
        """
        To test the method AppSettings.change_setting_by_name, we have to assert the following:
        1.Trying to change a setting, which does not exist should throw a SettingUnknownException.
        2.Trying to change a setting, which does exist, should result in the setting having the changed value.
        """
        # make sure we have a string, which is not a key in the dictionary
        random_word_length = 10
        random_word = RandomStringCreator.randomword(random_word_length)
        while random_word in AppSettings.settings:
            random_word_length += 1
            random_word = RandomStringCreator.randomword(random_word_length)

        # check for 1. (Does the method throw the correct exception?)
        try:
            AppSettings.change_setting_by_name(random_word, 'abc')
            assert False, 'Could change a not existing setting.'
        except SettingUnknownException:
            assert random_word not in AppSettings.settings, \
                'The method AppSettings.change_setting_by_name falsely throws exception SettingUnknownException.'

        # check for 2. (Does the method set the correct value for the setting?)
        if len(AppSettings.settings.keys()) == 0:
            test_setting_name = 'test_setting_name'
            test_setting_value = 'test_setting_value'
            new_value = test_setting_value + '_1'
            AppSettings.add_setting_by_name(test_setting_name, test_setting_value)
            AppSettings.change_setting_by_name(test_setting_name, new_value)
            assert AppSettings.get_setting_by_name(test_setting_name) == new_value, \
                'The method AppSettings.change_setting_by_name not set the correct value.'
        else:
            existing_dictionary_key = list(AppSettings.settings.keys())[0]
            try:
                old_value = AppSettings.get_setting_by_name(existing_dictionary_key)
                new_value = old_value + '_1'
                AppSettings.change_setting_by_name(existing_dictionary_key, new_value)
                assert AppSettings.get_setting_by_name(existing_dictionary_key) == new_value, \
                    'The method AppSettings.change_setting_by_name does change to the correct value.'
            except SettingUnknownException:
                assert False, 'AppSettings.change_setting_by_name a SettingUnknownException, ' \
                              'although the accessed key existed in the settings dictionary.'
 def save_settings(self, widget):
     AppSettings.change_setting_by_name(
         AppSettings.DIALOG_SHOW_SAVE_VOCABLES_CONFIRMATION_SETTING_NAME,
         not self.remember_decision_checkbutton.get_active()
     )