def _load_image(self, aFullFilenames): """Load an image into the pane, show broken image if needed""" # pylint: disable=too-many-branches, too-many-locals, too-many-statements # This is has to handle a number of special cases # and subdividing it further won't help clarity self._oImage.set_alignment(0.5, 0.5) # Centre image # Ensure we have an up to information about the image dates self._get_date_data() for sFullFilename in aFullFilenames: if not check_file(sFullFilename): if (self._oImagePlugin.DOWNLOAD_SUPPORTED and self._oImagePlugin.get_config_item(DOWNLOAD_IMAGES)): # Attempt to download the image from the url if not self._download_image(sFullFilename): # No download, so fall back to the 'no image' case self._oImage.set_from_icon_name( "image-missing", Gtk.IconSize.DIALOG) self._oImage.queue_draw() return else: if (self._oImagePlugin.DOWNLOAD_SUPPORTED and self._oImagePlugin.get_config_item(DOWNLOAD_IMAGES) and self._download_if_outdated(sFullFilename)): # Try download the image # We don't handle failure specially here - if it fails, # we will show the existing image self._download_image(sFullFilename) try: if self._bShowExpansions: self.oExpPrintLabel.set_markup( '<i>Image from expansion : </i> %s' % self._sCurExpPrint) self.oExpPrintLabel.show() iHeightOffset = self.oExpPrintLabel.get_allocation().height + 2 else: self.oExpPrintLabel.hide() # config changes can cause this iHeightOffset = 0 aPixbufs = [] iHeight = 0 iWidth = 0 for sFullFilename in aFullFilenames: oPixbuf = GdkPixbuf.Pixbuf.new_from_file(sFullFilename) iWidth = max(iWidth, oPixbuf.get_width()) iHeight = max(iHeight, oPixbuf.get_height()) aPixbufs.append(oPixbuf) if len(aPixbufs) > 1: # Create composite pixbuf oPixbuf = Gdk.Pixbuf(aPixbufs[0].get_colorspace(), aPixbufs[0].get_has_alpha(), aPixbufs[0].get_bits_per_sample(), (iWidth + 4) * len(aPixbufs) - 4, iHeight) oPixbuf.fill(0x00000000) # fill with transparent black iPos = 0 for oThisPixbuf in aPixbufs: # Scale all images to the same size oThisPixbuf.scale_simple(iWidth, iHeight, GdkPixbuf.InterpType.HYPER) # Add to the composite pixbuf oThisPixbuf.copy_area(0, 0, iWidth, iHeight, oPixbuf, iPos, 0) iPos += iWidth + 4 # Make iWidth the total width iWidth = (iWidth + 4) * len(aPixbufs) - 4 else: oPixbuf = aPixbufs[0] if self._iZoomMode == Size.FIT: # Need to fix aspect ratios iPaneHeight = (self._oView.get_vadjustment().get_page_size() - iHeightOffset) iPaneWidth = self._oView.get_hadjustment().get_page_size() # don't centre image under label self._oImage.set_alignment(0, 0.5) iDestWidth, iDestHeight = _scale_dims(iWidth, iHeight, iPaneWidth, iPaneHeight) if iDestWidth > 0 and iDestHeight > 0: self._oImage.set_from_pixbuf( oPixbuf.scale_simple(iDestWidth, iDestHeight, GdkPixbuf.InterpType.HYPER)) self._tPaneSize = ( self._oView.get_hadjustment().get_page_size(), self._oView.get_vadjustment().get_page_size()) elif self._iZoomMode == Size.VIEW_FIXED: iDestWidth, iDestHeight = _scale_dims(iWidth, iHeight, RATIO[0], RATIO[1]) self._oImage.set_from_pixbuf( oPixbuf.scale_simple(iDestWidth, iDestHeight, GdkPixbuf.InterpType.HYPER)) else: # Full size, so no scaling self._oImage.set_from_pixbuf(oPixbuf) except GObject.GError: self._oImage.set_from_icon_name("image-missing", Gtk.IconSize.DIALOG) self._oImage.queue_draw()