def set_overlay_image(self, image): """ Scales and updates the overlay image on the ViewButton :param image: (wx.Image or None) Image to be displayed or a default stock image. """ if image: # image doesn't have the same aspect ratio as the actual thumbnail # => rescale and crop on the center scaled_img = wxImageScaleKeepRatio(image, self.thumbnail_size, wx.IMAGE_QUALITY_HIGH) else: # black image scaled_img = wx.EmptyImage(*self.thumbnail_size) self.thumbnail_bmp = wx.BitmapFromImage(scaled_img) self.Refresh()
def _update_22_thumbnail(self, _): """ Called when any thumbnail is changed, to recompute the 2x2 thumbnail of the first button :param _: (Image) Unused """ # Create an image from the 4 thumbnails in a 2x2 layout with small # border. The button without a viewport attached is assumed to be the # one assigned to the 2x2 view btn_all = [b for b, (vp, _) in self.buttons.items() if vp is None][0] border_width = 2 # px size = max(1, btn_all.thumbnail_size.x), max(1, btn_all.thumbnail_size.y) size_sub = (max(1, (size[0] - border_width) // 2), max(1, (size[1] - border_width) // 2)) # starts with an empty image with the border colour everywhere im_22 = wx.EmptyImage(*size, clear=False) im_22.SetRGBRect(wx.Rect(0, 0, *size), *btn_all.GetBackgroundColour().Get()) i = 0 for vp, _ in self.buttons.values(): if vp is None: # 2x2 layout continue im = vp.microscope_view.thumbnail.value if im: sim = img.wxImageScaleKeepRatio(im, size_sub, wx.IMAGE_QUALITY_HIGH) else: # Create an empty black image, if no image is set sim = wx.EmptyImage(*size_sub) # compute placement y, x = divmod(i, 2) # copy im in the right place im_22.Paste(sim, x * (size_sub[0] + border_width), y * (size_sub[1] + border_width)) i += 1 # set_overlay_image will rescale to the correct button size btn_all.set_overlay_image(im_22)
def _update_22_thumbnail(self, _): """ Called when any thumbnail is changed, to recompute the 2x2 thumbnail of the first button :param _: (Image) Unused """ # Create an image from the 4 thumbnails in a 2x2 layout with small # border. The button without a viewport attached is assumed to be the # one assigned to the 2x2 view btn_all = [b for b, (vp, _) in self.buttons.items() if vp is None][0] border_width = 2 # px size = max(1, btn_all.thumbnail_size.x), max(1, btn_all.thumbnail_size.y) size_sub = (max(1, (size[0] - border_width) // 2), max(1, (size[1] - border_width) // 2)) # starts with an empty image with the border colour everywhere im_22 = wx.Image(*size, clear=False) im_22.SetRGB(wx.Rect(0, 0, *size), *(btn_all.GetBackgroundColour().Get(includeAlpha=False))) i = 0 for vp, _ in self.buttons.values(): if vp is None: # 2x2 layout continue im = vp.view.thumbnail.value if im: sim = img.wxImageScaleKeepRatio(im, size_sub, wx.IMAGE_QUALITY_HIGH) else: # Create an empty black image, if no image is set sim = wx.Image(*size_sub) # compute placement y, x = divmod(i, 2) # copy im in the right place im_22.Paste(sim, x * (size_sub[0] + border_width), y * (size_sub[1] + border_width)) i += 1 # set_overlay_image will rescale to the correct button size btn_all.set_overlay_image(im_22)
def set_overlay_image(self, image): """ Scales and updates the overlay image on the ViewButton :param image: (wx.Image or None) Image to be displayed or a default stock image. """ if image: # image doesn't have the same aspect ratio as the actual thumbnail # => rescale and crop on the center scaled_img = wxImageScaleKeepRatio(image, self.thumbnail_size, wx.IMAGE_QUALITY_HIGH) else: # black image scaled_img = wx.Image(*self.thumbnail_size) self.thumbnail_bmp = wx.Bitmap(scaled_img) self.Refresh()