~enli/lernid/links-in-default-browser

« back to all changes in this revision

Viewing changes to lernid/widgets/Slide.py

  • Committer: Michael Budde
  • Date: 2010-03-04 12:42:38 UTC
  • mfrom: (194.1.4 async-slide-download)
  • Revision ID: mbudde@gmail.com-20100304124238-82she325dp8aei2b
Download slides in the background (LP: #530119)

Merge of lp:~enli/lernid/async-slide-download by Peeyoosh Sangolekar

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import re
25
25
import logging
26
26
import urllib
 
27
from threading import Thread
27
28
 
28
29
from lernid.widgets.Widget import Widget
29
30
from lernid.lernidconfig import save_cache_path
138
139
            self._image.set_from_pixbuf(newpb)
139
140
            self._image.show()
140
141
 
 
142
    def _download_slides(self, session):
 
143
        path = os.path.join(save_cache_path('lernid'), 'slides.pdf')
 
144
        try:
 
145
            logging.debug('downloading slides from %s' % session.slides)
 
146
            Statusbar.push_message(_('Downloading session slides...'), 'slidesession')
 
147
            urllib.urlretrieve(session.slides, path)
 
148
            Statusbar.push_message(_('Slides have been downloaded'), 'slidesession')
 
149
            self._session_slide_downloaded = True
 
150
            self.emit('slides-downloaded')
 
151
            self._change_slide_page(1)
 
152
        except:
 
153
            Statusbar.push_message(_('An error was encountered while downloading slides'), 'slidesession')
 
154
            logging.debug('Error when downloading slides from %s' % session.slides)
 
155
 
141
156
    def _session_changed(self, schedule, session):
142
157
        Statusbar.pop_message('slidesession')
143
 
        path = os.path.join(save_cache_path('lernid'), 'slides.pdf')
144
158
        if session.slides:
145
 
            try:
146
 
                logging.debug('downloading slides from %s' % session.slides)
147
 
                urllib.urlretrieve(session.slides, path)
148
 
                Statusbar.push_message(_('Slides have been downloaded'), 'slidesession')
149
 
                self._session_slide_downloaded = True
150
 
                self.emit('slides-downloaded')
151
 
                self._change_slide_page(1)
152
 
            except:
153
 
                Statusbar.push_message(_('An error was encountered while downloading slides'), 'slidesession')
154
 
                logging.debug('Error when downloading slides from %s' % session.slides)
 
159
            thread = Thread(target=self._download_slides, args=(session,))
 
160
            thread.start()
155
161
        else:
156
162
            self._image.clear()
157
163
            self.hide()
163
169
        self.hide()
164
170
        Statusbar.pop_message('slidesession')
165
171
        self._session_slide_downloaded = False
 
172