Browse Source

Sorting seems to work

master
Julio Biason 16 years ago
parent
commit
e5fd183ff9
  1. 54
      mitterlib/ui/ui_pygtk.py

54
mitterlib/ui/ui_pygtk.py

@ -26,6 +26,7 @@ import logging
import threading import threading
import Queue import Queue
import re import re
import urllib2
from mitterlib.ui.helpers.image_helpers import find_image from mitterlib.ui.helpers.image_helpers import find_image
@ -465,13 +466,18 @@ class Interface(object):
data = store.get_value(position, 0) data = store.get_value(position, 0)
pic = data.avatar pic = data.avatar
if not pic in self._user_pics: if not pic in self._avatars:
cell.set_property('pixbuf', self._default_pixmap) self._threads.add_work(self._post_download_pic,
self._exception_download_pic,
self._download_pic,
pic)
# just make sure we download this pic too. # set the user avatar to the default image, so it won't get queued
#self.queue_pic(pic) # again. Once downloaded, the _post_download_pic will update the
else: # image and force a redraw.
cell.set_property('pixbuf', self._user_pics[pic]) self._avatars[pic] = self._default_pixmap
cell.set_property('pixbuf', self._user_pics[pic])
return return
@ -621,6 +627,40 @@ class Interface(object):
_log.debug(str(exception)) _log.debug(str(exception))
return return
### image download function
def _download_pic(self, url):
"""Download a picture from the web. Can be used in a thread."""
request = urllib2.Request(url=url)
_log.debug('Starting request of %s' % (url))
response = urllib2.urlopen(request)
data = response.read()
_log.debug('Request completed')
return (url, data)
### Results from the picture request
def _post_download_pic(self, widget, data):
"""Called after the data from the picture is available."""
(url, data) = data
loader = gtk.gdk.PixbufLoader()
loader.write(data)
loader.close()
user_pic = loader.get_pixbuf()
user_pic = user_pic.scale_simple(48, 48, gtk.gdk.INTERP_BILINEAR)
self._avatars[url] = user_pic
self._grid.queue_draw()
return
def _exception_download_pic(self, widget, exception):
"""Called in case we have a problem downloading an user avatar."""
_log.debug('Exception trying to get an avatar.')
_log.debug(str(exception))
return
# ------------------------------------------------------------ # ------------------------------------------------------------
# Required functions for all interfaces # Required functions for all interfaces
# ------------------------------------------------------------ # ------------------------------------------------------------
@ -633,7 +673,7 @@ class Interface(object):
self._connection = connection self._connection = connection
self._options = options self._options = options
self._user_pics = {} self._avatars = {}
self._pic_queue = set() self._pic_queue = set()
# Load images # Load images

Loading…
Cancel
Save