Hi Jesús
Thanks, it helped a lot (and it works for me now)!
My code looks like:
    def get_image(self, item, theme):
        if isinstance(item, Action):
            image_deferred = defer.succeed(item.icon)
        elif isinstance(item, StationModel):
            image_deferred = defer.succeed(item.resource)
        else:
            image_deferred = None

        return image_deferred

Pretty simple.

Best Regards,
Kristian

> Date: Fri, 13 Feb 2009 11:12:14 +0100
> From: [email protected]
> To: [email protected]
> CC: [email protected]
> Subject: Re: [Elisa] Problems with get_image and deferred
> 
> En/na Kristian Lippert ha escrit:
> > Hi
> > I read in the documentation that GenericListViewMode.get_image 
> > overrides must return a cancellable deferred that must return a path 
> > to the resource (my jpg picture).
> > It looks like:
> >     def get_image(self, item, theme): #gets called one time for each 
> > item when displaying in list
> >         # this call is async and must return a deferred
> >
> >         def get_resource(item):
> >             if isinstance(item, Action):
> >                 resource = item.icon
> >             elif isinstance(item, StationModel):
> >                 tmp = os.path.join(CONFIG_DIR, 'mystream_logos')
> >                 resource = os.path.join(tmp, item.resource)
> >             else:
> >                 resource = None
> >             return resource
> >
> >         dfr = defer.Deferred().addCallback(get_resource, item)
> Look at this code from another plugin. In your case is a lot more simple:
> 
> def get_image(self, item, theme):
>         if isinstance(item, RadioModel):
>             try:
>                 thumbnail_file = item.thumbnail_file
>                 image_deferred = defer.succeed(item.thumbnail_file)
>             except AttributeError:
>                 def get_thumbnail(images):
>                     return _get_photo_thumbnail(item)
>                
>                 image_deferred = defer.succeed(item)
>                 image_deferred.addCallback(get_thumbnail)
>             return image_deferred
>         else:
>             return None
> 
> -- 
> Jesús Corrius
> <[email protected]>

_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.

http://www.microsoft.com/windows/windowslive/products/photos.aspx

Reply via email to