/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to avatarproviders.py

  • Committer: Curtis Hovey
  • Date: 2011-09-08 03:11:06 UTC
  • mto: This revision was merged to the branch mainline in revision 741.
  • Revision ID: sinzui.is@verizon.net-20110908031106-c0s7grzmctdyghcm
Fixed packing args.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
        threading.Thread.__init__(self)
54
54
        self.__stop = threading.Event()
55
55
        self.__queue = Queue.Queue()
 
56
 
56
57
        self.__provider_method = provider_method
57
 
        self.__callback_method = None
58
 
        self.__error_method = None
59
58
 
60
59
    def stop(self):
61
60
        """ Stop this worker """
70
69
        return not self.__stop.is_set()
71
70
 
72
71
    def set_callback_method(self, method):
73
 
        """Fire the given callback method when treatment is finished."""
 
72
        """ Fire the given callback method when treatment is finished """
74
73
        self.__callback_method = method
75
74
 
76
 
    def set_error_method(self, method):
77
 
        """Fire the given callback when retrieving a avatar fails."""
78
 
        self.__error_method = method
79
 
 
80
75
    def queue(self, id_field):
81
76
        """Put in Queue the id_field to treat in the thread.
82
77
 
95
90
                # Call provider method to get fields to pass in the request
96
91
                url = self.__provider_method(id_field)
97
92
                # Execute the request
98
 
                try:
99
 
                    response = urllib2.urlopen(url)
100
 
                except urllib2.URLError, e:
101
 
                    if self.__error_method is not None:
102
 
                        self.__error_method(e)
103
 
                else:
104
 
                    # Fire the callback method
105
 
                    if not self.__callback_method is None:
106
 
                        self.__callback_method(response, id_field)
 
93
                response = urllib2.urlopen(url)
 
94
                # Fire the callback method
 
95
                if not self.__callback_method is None:
 
96
                    self.__callback_method(response, id_field)
107
97
                self.__queue.task_done()
108
98
            except Queue.Empty:
109
99
                # There is no more work to do.