Example #1
0
 def on_replace_click(self):
     """
     Called to replace Live background with the media selected.
     """
     if check_item_selected(self.list_view,
                            translate('MediaPlugin.MediaItem',
                                      'You must select a media file to replace the background with.')):
         item = self.list_view.currentItem()
         filename = item.data(QtCore.Qt.UserRole)
         if os.path.exists(filename):
             service_item = ServiceItem()
             service_item.title = 'webkit'
             service_item.processor = 'webkit'
             (path, name) = os.path.split(filename)
             service_item.add_from_command(path, name, CLAPPERBOARD)
             if self.media_controller.video(DisplayControllerType.Live, service_item, video_behind_text=True):
                 self.reset_action.setVisible(True)
             else:
                 critical_error_message_box(UiStrings().LiveBGError,
                                            translate('MediaPlugin.MediaItem',
                                                      'There was no display item to amend.'))
         else:
             critical_error_message_box(UiStrings().LiveBGError,
                                        translate('MediaPlugin.MediaItem',
                                                  'There was a problem replacing your background, '
                                                  'the media file "%s" no longer exists.') % filename)
Example #2
0
    def test_add_from_command_for_a_presentation(self):
        """
        Test the Service Item - adding a presentation
        """
        # GIVEN: A service item, a mocked icon and presentation data
        service_item = ServiceItem(None)
        presentation_name = 'test.pptx'
        image = MagicMock()
        display_title = 'DisplayTitle'
        notes = 'Note1\nNote2\n'
        frame = {
            'title': presentation_name,
            'image': image,
            'path': TEST_PATH,
            'display_title': display_title,
            'notes': notes
        }

        # WHEN: adding presentation to service_item
        service_item.add_from_command(TEST_PATH, presentation_name, image,
                                      display_title, notes)

        # THEN: verify that it is setup as a Command and that the frame data matches
        assert service_item.service_item_type == ServiceItemType.Command, 'It should be a Command'
        assert service_item.get_frames()[0] == frame, 'Frames should match'
Example #3
0
    def add_from_command_for_a_presentation_thumb_test(self, mocked_get_section_data_path):
        """
        Test the Service Item - adding a presentation, and updating the thumb path
        """
        # GIVEN: A service item, a mocked AppLocation and presentation data
        mocked_get_section_data_path.return_value = os.path.join('mocked', 'section', 'path')
        service_item = ServiceItem(None)
        service_item.has_original_files = False
        service_item.name = 'presentations'
        presentation_name = 'test.pptx'
        thumb = os.path.join('tmp', 'test', 'thumb.png')
        display_title = 'DisplayTitle'
        notes = 'Note1\nNote2\n'
        expected_thumb_path = os.path.join('mocked', 'section', 'path', 'thumbnails',
                                           md5_hash(os.path.join(TEST_PATH, presentation_name).encode('utf-8')),
                                           'thumb.png')
        frame = {'title': presentation_name, 'image': expected_thumb_path, 'path': TEST_PATH,
                 'display_title': display_title, 'notes': notes}

        # WHEN: adding presentation to service_item
        service_item.add_from_command(TEST_PATH, presentation_name, thumb, display_title, notes)

        # THEN: verify that it is setup as a Command and that the frame data matches
        self.assertEqual(service_item.service_item_type, ServiceItemType.Command, 'It should be a Command')
        self.assertEqual(service_item.get_frames()[0], frame, 'Frames should match')
Example #4
0
 def on_replace_click(self):
     """
     Called to replace Live background with the media selected.
     """
     if check_item_selected(
             self.list_view,
             translate(
                 'MediaPlugin.MediaItem',
                 'You must select a media file to replace the background with.'
             )):
         item = self.list_view.currentItem()
         filename = item.data(QtCore.Qt.UserRole)
         if os.path.exists(filename):
             service_item = ServiceItem()
             service_item.title = 'webkit'
             service_item.processor = 'webkit'
             (path, name) = os.path.split(filename)
             service_item.add_from_command(path, name, CLAPPERBOARD)
             if self.media_controller.video(DisplayControllerType.Live,
                                            service_item,
                                            video_behind_text=True):
                 self.reset_action.setVisible(True)
             else:
                 critical_error_message_box(
                     UiStrings().LiveBGError,
                     translate('MediaPlugin.MediaItem',
                               'There was no display item to amend.'))
         else:
             critical_error_message_box(
                 UiStrings().LiveBGError,
                 translate(
                     'MediaPlugin.MediaItem',
                     'There was a problem replacing your background, '
                     'the media file "%s" no longer exists.') % filename)
Example #5
0
    def build_html(self, service_item, image_path=''):
        """
        Store the service_item and build the new HTML from it. Add the HTML to the display

        :param service_item: The Service item to be used
        :param image_path: Where the image resides.
        """
        self.web_loaded = False
        self.initial_fame = None
        self.service_item = service_item
        background = None
        # We have an image override so keep the image till the theme changes.
        if self.override:
            # We have an video override so allow it to be stopped.
            if 'video' in self.override:
                Registry().execute('video_background_replaced')
                self.override = {}
            # We have a different theme.
            elif self.override['theme'] != service_item.theme_data.background_filename:
                Registry().execute('live_theme_changed')
                self.override = {}
            else:
                # replace the background
                background = self.image_manager.get_image_bytes(self.override['image'], ImageSource.ImagePlugin)
        self.set_transparency(self.service_item.theme_data.background_type ==
                              BackgroundType.to_string(BackgroundType.Transparent))
        image_bytes = None
        if self.service_item.theme_data.background_type == 'image':
            if self.service_item.theme_data.background_filename:
                self.service_item.bg_image_bytes = self.image_manager.get_image_bytes(
                    self.service_item.theme_data.background_filename, ImageSource.Theme)
            if image_path:
                image_bytes = self.image_manager.get_image_bytes(image_path, ImageSource.ImagePlugin)
        created_html = build_html(self.service_item, self.screen, self.is_live, background, image_bytes,
                                  plugins=self.plugin_manager.plugins)
        self.web_view.setHtml(created_html)
        if service_item.foot_text:
            self.footer(service_item.foot_text)
        # if was hidden keep it hidden
        if self.hide_mode and self.is_live and not service_item.is_media():
            if Settings().value('core/auto unblank'):
                Registry().execute('slidecontroller_live_unblank')
            else:
                self.hide_display(self.hide_mode)
        if self.service_item.theme_data.background_type == 'video' and self.is_live:
            if self.service_item.theme_data.background_filename:
                service_item = ServiceItem()
                service_item.title = 'webkit'
                service_item.processor = 'webkit'
                path = os.path.join(AppLocation.get_section_data_path('themes'),
                                    self.service_item.theme_data.theme_name)
                service_item.add_from_command(path,
                                              self.service_item.theme_data.background_filename,
                                              ':/media/slidecontroller_multimedia.png')
                self.media_controller.video(DisplayControllerType.Live, service_item, video_behind_text=True)
        self._hide_mouse()
Example #6
0
    def add_from_comamnd_without_display_title_and_notes_test(self):
        """
        Test the Service Item - add from command, but not presentation
        """
        # GIVEN: A new service item, a mocked icon and image data
        service_item = ServiceItem(None)
        image_name = 'test.img'
        image = MagicMock()
        frame = {'title': image_name, 'image': image, 'path': TEST_PATH,
                 'display_title': None, 'notes': None}

        # WHEN: adding image to service_item
        service_item.add_from_command(TEST_PATH, image_name, image)

        # THEN: verify that it is setup as a Command and that the frame data matches
        self.assertEqual(service_item.service_item_type, ServiceItemType.Command, 'It should be a Command')
        self.assertEqual(service_item.get_frames()[0], frame, 'Frames should match')
Example #7
0
    def add_from_command_for_a_presentation_test(self):
        """
        Test the Service Item - adding a presentation
        """
        # GIVEN: A service item, a mocked icon and presentation data
        service_item = ServiceItem(None)
        presentation_name = 'test.pptx'
        image = MagicMock()
        display_title = 'DisplayTitle'
        notes = 'Note1\nNote2\n'
        frame = {'title': presentation_name, 'image': image, 'path': TEST_PATH,
                 'display_title': display_title, 'notes': notes}

        # WHEN: adding presentation to service_item
        service_item.add_from_command(TEST_PATH, presentation_name, image, display_title, notes)

        # THEN: verify that it is setup as a Command and that the frame data matches
        self.assertEqual(service_item.service_item_type, ServiceItemType.Command, 'It should be a Command')
        self.assertEqual(service_item.get_frames()[0], frame, 'Frames should match')
    def serviceitem_add_command_test(self):
        """
        Test the Service Item - add command test
        """
        # GIVEN: A new service item and a mocked renderer
        service_item = ServiceItem(None)
        service_item.name = u'test'

        # WHEN: adding image to a service item
        test_file = os.path.join(TESTPATH, u'church.jpg')
        service_item.add_from_command(TESTPATH, u'church.jpg', test_file)

        # THEN: We should get back a valid service item
        assert service_item.is_valid is True, u'The new service item should be valid'
        assert len(service_item._display_frames) == 0, u'The service item has no display frames '

        # THEN: We should have a page of output.
        assert len(service_item._raw_frames) == 1, u'A valid rendered Service Item has one raw frame'
        assert service_item.get_rendered_frame(0) == test_file, u'The image matches the input'

        # WHEN requesting a saved service item
        service = service_item.get_service_repr(True)

        # THEN: We should have two parts of the service.
        assert len(service) == 2, u'A saved service has two parts'
        assert service[u'header'][u'name']  == u'test' , u'A test plugin'
        assert service[u'data'][0][u'title'] == u'church.jpg' , u'The first title name '
        assert service[u'data'][0][u'path'] == TESTPATH , u'The first image name'
        assert service[u'data'][0][u'image'] == test_file , u'The first image name'

        # WHEN validating a service item
        service_item.validate_item([u'jpg'])

        # THEN the service item should be valid
        assert service_item.is_valid is True, u'The service item should be valid'

        # WHEN validating a service item with a different suffix
        service_item.validate_item([u'png'])

        # THEN the service item should not be valid
        assert service_item.is_valid is False, u'The service item is not valid'
Example #9
0
    def build_html(self, service_item, image_path=''):
        """
        Store the service_item and build the new HTML from it. Add the HTML to the display

        :param service_item: The Service item to be used
        :param image_path: Where the image resides.
        """
        self.web_loaded = False
        self.initial_fame = None
        self.service_item = service_item
        background = None
        # We have an image override so keep the image till the theme changes.
        if self.override:
            # We have an video override so allow it to be stopped.
            if 'video' in self.override:
                Registry().execute('video_background_replaced')
                self.override = {}
            # We have a different theme.
            elif self.override['theme'] != path_to_str(
                    service_item.theme_data.background_filename):
                Registry().execute('live_theme_changed')
                self.override = {}
            else:
                # replace the background
                background = self.image_manager.get_image_bytes(
                    self.override['image'], ImageSource.ImagePlugin)
        self.set_transparency(
            self.service_item.theme_data.background_type ==
            BackgroundType.to_string(BackgroundType.Transparent))
        image_bytes = None
        if self.service_item.theme_data.background_type == 'image':
            if self.service_item.theme_data.background_filename:
                self.service_item.bg_image_bytes = self.image_manager.get_image_bytes(
                    path_to_str(
                        self.service_item.theme_data.background_filename),
                    ImageSource.Theme)
            if image_path:
                image_bytes = self.image_manager.get_image_bytes(
                    image_path, ImageSource.ImagePlugin)
        created_html = build_html(self.service_item,
                                  self.screen,
                                  self.is_live,
                                  background,
                                  image_bytes,
                                  plugins=self.plugin_manager.plugins)
        self.web_view.setHtml(created_html)
        if service_item.foot_text:
            self.footer(service_item.foot_text)
        # if was hidden keep it hidden
        if self.hide_mode and self.is_live and not service_item.is_media():
            if Settings().value('core/auto unblank'):
                Registry().execute('slidecontroller_live_unblank')
            else:
                self.hide_display(self.hide_mode)
        if self.service_item.theme_data.background_type == 'video' and self.is_live:
            if self.service_item.theme_data.background_filename:
                service_item = ServiceItem()
                service_item.title = 'webkit'
                service_item.processor = 'webkit'
                path = str(
                    AppLocation.get_section_data_path('themes') /
                    self.service_item.theme_data.theme_name)
                service_item.add_from_command(
                    path,
                    path_to_str(
                        self.service_item.theme_data.background_filename),
                    UiIcons().media)
                self.media_controller.video(DisplayControllerType.Live,
                                            service_item,
                                            video_behind_text=True)
        self._hide_mouse()