예제 #1
0
    def _get_contact_pixbuf_or_default(self, contact):
        '''try to return a pixbuf of the user picture or the default
        picture
        '''
        if contact.picture:
            # TODO: This could be handled in AvatarManager in the same
            # way as avatars from the Avatar class
            try:
                animation = gtk.gdk.PixbufAnimation(contact.picture)
            except gobject.GError:
                pix = utils.gtk_pixbuf_load(
                    gui.theme.image_theme.user,
                    (self.avatar_size, self.avatar_size))
                picture = gtk.image_new_from_pixbuf(pix)
                return picture

            if animation.is_static_image():
                pix = utils.gtk_pixbuf_load(
                    contact.picture, (self.avatar_size, self.avatar_size))

                if bool(contact.blocked):
                    pixbufblock = utils.gtk_pixbuf_load(
                        gui.theme.image_theme.blocked_overlay)
                    utils.simple_images_overlap(pix, pixbufblock,
                                                -pixbufblock.props.width,
                                                -pixbufblock.props.width)

                picture = gtk.image_new_from_pixbuf(pix)
            else:
                myanimation = utils.simple_animation_scale(
                    contact.picture, self.avatar_size, self.avatar_size)

                if bool(contact.blocked):
                    pixbufblock = utils.gtk_pixbuf_load(
                        gui.theme.image_theme.blocked_overlay)
                    static_image = myanimation.get_static_image()
                    pix = static_image.scale_simple(self.avatar_size,
                                                    self.avatar_size,
                                                    gtk.gdk.INTERP_BILINEAR)
                    utils.simple_images_overlap(pix, pixbufblock,
                                                -pixbufblock.props.width,
                                                -pixbufblock.props.width)
                    picture = gtk.image_new_from_pixbuf(pix)
                else:
                    picture = gtk.image_new_from_animation(myanimation)
        else:
            pix = utils.gtk_pixbuf_load(gui.theme.image_theme.user,
                                        (self.avatar_size, self.avatar_size))

            if bool(contact.blocked):
                pixbufblock = utils.gtk_pixbuf_load(
                    gui.theme.image_theme.blocked_overlay)
                utils.simple_images_overlap(pix, pixbufblock,
                                            -pixbufblock.props.width,
                                            -pixbufblock.props.width)

            picture = gtk.image_new_from_pixbuf(pix)

        return picture
예제 #2
0
    def _get_contact_pixbuf_or_default(self, contact):
        '''try to return a pixbuf of the user picture or the default
        picture
        '''
        if contact.picture:
            # TODO: This could be handled in AvatarManager in the same
            # way as avatars from the Avatar class
            try:
                animation = gtk.gdk.PixbufAnimation(contact.picture)
            except gobject.GError:
                pix = utils.gtk_pixbuf_load(gui.theme.image_theme.user,
                        (self.avatar_size, self.avatar_size))
                picture = gtk.image_new_from_pixbuf(pix)
                return picture

            if animation.is_static_image():
                pix = utils.gtk_pixbuf_load(contact.picture,
                        (self.avatar_size, self.avatar_size))

                if bool(contact.blocked):
                    pixbufblock=utils.gtk_pixbuf_load(gui.theme.image_theme.blocked_overlay)
                    utils.simple_images_overlap(pix, pixbufblock,
                                                -pixbufblock.props.width,
                                                -pixbufblock.props.width)

                picture = gtk.image_new_from_pixbuf(pix)
            else:
                myanimation = utils.simple_animation_scale(contact.picture,
                                                           self.avatar_size,
                                                           self.avatar_size)

                if bool(contact.blocked):
                    pixbufblock=utils.gtk_pixbuf_load(gui.theme.image_theme.blocked_overlay)
                    static_image = myanimation.get_static_image()
                    pix = static_image.scale_simple(self.avatar_size,
                                                    self.avatar_size,
                                                    gtk.gdk.INTERP_BILINEAR)

                    utils.simple_images_overlap(pix, pixbufblock,
                                                -pixbufblock.props.width,
                                                -pixbufblock.props.width)

                    picture = gtk.image_new_from_pixbuf(pix)
                else:
                    picture = gtk.image_new_from_animation(myanimation)
        else:
            pix = utils.gtk_pixbuf_load(gui.theme.image_theme.user,
                        (self.avatar_size, self.avatar_size))

            if bool(contact.blocked):
                pixbufblock=utils.gtk_pixbuf_load(gui.theme.image_theme.blocked_overlay)
                utils.simple_images_overlap(pix, pixbufblock,
                                            -pixbufblock.props.width,
                                            -pixbufblock.props.width)

            picture = gtk.image_new_from_pixbuf(pix)

        return picture
예제 #3
0
파일: Avatar.py 프로젝트: stlcours/emesene
    def set_from_file(self, filename, blocked=False):
        self.filename = filename
        self.blocked = blocked
        if not gui.gtkui.utils.file_readable(filename):
            if self._dimension > 32:
                # use big fallback image
                self.filename = gui.theme.image_theme.user_def_imagetool
            else:
                self.filename = gui.theme.image_theme.user

        try:
            animation = gtk.gdk.PixbufAnimation(self.filename)
        except gobject.GError:
            animation = gtk.gdk.PixbufAnimation(gui.theme.image_theme.user)

        if animation.is_static_image() or self.blocked:
            static_image = animation.get_static_image()
            static_image = static_image.scale_simple(self._dimension,
                                                     self._dimension,
                                                     gtk.gdk.INTERP_BILINEAR)
        else:
            animation = utils.simple_animation_scale(self.filename,
                                                     self._dimension,
                                                     self._dimension)
            static_image = animation.get_static_image()

        if self.blocked:
            if self._dimension > 32:
                # use big fallback image
                newdim = int(self._dimension * 0.5)
                pixbufblock = utils.gtk_pixbuf_load(
                    gui.theme.image_theme.blocked_overlay_big,
                    (newdim, newdim))
            else:
                pixbufblock = utils.gtk_pixbuf_load(
                    gui.theme.image_theme.blocked_overlay)

            output_pixbuf = utils.simple_images_overlap(
                static_image, pixbufblock, -pixbufblock.props.width,
                -pixbufblock.props.width)

            self.__set_from_pixbuf(output_pixbuf)
            self.current_animation = None
            return
        elif animation.is_static_image():
            self.__set_from_pixbuf(static_image)
            self.current_animation = None
            return

        self.current_animation = animation
        self._start_animation(animation)
예제 #4
0
    def set_from_file(self, filename, blocked=False):
        self.filename = filename
        self.blocked  = blocked
        if not gui.gtkui.utils.file_readable(filename):
            if self._dimension > 32:
                # use big fallback image
                self.filename = gui.theme.image_theme.user_def_imagetool
            else:
                self.filename = gui.theme.image_theme.user

        try:
            animation = gtk.gdk.PixbufAnimation(self.filename)
        except gobject.GError:
            animation = gtk.gdk.PixbufAnimation(gui.theme.image_theme.user)

        if animation.is_static_image() or self.blocked:
            static_image = animation.get_static_image()
            static_image = static_image.scale_simple(self._dimension,
                                                    self._dimension,
                                                    gtk.gdk.INTERP_BILINEAR)
        else:
            animation = utils.simple_animation_scale(self.filename,
                                                self._dimension,
                                                self._dimension)
            static_image = animation.get_static_image()

        if self.blocked:
            if self._dimension > 32:
                # use big fallback image
                pixbufblock = utils.gtk_pixbuf_load(gui.theme.image_theme.blocked_overlay_big,
                                                    (int(self._dimension * 0.5),
                                                     int(self._dimension * 0.5)))
            else:
                pixbufblock = utils.gtk_pixbuf_load(gui.theme.image_theme.blocked_overlay)

            output_pixbuf = utils.simple_images_overlap(static_image, pixbufblock,
                                                        -pixbufblock.props.width,
                                                        -pixbufblock.props.width)

            self.__set_from_pixbuf(output_pixbuf)
            self.current_animation = None
            return
        #FIXME: animations are broken on gtk3, use static pixbuf for now
        elif animation.is_static_image() or check_gtk3():
            self.__set_from_pixbuf(static_image)
            self.current_animation = None
            return

        self.current_animation = animation
        self._start_animation(animation)