示例#1
0
    def _create_album_info(self, title, artist_name, tracks, length):
        """
        Create album info labels.
        @param title: Album title
        @param artist_name: Artist
        @param tracks: List of CompactDisc objects
        """
        album = Label(0.04167, "text", 0.50146, 0.13,
           artist_name + " - " + title, font_weight="bold")
        album.set_size(0.4393, 0.06510)
        album.set_ellipsize(pango.ELLIPSIZE_END)
        self.add(album)

        minutes = str(length / 60)

        num_of_tracks = Label(0.02604, "subtitle", 0.50146, 0.18,
            _("%(total)s tracks, %(time)s minutes") % \
            {'total': len(tracks), 'time': minutes}, font_weight="bold")
        self.add(num_of_tracks)
示例#2
0
    def _create_no_photos_information(self):
        """
        Create textures and labels for information screen. This is displayed
        instead of album list if there are no photos available and it helps
        users to add new photographs to the system.
        """
        # Create warning icon
        warning_icon = Texture(self.theme.getImage("warning_icon"), 0.28, 0.27)
        self.add(warning_icon)

        # Create warning title
        info_title = Label(0.0625, "title", 0.3367, 0.2709,
            _("No photographs available!"))
        self.add(info_title)

        # Create warning help text
        message = _(
            "There are no indexed photographs in the Entertainer media "
            "library. To add photographs, start the Content management tool "
            "and open the 'Images' tab. Now click on the 'Add' button and "
            "select some folders which contain image files.")
        info = Label(0.0417, "menuitem_inactive", 0.2804, 0.45, message)
        info.set_size(0.5, 0.5859)
        self.add(info)
示例#3
0
    def _create_no_photos_information(self):
        """
        Create textures and labels for information screen. This is displayed
        instead of album list if there are no photos available and it helps
        users to add new photographs to the system.
        """
        # Create warning icon
        warning_icon = Texture(self.theme.getImage("warning_icon"), 0.28, 0.27)
        self.add(warning_icon)

        # Create warning title
        info_title = Label(0.0625, "title", 0.3367, 0.2709,
                           _("No photographs available!"))
        self.add(info_title)

        # Create warning help text
        message = _(
            "There are no indexed photographs in the Entertainer media "
            "library. To add photographs, start the Content management tool "
            "and open the 'Images' tab. Now click on the 'Add' button and "
            "select some folders which contain image files.")
        info = Label(0.0417, "menuitem_inactive", 0.2804, 0.45, message)
        info.set_size(0.5, 0.5859)
        self.add(info)
示例#4
0
class LabelTest(EntertainerTest):
    """Test for entertainerlib.gui.widgets.label"""

    def setUp(self):
        """Set up the test"""
        EntertainerTest.setUp(self)

        self.label = Label(0.1, "screentitle", 0.1, 0.2, "Test Label text",
            "test_name")

    def test_create(self):
        """Test correct Label initialization."""
        self.assertTrue(isinstance(self.label, (Base, clutter.Label)))

    def test_set_size(self):
        """Test correct size setting."""
        self.label.set_size(.75, .8)
        self.assertEqual(self.label.get_size(), (1024, 614))
        self.assertTrue(self.label.width > 0.75 * 0.99)
        self.assertTrue(self.label.width < 0.75 * 1.01)

    def test_width(self):
        """Test the width property."""
        self.label.width = 0.5
        self.assertEqual(self.label.width, 0.5)

        self.label._set_width(0.4)
        self.assertTrue(self.label._get_width() > 0.4 * 0.99)
        self.assertTrue(self.label._get_width() < 0.4 * 1.01)

    def test_font_size(self):
        """Test the font_size property."""
        self.label.font_size = 0.2
        self.assertEqual(self.label.font_size, 0.2)

        self.label._set_font_size(0.3)
        self.assertEqual(self.label._get_font_size(), 0.3)

    def testHeight(self):
        """Test the height property"""
        self.label.height = 0.5
        self.assertEqual(self.label.height, 0.5)

        self.label._set_height(0.4)
        self.assertTrue(self.label._get_height() > 0.4 * 0.99)
        self.assertTrue(self.label._get_height() < 0.4 * 1.01)

    def test_position(self):
        """Test the position property."""
        self.assertEqual(self.label.position, (0.1, 0.2))

        self.label.position = (0.4, 0.5)
        self.assertEqual(self.label.position, (0.4, 0.5))

        self.label._set_position((0.3, 0.6))
        self.assertEqual(self.label._get_position(), (0.3, 0.6))

    def test_color(self):
        """Test the color property."""
        self.label.color = "screentitle"
        self.assertEqual(self.label.color, "screentitle")
        self.assertEqual(self.label.get_color().red, 255)
        self.assertEqual(self.label.get_color().green, 255)
        self.assertEqual(self.label.get_color().blue, 255)
        self.assertEqual(self.label.get_color().alpha, 16)

        self.label.color = "background"
        self.assertEqual(self.label.color, "background")
        self.assertEqual(self.label.get_color().red, 21)
        self.assertEqual(self.label.get_color().green, 45)
        self.assertEqual(self.label.get_color().blue, 83)
        self.assertEqual(self.label.get_color().alpha, 255)
示例#5
0
class Photographs(Screen):
    '''Screen displays a grid of selectable photograph thumbnails.'''
    def __init__(self, move_to_new_screen_callback, title, images):
        Screen.__init__(self, 'Photographs', move_to_new_screen_callback)

        self.images = images

        # Screen Title (Displayed at the bottom left corner)
        screen_title = Label(0.13, "screentitle", 0, 0.87, title)
        self.add(screen_title)

        # Image Title (over album list)
        self.image_title = Label(0.04167, "title", 0.0586, 0.7943, " ")
        self.image_title.set_ellipsize(pango.ELLIPSIZE_END)
        self.add(self.image_title)

        self.image_desc = Label(0.04167, "subtitle", 0.0586, 0.9115, " ")
        self.image_desc.set_line_wrap(True)
        self.image_desc.set_ellipsize(pango.ELLIPSIZE_END)
        self.add(self.image_desc)

        # Display throbber animation while loading photographs
        self.throbber = LoadingAnimation(0.9, 0.9)
        self.throbber.show()
        self.add(self.throbber)

        # List indicator
        self.li = None
        self._create_list_indicator()

        # Create photomenu
        self.menu = ImageMenu(0.03, 0.08, 0.12, self.y_for_x(0.12))
        self.menu.items_per_col = 3
        self.menu.visible_rows = 3
        self.menu.visible_cols = 8
        self.menu.active = True
        self.add(self.menu)

        photos = self.images
        photos_list = [[Texture(photo.get_thumbnail_url()), photo] \
            for photo in photos]
        self.menu.async_add(photos_list)

        self.menu.connect("selected", self._handle_select)
        self.menu.connect('moved', self._update_image_info)
        self.menu.connect("filled", self._on_menu_filled)

    def _update_image_info(self, event=None):
        """Update image information box."""
        image = self.images[self.menu.selected_index]
        name = image.get_title()
        desc = image.get_description()
        self.image_title.set_text(name)
        self.image_title.set_size(0.366, 0.04167)
        self.image_desc.set_text(desc)
        self.image_desc.set_size(0.366, 0.0911)
        self.li.set_current(self.menu.selected_index + 1)

    def _create_list_indicator(self):
        '''Create list indicator for albums list.'''
        self.li = ListIndicator(0.77, 0.8, 0.18, 0.045,
                                ListIndicator.HORIZONTAL)
        self.li.set_maximum(len(self.images))
        self.add(self.li)

    def _handle_up(self):
        '''Handle UserEvent.NAVIGATE_UP.'''
        self.menu.up()

    def _handle_down(self):
        '''Handle UserEvent.NAVIGATE_DOWN.'''
        self.menu.down()

    def _handle_left(self):
        '''Handle UserEvent.NAVIGATE_LEFT.'''
        self.menu.left()

    def _handle_right(self):
        '''Handle UserEvent.NAVIGATE_RIGHT.'''
        self.menu.right()

    def _handle_select(self, event=None):
        '''Handle UserEvent.NAVIGATE_SELECT.'''
        index = self.menu.selected_index
        kwargs = {'current_photo_index': index, 'images': self.images}
        self.callback("photo", kwargs)

    def _on_menu_filled(self, event=None):
        '''Handles filled event.'''
        self.throbber.hide()
示例#6
0
    def create_movie_information(self):
        '''Create clutter parts related to movie information'''

        # Movie art texture
        if self.movie.has_cover_art():
            pixbuf = gtk.gdk.pixbuf_new_from_file(self.movie.cover_art_url)
        else:
            pixbuf = gtk.gdk.pixbuf_new_from_file(
                self.theme.getImage("default_movie_art"))
        movie_art = EyeCandyTexture(0.33, 0.1, 0.1, 0.25, pixbuf)
        self.add(movie_art)

        # Movie title
        title = Label(0.04, "title", 0.47, 0.1, self.movie.title,
            font_weight="bold")
        title.set_ellipsize(pango.ELLIPSIZE_END)
        title.set_size(0.5124, 0.05208)
        self.add(title)

        # Movie release year
        year_text = _("Released in %(year)s") % {'year': self.movie.year}
        year = Label(0.032, "subtitle", 0.47, 0.3, year_text)
        year.set_ellipsize(pango.ELLIPSIZE_END)
        year.set_size(0.5124, 0.05208)
        self.add(year)

        # Show only 2 genres (or one if there is only one)
        genres_list = self.movie.genres
        if len(genres_list) == 0:
            genres_text = _("Unknown")
        else:
            genres_text = "/".join(genres_list[:2])

        # Runtime and genres
        info_text = _("%(runtime)s min, %(genre)s") % \
            {'runtime': self.movie.runtime, 'genre': genres_text}
        info = Label(0.032, "subtitle", 0.47, 0.24, info_text)
        info.set_ellipsize(pango.ELLIPSIZE_END)
        info.set_size(0.5124, 0.05208)
        self.add(info)

        # Stars (rating)
        star = Texture(self.theme.getImage("star"))
        star.hide()
        self.add(star)
        star2 = Texture(self.theme.getImage("star2"))
        star2.hide()
        self.add(star2)

        for i in range(self.movie.rating):
            tex = clutter.Clone(star)
            tex.set_position(
                self.get_abs_x(0.47) + (self.get_abs_x(0.0366) * i),
                self.get_abs_y(0.17))
            tex.set_size(self.get_abs_x(0.024), self.get_abs_y(0.04))
            self.add(tex)

        dark_star = 5 - self.movie.rating
        for i in range(dark_star):
            tex = clutter.Clone(star2)
            tex.set_position(self.get_abs_x(0.47) + (self.get_abs_x(0.0366) * \
                (i + self.movie.rating)), self.get_abs_y(0.17))
            tex.set_size(self.get_abs_x(0.024), self.get_abs_y(0.04))
            self.add(tex)

        # Plot
        plot = Label(0.029, "subtitle", 0, 0, self.movie.plot)
        plot.set_justify(True)
        plot.set_line_wrap_mode(pango.WRAP_WORD)
        plot.set_line_wrap(True)
        plot.width = 0.5124
        self.scroll_area = ScrollArea(0.33, 0.38, 0.5124, 0.3516, plot)
        self.add(self.scroll_area)

        # Actors
        self.add(Label(0.032, "title", 0.33, 0.8, _("Starring")))

        actors_list = self.movie.actors
        if len(actors_list) == 0:
            actors_text = _("Unknown")
        else:
            actors_text = ", ".join(actors_list[:5])
        actors = Label(0.032, "subtitle", 0.46, 0.8, actors_text)
        actors.set_ellipsize(pango.ELLIPSIZE_END)
        actors.set_size(0.5124, 0.05208)
        self.add(actors)

        # Directors
        self.add(Label(0.032, "title", 0.33, 0.86, _("Directed by")))

        directors_list = self.movie.directors
        if len(directors_list) == 0:
            directors_text = _("Unknown")
        else:
            directors_text = ", ".join(directors_list[:2])
        directors = Label(0.032, "subtitle", 0.46, 0.86, directors_text)
        directors.set_ellipsize(pango.ELLIPSIZE_END)
        directors.set_size(0.5124, 0.05208)
        self.add(directors)

        # Writers
        self.add(Label(0.032, "title", 0.33, 0.92, _("Written by")))

        writers_list = self.movie.writers
        if len(directors_list) == 0:
            writers_text = _("Unknown")
        else:
            writers_text = ", ".join(writers_list[:2])
        writers = Label(0.032, "subtitle", 0.46, 0.92, writers_text)
        writers.set_ellipsize(pango.ELLIPSIZE_END)
        writers.set_size(0.5124, 0.05208)
        self.add(writers)
示例#7
0
class LabelTest(EntertainerTest):
    """Test for entertainerlib.gui.widgets.label"""
    def setUp(self):
        """Set up the test"""
        EntertainerTest.setUp(self)

        self.label = Label(0.1, "screentitle", 0.1, 0.2, "Test Label text",
                           "test_name")

    def test_create(self):
        """Test correct Label initialization."""
        self.assertTrue(isinstance(self.label, (Base, clutter.Label)))

    def test_set_size(self):
        """Test correct size setting."""
        self.label.set_size(.75, .8)
        self.assertEqual(self.label.get_size(), (1024, 614))
        self.assertTrue(self.label.width > 0.75 * 0.99)
        self.assertTrue(self.label.width < 0.75 * 1.01)

    def test_width(self):
        """Test the width property."""
        self.label.width = 0.5
        self.assertEqual(self.label.width, 0.5)

        self.label._set_width(0.4)
        self.assertTrue(self.label._get_width() > 0.4 * 0.99)
        self.assertTrue(self.label._get_width() < 0.4 * 1.01)

    def test_font_size(self):
        """Test the font_size property."""
        self.label.font_size = 0.2
        self.assertEqual(self.label.font_size, 0.2)

        self.label._set_font_size(0.3)
        self.assertEqual(self.label._get_font_size(), 0.3)

    def testHeight(self):
        """Test the height property"""
        self.label.height = 0.5
        self.assertEqual(self.label.height, 0.5)

        self.label._set_height(0.4)
        self.assertTrue(self.label._get_height() > 0.4 * 0.99)
        self.assertTrue(self.label._get_height() < 0.4 * 1.01)

    def test_position(self):
        """Test the position property."""
        self.assertEqual(self.label.position, (0.1, 0.2))

        self.label.position = (0.4, 0.5)
        self.assertEqual(self.label.position, (0.4, 0.5))

        self.label._set_position((0.3, 0.6))
        self.assertEqual(self.label._get_position(), (0.3, 0.6))

    def test_color(self):
        """Test the color property."""
        self.label.color = "screentitle"
        self.assertEqual(self.label.color, "screentitle")
        self.assertEqual(self.label.get_color().red, 255)
        self.assertEqual(self.label.get_color().green, 255)
        self.assertEqual(self.label.get_color().blue, 255)
        self.assertEqual(self.label.get_color().alpha, 16)

        self.label.color = "background"
        self.assertEqual(self.label.color, "background")
        self.assertEqual(self.label.get_color().red, 21)
        self.assertEqual(self.label.get_color().green, 45)
        self.assertEqual(self.label.get_color().blue, 83)
        self.assertEqual(self.label.get_color().alpha, 255)
示例#8
0
class Photographs(Screen):
    '''Screen displays a grid of selectable photograph thumbnails.'''

    def __init__(self, move_to_new_screen_callback, title, images):
        Screen.__init__(self, 'Photographs', move_to_new_screen_callback)

        self.images = images

        # Screen Title (Displayed at the bottom left corner)
        screen_title = Label(0.13, "screentitle", 0, 0.87, title)
        self.add(screen_title)

        # Image Title (over album list)
        self.image_title = Label(0.04167, "title", 0.0586, 0.7943, " ")
        self.image_title.set_ellipsize(pango.ELLIPSIZE_END)
        self.add(self.image_title)

        self.image_desc = Label(0.04167, "subtitle", 0.0586, 0.9115, " ")
        self.image_desc.set_line_wrap(True)
        self.image_desc.set_ellipsize(pango.ELLIPSIZE_END)
        self.add(self.image_desc)

        # Display throbber animation while loading photographs
        self.throbber = LoadingAnimation(0.9, 0.9)
        self.throbber.show()
        self.add(self.throbber)

        # List indicator
        self.li = None
        self._create_list_indicator()

        # Create photomenu
        self.menu = ImageMenu(0.03, 0.08, 0.12, self.y_for_x(0.12))
        self.menu.items_per_col = 3
        self.menu.visible_rows = 3
        self.menu.visible_cols = 8
        self.menu.active = True
        self.add(self.menu)

        photos = self.images
        photos_list = [[Texture(photo.get_thumbnail_url()), photo] \
            for photo in photos]
        self.menu.async_add(photos_list)

        self.menu.connect("selected", self._handle_select)
        self.menu.connect('moved', self._update_image_info)
        self.menu.connect("filled", self._on_menu_filled)

    def _update_image_info(self, event=None):
        """Update image information box."""
        image = self.images[self.menu.selected_index]
        name = image.get_title()
        desc = image.get_description()
        self.image_title.set_text(name)
        self.image_title.set_size(0.366, 0.04167)
        self.image_desc.set_text(desc)
        self.image_desc.set_size(0.366, 0.0911)
        self.li.set_current(self.menu.selected_index + 1)

    def _create_list_indicator(self):
        '''Create list indicator for albums list.'''
        self.li = ListIndicator(0.77, 0.8, 0.18, 0.045,
            ListIndicator.HORIZONTAL)
        self.li.set_maximum(len(self.images))
        self.add(self.li)

    def _handle_up(self):
        '''Handle UserEvent.NAVIGATE_UP.'''
        self.menu.up()

    def _handle_down(self):
        '''Handle UserEvent.NAVIGATE_DOWN.'''
        self.menu.down()

    def _handle_left(self):
        '''Handle UserEvent.NAVIGATE_LEFT.'''
        self.menu.left()

    def _handle_right(self):
        '''Handle UserEvent.NAVIGATE_RIGHT.'''
        self.menu.right()

    def _handle_select(self, event=None):
        '''Handle UserEvent.NAVIGATE_SELECT.'''
        index = self.menu.selected_index
        kwargs = {'current_photo_index' : index, 'images' : self.images}
        self.callback("photo", kwargs)

    def _on_menu_filled(self, event=None):
        '''Handles filled event.'''
        self.throbber.hide()