| | 271 | |
| | 272 | def OnScrollEvent(self, widget, event): |
| | 273 | if event.direction == gtk.gdk.SCROLL_UP: |
| | 274 | self.MakeZoomIn() |
| | 275 | else: |
| | 276 | self.MakeZoomOut() |
| | 277 | |
| | 278 | return True # Don't scroll the gtk.ScrolledWindow |
| | 279 | |
| | 280 | def MakeZoomIn(self): |
| | 281 | def CalcZoomIn(a): |
| | 282 | return a + a * self.actual_zoom / 100 + a * self.zoom_factor / 100 |
| | 283 | |
| | 284 | import gc |
| | 285 | |
| | 286 | if self.image is None or self.actual_zoom > 100: |
| | 287 | return |
| | 288 | |
| | 289 | x = self.image_pixbuf.get_width() |
| | 290 | y = self.image_pixbuf.get_height() |
| | 291 | |
| | 292 | self.actual_zoom += self.zoom_factor |
| | 293 | |
| | 294 | pixbuf_zoomed = self.image_pixbuf.scale_simple(CalcZoomIn(x), |
| | 295 | CalcZoomIn(y), |
| | 296 | gtk.gdk.INTERP_TILES) |
| | 297 | self.image.set_from_pixbuf(pixbuf_zoomed) |
| | 298 | |
| | 299 | del pixbuf_zoomed |
| | 300 | gc.collect() |
| | 302 | def MakeZoomOut(self): |
| | 303 | def CalcZoomOut(a): |
| | 304 | return a + a * self.actual_zoom / 100 - a * self.zoom_factor / 100 |
| | 305 | |
| | 306 | import gc |
| | 307 | |
| | 308 | if self.image is None: |
| | 309 | return |
| | 310 | |
| | 311 | x = self.image_pixbuf.get_width() |
| | 312 | y = self.image_pixbuf.get_height() |
| | 313 | |
| | 314 | self.actual_zoom -= self.zoom_factor |
| | 315 | |
| | 316 | if CalcZoomOut(x) < 10 or CalcZoomOut(y) < 10: |
| | 317 | self.actual_zoom += self.zoom_factor |
| | 318 | return |
| | 319 | |
| | 320 | pixbuf_zoomed = self.image_pixbuf.scale_simple(CalcZoomOut(x), |
| | 321 | CalcZoomOut(y), |
| | 322 | gtk.gdk.INTERP_TILES) |
| | 323 | self.image.set_from_pixbuf(pixbuf_zoomed) |
| | 324 | |
| | 325 | del pixbuf_zoomed |
| | 326 | gc.collect() |
| | 327 | |