Beispiel #1
0
    def test_expand_json(self):
        """
        Test the expand_json method
        """
        # GIVEN: A ThemeXML object and some JSON to "expand"
        theme = ThemeXML()
        theme_json = {
            'background': {
                'border_color': '#000000',
                'type': 'solid'
            },
            'display': {
                'vertical_align': 0
            },
            'font': {
                'footer': {
                    'bold': False
                },
                'main': {
                    'name': 'Arial'
                }
            }
        }

        # WHEN: ThemeXML.expand_json() is run
        theme.expand_json(theme_json)

        # THEN: The attributes should be set on the object
        self.assertEqual('#000000', theme.background_border_color, 'background_border_color should be "#000000"')
        self.assertEqual('solid', theme.background_type, 'background_type should be "solid"')
        self.assertEqual(0, theme.display_vertical_align, 'display_vertical_align should be 0')
        self.assertFalse(theme.font_footer_bold, 'font_footer_bold should be False')
        self.assertEqual('Arial', theme.font_main_name, 'font_main_name should be "Arial"')
Beispiel #2
0
 def on_add_theme(self, field=None):
     """
     Loads a new theme with the default settings and then launches the theme editing form for the user to make
     their customisations.
     :param field:
     """
     theme = ThemeXML()
     theme.set_default_header_footer()
     self.theme_form.theme = theme
     self.theme_form.exec()
     self.load_themes()
Beispiel #3
0
 def on_add_theme(self, field=None):
     """
     Loads a new theme with the default settings and then launches the theme editing form for the user to make
     their customisations.
     :param field:
     """
     theme = ThemeXML()
     theme.set_default_header_footer()
     self.theme_form.theme = theme
     self.theme_form.exec()
     self.load_themes()
Beispiel #4
0
    def _create_theme_from_xml(self, theme_xml, image_path):
        """
        Return a theme object using information parsed from XML

        :param theme_xml: The Theme data object.
        :param image_path: Where the theme image is stored
        :return: Theme data.
        """
        theme = ThemeXML()
        theme.parse(theme_xml)
        theme.extend_image_filename(image_path)
        return theme
Beispiel #5
0
 def load_first_time_themes(self):
     """
     Imports any themes on start up and makes sure there is at least one theme
     """
     self.application.set_busy_cursor()
     files = AppLocation.get_files(self.settings_section, '.otz')
     for theme_file in files:
         theme_file = os.path.join(self.path, theme_file)
         self.unzip_theme(theme_file, self.path)
         delete_file(theme_file)
     files = AppLocation.get_files(self.settings_section, '.png')
     # No themes have been found so create one
     if not files:
         theme = ThemeXML()
         theme.theme_name = UiStrings().Default
         self._write_theme(theme, None, None)
         Settings().setValue(self.settings_section + '/global theme', theme.theme_name)
     self.application.set_normal_cursor()
Beispiel #6
0
 def load_first_time_themes(self):
     """
     Imports any themes on start up and makes sure there is at least one theme
     """
     self.application.set_busy_cursor()
     files = AppLocation.get_files(self.settings_section, '.otz')
     for theme_file in files:
         theme_file = os.path.join(self.path, theme_file)
         self.unzip_theme(theme_file, self.path)
         delete_file(theme_file)
     files = AppLocation.get_files(self.settings_section, '.png')
     # No themes have been found so create one
     if not files:
         theme = ThemeXML()
         theme.theme_name = UiStrings().Default
         self._write_theme(theme, None, None)
         Settings().setValue(self.settings_section + '/global theme',
                             theme.theme_name)
     self.application.set_normal_cursor()
Beispiel #7
0
    def test_set_text_rectangle(self, mock_outline_css, mock_lyrics_css, mock_webview):
        """
        Test set_text_rectangle returns a proper html string
        """
        # GIVEN: test object and data
        mock_lyrics_css.return_value = ' FORMAT CSS; '
        mock_outline_css.return_value = ' OUTLINE CSS; '
        theme_data = ThemeXML()
        theme_data.font_main_name = 'Arial'
        theme_data.font_main_size = 20
        theme_data.font_main_color = '#FFFFFF'
        theme_data.font_main_outline_color = '#FFFFFF'
        main = QtCore.QRect(10, 10, 1280, 900)
        foot = QtCore.QRect(10, 1000, 1260, 24)
        renderer = Renderer()

        # WHEN: Calling method
        renderer._set_text_rectangle(theme_data=theme_data, rect_main=main, rect_footer=foot)

        # THEN: QtWebKitWidgets should be called with the proper string
        mock_webview.setHtml.called_with(CSS_TEST_ONE, 'Should be the same')
Beispiel #8
0
    def test_expand_json(self):
        """
        Test the expand_json method
        """
        # GIVEN: A ThemeXML object and some JSON to "expand"
        theme = ThemeXML()
        theme_json = {
            'background': {
                'border_color': '#000000',
                'type': 'solid'
            },
            'display': {
                'vertical_align': 0
            },
            'font': {
                'footer': {
                    'bold': False
                },
                'main': {
                    'name': 'Arial'
                }
            }
        }

        # WHEN: ThemeXML.expand_json() is run
        theme.expand_json(theme_json)

        # THEN: The attributes should be set on the object
        self.assertEqual('#000000', theme.background_border_color,
                         'background_border_color should be "#000000"')
        self.assertEqual('solid', theme.background_type,
                         'background_type should be "solid"')
        self.assertEqual(0, theme.display_vertical_align,
                         'display_vertical_align should be 0')
        self.assertFalse(theme.font_footer_bold,
                         'font_footer_bold should be False')
        self.assertEqual('Arial', theme.font_main_name,
                         'font_main_name should be "Arial"')
Beispiel #9
0
    def get_theme_data(self, theme_name):
        """
        Returns a theme object from an XML file

        :param theme_name: Name of the theme to load from file
        :return: The theme object.
        """
        self.log_debug('get theme data for theme %s' % theme_name)
        xml_file = os.path.join(self.path, str(theme_name),
                                str(theme_name) + '.xml')
        xml = get_text_file_string(xml_file)
        if not xml:
            self.log_debug('No theme data - using default theme')
            return ThemeXML()
        else:
            return self._create_theme_from_xml(xml, self.path)
Beispiel #10
0
    def _create_theme_from_xml(self, theme_xml, image_path):
        """
        Return a theme object using information parsed from XML

        :param theme_xml: The Theme data object.
        :param image_path: Where the theme image is stored
        :return: Theme data.
        """
        theme = ThemeXML()
        theme.parse(theme_xml)
        theme.extend_image_filename(image_path)
        return theme
Beispiel #11
0
    def test_extend_image_filename(self):
        """
        Test the extend_image_filename method
        """
        # GIVEN: A theme object
        theme = ThemeXML()
        theme.theme_name = 'MyBeautifulTheme   '
        theme.background_filename = '    video.mp4'
        theme.background_type = 'video'
        path = os.path.expanduser('~')

        # WHEN: ThemeXML.extend_image_filename is run
        theme.extend_image_filename(path)

        # THEN: The filename of the background should be correct
        expected_filename = os.path.join(path, 'MyBeautifulTheme', 'video.mp4')
        self.assertEqual(expected_filename, theme.background_filename)
        self.assertEqual('MyBeautifulTheme', theme.theme_name)
Beispiel #12
0
    def test_new_theme(self):
        """
        Test the ThemeXML constructor
        """
        # GIVEN: The ThemeXML class
        # WHEN: A theme object is created
        default_theme = ThemeXML()

        # THEN: The default values should be correct
        self.assertEqual('#000000', default_theme.background_border_color,
                         'background_border_color should be "#000000"')
        self.assertEqual('solid', default_theme.background_type,
                         'background_type should be "solid"')
        self.assertEqual(0, default_theme.display_vertical_align,
                         'display_vertical_align should be 0')
        self.assertEqual('Arial', default_theme.font_footer_name,
                         'font_footer_name should be "Arial"')
        self.assertFalse(default_theme.font_main_bold,
                         'font_main_bold should be False')
        self.assertEqual(47, len(default_theme.__dict__),
                         'The theme should have 47 attributes')
Beispiel #13
0
    def test_extend_image_filename(self):
        """
        Test the extend_image_filename method
        """
        # GIVEN: A theme object
        theme = ThemeXML()
        theme.theme_name = 'MyBeautifulTheme   '
        theme.background_filename = '    video.mp4'
        theme.background_type = 'video'
        path = os.path.expanduser('~')

        # WHEN: ThemeXML.extend_image_filename is run
        theme.extend_image_filename(path)

        # THEN: The filename of the background should be correct
        expected_filename = os.path.join(path, 'MyBeautifulTheme', 'video.mp4')
        self.assertEqual(expected_filename, theme.background_filename)
        self.assertEqual('MyBeautifulTheme', theme.theme_name)
Beispiel #14
0
    def test_set_text_rectangle(self, mock_outline_css, mock_lyrics_css,
                                mock_webview):
        """
        Test set_text_rectangle returns a proper html string
        """
        # GIVEN: test object and data
        mock_lyrics_css.return_value = ' FORMAT CSS; '
        mock_outline_css.return_value = ' OUTLINE CSS; '
        theme_data = ThemeXML()
        theme_data.font_main_name = 'Arial'
        theme_data.font_main_size = 20
        theme_data.font_main_color = '#FFFFFF'
        theme_data.font_main_outline_color = '#FFFFFF'
        main = QtCore.QRect(10, 10, 1280, 900)
        foot = QtCore.QRect(10, 1000, 1260, 24)
        renderer = Renderer()

        # WHEN: Calling method
        renderer._set_text_rectangle(theme_data=theme_data,
                                     rect_main=main,
                                     rect_footer=foot)

        # THEN: QtWebKitWidgets should be called with the proper string
        mock_webview.setHtml.called_with(CSS_TEST_ONE, 'Should be the same')