ZoomPanView initial size
Hi pythoneestas and prob mostly @mikael
I have a ZoomPanView that has an arbitrary number of images inside it.
I would like the view to initially when first built to fit entirely inside the screen
ie the view is much larger than this as it contains many other images.
I can’t find a way of scaling it such that it’s already “zoomed out” and shows all its contents as it would be if it was “touch zoomed out”.
It always gets built just showing the top left portion of the first image in its contents.
I’ve tried .scale .start_scale etc and no luck.
mikael last edited by mikael
@rb, I guess you are talking about the ZoomPanView that comes with pygestures.
If so, yes, it does not really expose the functionality you need in a convenient way, but see below, does this do what you were after?
import ui from pygestures import ZoomPanView class ZoomedOutView(ZoomPanView): def zoom_to_fit(self): bbox = ui.Rect(0,0,1,1) zoomer = self.zoomer for view in zoomer.subviews: bbox = bbox.union(view.frame) self.scale = min( self.width/bbox.width, self.height/bbox.height, ) self._set_transforms() zoomer.x = zoomer.y = 0 def layout(self): self.zoom_to_fit() z = ZoomedOutView() images = ( ('test:Boat', 'test:Bridge', 'test:Gray21'), ('test:Lenna', 'test:Mandrill', 'test:Numbers'), ('test:Pattern', 'test:Peppers', 'test:Sailboat') ) max_y = 0 for row in images: current_x = 0 current_y = max_y for image in row: img = ui.Image(image) iv = ui.ImageView(image=img, x=current_x, y=current_y, width=img.size.w, height=img.size.h ) z.add_subview(iv) current_x = iv.frame.max_x max_y = max(max_y, iv.frame.max_y) z.present('fullscreen', animated=False)
@mikael thanks for replying - this almost does exactly what I’m after yes but it appears to disable any subsequent zooming after the view is initially built.
I’d like the functionality of the zoom /pan as normal after the initial placement ideally.
I will try and work out how to re-enable that from your code though - thanks again!
mikael last edited by
@rb, true, the layout is ”too aggressive”. You can quick-fix it with something like this:
first = True def layout(self): if self.first: self.zoom_to_fit() self.first = False
first = True
self.first = False
Perfect exactly what I’m after thankyou Mikel :)