Ticket #160: userinfo.py.diff

File userinfo.py.diff, 2.6 kB (added by Sergio Perticone, 19 months ago)
  • userinfo.py

    old new  
    8888                self.user = user 
    8989                self.conn = conn 
    9090                self._descr = "" 
     91                self.image_pixbuf = None 
     92                self.zoom_factor = 5 
     93                self.actual_zoom = 0 
    9194                 
    9295                self.hatesStore = gtk.ListStore(gobject.TYPE_STRING) 
    9396                self.Hates.set_model(self.hatesStore) 
     
    201204                                loader = gtk.gdk.PixbufLoader() 
    202205                                loader.write(pic) 
    203206                                loader.close() 
    204                                 self.image.set_from_pixbuf(loader.get_pixbuf()) 
     207                                self.image_pixbuf = loader.get_pixbuf() 
     208                                self.image.set_from_pixbuf(self.image_pixbuf) 
    205209                                del pic, loader 
    206210                                gc.collect() 
    207211 
     212                                self.actual_zoom = 0 
     213 
    208214                        except TypeError, e: 
    209215                                name = tempfile.mktemp() 
    210216                                f = open(name,"w") 
     
    259265        def OnSavePicture(self, widget): 
    260266                if self.image is None: 
    261267                        return 
    262                 pixbuf = self.image.get_pixbuf() 
    263268                name = os.path.join(self.frame.np.config.sections["transfers"]["downloaddir"],self.encode(self.user)) + ".jpg" 
    264                 pixbuf.save(name, "jpeg", {"quality": "100"}) 
     269                self.image_pixbuf.save(name, "jpeg", {"quality": "100"}) 
    265270                self.frame.logMessage("Picture saved to " + name) 
     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() 
    266301                 
     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         
    267328        def encode(self, path): 
    268329                try: 
    269330                        if sys.platform == "win32":