321 |
321 |
322 from .PageThumbnailer import PageThumbnailer |
322 from .PageThumbnailer import PageThumbnailer |
323 thumbnailer = PageThumbnailer(self) |
323 thumbnailer = PageThumbnailer(self) |
324 thumbnailer.setUrl(QUrl.fromEncoded(url.encode("utf-8"))) |
324 thumbnailer.setUrl(QUrl.fromEncoded(url.encode("utf-8"))) |
325 thumbnailer.setLoadTitle(loadTitle) |
325 thumbnailer.setLoadTitle(loadTitle) |
326 thumbnailer.thumbnailCreated.connect(self.__thumbnailCreated) |
326 thumbnailer.thumbnailCreated.connect( |
|
327 lambda imag: self.__thumbnailCreated(imag, thumbnailer)) |
327 self.__thumbnailers.append(thumbnailer) |
328 self.__thumbnailers.append(thumbnailer) |
328 |
329 |
329 thumbnailer.start() |
330 thumbnailer.start() |
330 |
331 |
331 @pyqtSlot(str) |
332 @pyqtSlot(str) |
383 |
384 |
384 @return speed dial size (integer) |
385 @return speed dial size (integer) |
385 """ |
386 """ |
386 return self.__speedDialSize |
387 return self.__speedDialSize |
387 |
388 |
388 def __thumbnailCreated(self, image): |
389 def __thumbnailCreated(self, image, thumbnailer): |
389 """ |
390 """ |
390 Private slot to handle the creation of a thumbnail image. |
391 Private slot to handle the creation of a thumbnail image. |
391 |
392 |
392 @param image thumbnail image (QPixmap) |
393 @param image thumbnail image |
393 """ |
394 @type QPixmap |
394 from .PageThumbnailer import PageThumbnailer |
395 @param thumbnailer reference to the page thumbnailer |
395 thumbnailer = self.sender() |
396 @type PageThumbnailer |
396 if not isinstance(thumbnailer, PageThumbnailer) or \ |
397 """ |
397 thumbnailer not in self.__thumbnailers: |
398 if thumbnailer in self.__thumbnailers: |
398 return |
399 loadTitle = thumbnailer.loadTitle() |
399 |
400 title = thumbnailer.title() |
400 loadTitle = thumbnailer.loadTitle() |
401 url = thumbnailer.url().toString() |
401 title = thumbnailer.title() |
402 fileName = self.__imageFileName(url) |
402 url = thumbnailer.url().toString() |
403 |
403 fileName = self.__imageFileName(url) |
404 if image.isNull(): |
404 |
405 fileName = "qrc:icons/brokenPage.png" |
405 if image.isNull(): |
406 title = self.tr("Unable to load") |
406 fileName = "qrc:icons/brokenPage.png" |
407 page = self.pageForUrl(thumbnailer.url()) |
407 title = self.tr("Unable to load") |
408 page.broken = True |
408 page = self.pageForUrl(thumbnailer.url()) |
409 else: |
409 page.broken = True |
410 if not image.save(fileName, "PNG"): |
410 else: |
411 qWarning( |
411 if not image.save(fileName, "PNG"): |
412 "SpeedDial.__thumbnailCreated: Cannot save thumbnail" |
412 qWarning( |
413 " to {0}".format(fileName)) |
413 "SpeedDial.__thumbnailCreated: Cannot save thumbnail" |
414 |
414 " to {0}".format(fileName)) |
415 self.__regenerateScript = True |
415 |
416 thumbnailer.deleteLater() |
416 self.__regenerateScript = True |
417 self.__thumbnailers.remove(thumbnailer) |
417 thumbnailer.deleteLater() |
418 |
418 self.__thumbnailers.remove(thumbnailer) |
419 if loadTitle: |
419 |
420 self.pageTitleLoaded.emit(url, title) |
420 if loadTitle: |
421 |
421 self.pageTitleLoaded.emit(url, title) |
422 self.thumbnailLoaded.emit( |
422 |
423 url, pixmapToDataUrl(QPixmap(fileName)).toString()) |
423 self.thumbnailLoaded.emit( |
|
424 url, pixmapToDataUrl(QPixmap(fileName)).toString()) |
|
425 |
424 |
426 def __escapeTitle(self, title): |
425 def __escapeTitle(self, title): |
427 """ |
426 """ |
428 Private method to escape a title string. |
427 Private method to escape a title string. |
429 |
428 |