Diez B. Roggisch wrote:
> I'm not aware of a ready-to-go solution, but at least under Qt you 
> should be able to utilize the KHTML component to render a bitmap file.

That's a god idea. I will look into that.

>>Would be nice to have an easy-to-use TG widget for this.
> 
> This isn't a TG widget domain. A widget is a server-side, 
> HTML-processing thing. There is no way it can accomplish that.

I beg to differ (untested, but I do a similar thing with gravatar images):


import md5
from os.path import join
from urllib import quote_plus

import cherrypy

from turbogears import config, controllers
from turbogears import url as tg_url
from turbogears.widgets import *

class Snapshot(Widget):
     template = """<img xmlns:py="http://purl.org/kid/ns#"; py:attrs="attrs"
src="${url}" />"""
     params = ['url', 'size']
     url = None
     size = 200
     _controller_url = '/snapshot'

     def update_params(self, params):
         """Converts site URL to URL to our controller.
         """

         super(Snapshot, self).update_params(params)
         url = "%s?site=%s&size=%i" % (self._controller_url,
           quote_plus(params['url']), params['size'])
         params['url'] = tg_url(url)
         params['attrs'].setdefault('class', 'snapshot')

class SnapshotController(controllers.Controller):

     def __init__(self, cache_dir=None):
         self.cache_dir = cache_dir
         if not cache_dir:
             self.cache_dir = join(
               config.get('static_filter.dir', path="/static"),
               'images', 'snapshots')

     @expose()
     def default(self, site, size):
         """Get website snapshot from cache or schedule generation."""

         # look up and/or generate snapshot here
         # taking size into account
         img = self.get_snapshot(site, size)
         # img now either is the snapshot from the cache or a 
placeholder image
         cherry.serve_file(img, 'image/jpg')

     def get_snapshot(self, site, size):
         """This is where the magic happens"""

         return join(self.cache_dir, md5.new(site + str(size)).hexdigest())


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to