Ejemplo n.º 1
0
    def load_settings(cls):
        xml_settings_file_path = get_full_path('res/settings', 'settings.xml')
        xsd_settings_file_path = get_full_path('res/settings', 'settings.xsd')

        AppSettings.settings = {}
        xmlparser = XMLParser()
        AppSettings.xml_root = xmlparser.get_xml_element_tree_root(xsd_settings_file_path, xml_settings_file_path)

        for item in AppSettings.xml_root:
            AppSettings.settings[item.find('name').text] = item.find('value').text
Ejemplo n.º 2
0
    def load_settings(cls):
        xml_settings_file_path = get_full_path('res/settings', 'settings.xml')
        xsd_settings_file_path = get_full_path('res/settings', 'settings.xsd')

        AppSettings.settings = {}
        xmlparser = XMLParser()
        AppSettings.xml_root = xmlparser.get_xml_element_tree_root(
            xsd_settings_file_path, xml_settings_file_path)

        for item in AppSettings.xml_root:
            AppSettings.settings[item.find('name').text] = item.find(
                'value').text
Ejemplo n.º 3
0
    def test_xml_settings_file_invariance(self):
        xml_settings_file_path = get_full_path('res/settings', 'settings.xml')

        settings_file_content_1 = None
        with open(xml_settings_file_path, 'rb') as settings_file:
            settings_file_content_1 = settings_file.read()

        AppSettings.load_settings()
        settings_1 = AppSettings.settings

        AppSettings.save_settings()

        settings_file_content_2 = None
        with open(xml_settings_file_path, 'rb') as settings_file:
            settings_file_content_2 = settings_file.read()

        AppSettings.load_settings()
        settings_2 = AppSettings.settings

        # equality does not work, since dictionaries do not have an invariant order of access,
        # but something weaker might work

        # assert settings_file_content_1 == settings_file_content_2, \
        #     'Loading and saving the settings causes changes in the XML settings file, ' \
        #     'although the settings didn\'t change. These changes might be whitespace character differences.'

        assert len(settings_file_content_1) == len(settings_file_content_2), \
            'The settings file contents differ in length.'

        for character in settings_file_content_1:
            assert character in settings_file_content_2, \
                'There is content in one settings file, which is not in the other.'

        for character in settings_file_content_2:
            assert character in settings_file_content_1, \
                'There is content in one settings file, which is not in the other.'

        characters_1 = {}
        for character in settings_file_content_1:
            if character in characters_1:
                characters_1[character] += 1
            else:
                characters_1[character] = 1

        characters_2 = {}
        for character in settings_file_content_2:
            if character in characters_2:
                characters_2[character] += 1
            else:
                characters_2[character] = 1

        assert characters_1 == characters_2, \
            'The settings files do not contain the same characters.'

        assert settings_1 == settings_2, \
            'Loading and saving the settings causes changes in the settings, ' \
            'although were not intentionally changed.'
Ejemplo n.º 4
0
    def test_xml_settings_file_invariance(self):
        xml_settings_file_path = get_full_path('res/settings', 'settings.xml')

        settings_file_content_1 = None
        with open(xml_settings_file_path, 'rb') as settings_file:
            settings_file_content_1 = settings_file.read()

        AppSettings.load_settings()
        settings_1 = AppSettings.settings

        AppSettings.save_settings()

        settings_file_content_2 = None
        with open(xml_settings_file_path, 'rb') as settings_file:
            settings_file_content_2 = settings_file.read()

        AppSettings.load_settings()
        settings_2 = AppSettings.settings

        # equality does not work, since dictionaries do not have an invariant order of access,
        # but something weaker might work

        # assert settings_file_content_1 == settings_file_content_2, \
        #     'Loading and saving the settings causes changes in the XML settings file, ' \
        #     'although the settings didn\'t change. These changes might be whitespace character differences.'

        assert len(settings_file_content_1) == len(settings_file_content_2), \
            'The settings file contents differ in length.'

        for character in settings_file_content_1:
            assert character in settings_file_content_2, \
                'There is content in one settings file, which is not in the other.'

        for character in settings_file_content_2:
            assert character in settings_file_content_1, \
                'There is content in one settings file, which is not in the other.'

        characters_1 = {}
        for character in settings_file_content_1:
            if character in characters_1:
                characters_1[character] += 1
            else:
                characters_1[character] = 1

        characters_2 = {}
        for character in settings_file_content_2:
            if character in characters_2:
                characters_2[character] += 1
            else:
                characters_2[character] = 1

        assert characters_1 == characters_2, \
            'The settings files do not contain the same characters.'

        assert settings_1 == settings_2, \
            'Loading and saving the settings causes changes in the settings, ' \
            'although were not intentionally changed.'
Ejemplo n.º 5
0
    def load_style_sheet(self):
        if self.style_provider is None:
            self.style_provider = Gtk.CssProvider()

        self.style_provider.load_from_path(
            get_full_path('res/css', 'style.css'))

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(), self.style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
Ejemplo n.º 6
0
    def save_settings(cls):
        # print('trying to save settings:', AppSettings.settings)

        xml_settings_file_path = get_full_path('res/settings', 'settings.xml')
        xsd_settings_file_path = get_full_path('res/settings', 'settings.xsd')

        xml_parser = XMLParser()

        new_xml_root = etree.Element('list')
        for key, value in AppSettings.settings.items():
            setting_node = etree.SubElement(new_xml_root, 'setting')
            name_node = etree.SubElement(setting_node, 'name')
            name_node.text = key
            value_node = etree.SubElement(setting_node, 'value')
            value_node.text = value

        if xml_parser.validate_tree(xsd_settings_file_path, new_xml_root):
            xml_parser.write_xml_file(xml_settings_file_path, new_xml_root)
        else:
            raise XMLInvalidException('The XML is not valid.')
Ejemplo n.º 7
0
    def save_settings(cls):
        # print('trying to save settings:', AppSettings.settings)

        xml_settings_file_path = get_full_path('res/settings', 'settings.xml')
        xsd_settings_file_path = get_full_path('res/settings', 'settings.xsd')

        xml_parser = XMLParser()

        new_xml_root = etree.Element('list')
        for key, value in AppSettings.settings.items():
            setting_node = etree.SubElement(new_xml_root, 'setting')
            name_node = etree.SubElement(setting_node, 'name')
            name_node.text = key
            value_node = etree.SubElement(setting_node, 'value')
            value_node.text = value

        if xml_parser.validate_tree(xsd_settings_file_path, new_xml_root):
            xml_parser.write_xml_file(xml_settings_file_path, new_xml_root)
        else:
            raise XMLInvalidException('The XML is not valid.')
Ejemplo n.º 8
0
    def load_style_sheet(self):
        if self.style_provider is None:
            self.style_provider = Gtk.CssProvider()

        self.style_provider.load_from_path(get_full_path('res/css', 'style.css'))

        Gtk.StyleContext.add_provider_for_screen(
            Gdk.Screen.get_default(),
            self.style_provider,
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
        )
Ejemplo n.º 9
0
 def test_xml_file_validity(self):
     assert XMLParser.validate_file(
         xsd_file_path=get_full_path('res/settings', 'settings.xsd'),
         xml_file_path=get_full_path('res/settings', 'settings.xml'),
     ), 'Your XML settings file is not valid against the provided XSD file.'