python - How can i import gtk.gdk from gi.repository -


i have python code takes screenshot of x screen.

#!/usr/bin/python import gtk.gdk  w = gtk.gdk.get_default_root_window() sz = w.get_size() print "the size of window %d x %d" % sz pb = gtk.gdk.pixbuf(gtk.gdk.colorspace_rgb,false,8,sz[0],sz[1]) pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1]) if (pb != none):     pb.save("screenshot.png","png")     print "screenshot saved screenshot.png." else:     print "unable screenshot." 

it works need import from gi.repository import gdk instead gtk.gdk. have tried following:

#!/usr/bin/python gi.repository import gtk, gdk, gdkpixbuf gi.repository.gdkpixbuf import pixbuf  w = gdk.get_default_root_window() sz = w.get_size() print "the size of window %d x %d" % sz pb = pixbuf(gdk.colorspace_rgb,false,8,sz[0],sz[1]) pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1]) if (pb != none):     pb.save("screenshot.png","png")     print "screenshot saved screenshot.png." else:     print "unable screenshot." 

but:

traceback (most recent call last):   file "./dsd", line 6, in <module>     sz = w.get_size() attributeerror: 'gtk.gdk.x11window' object has no attribute 'get_size' 

is there way use gi.repository script? thanks

edit: solved problem of attributeerror: 'gtk.gdk.x11window' object has no attribute 'get_size' using sz = w.get_geometry() instead get_size. new code:

#!/usr/bin/python gi.repository import gtk, gdk, gdkpixbuf  gi.repository.gdkpixbuf import pixbuf  w = gdk.get_default_root_window() sz = w.get_geometry() #print "the size of window %d x %d" % sz pb = gdkpixbuf.pixbuf.new(gdkpixbuf.colorspace.rgb,false,8,sz[2],sz[3]) pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[2],sz[3]) if (pb != none):     pb.save("screenshot.png","png")     print "screenshot saved screenshot.png." else:     print "unable screenshot." 

but having problem code:

traceback (most recent call last):   file "./dsd", line 9, in <module>     pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[2],sz[3]) attributeerror: 'pixbuf' object has no attribute 'get_from_drawable' 

how can use "get_from_drawable" attribute of pixbuf? again!

i know answer arrives bit late, better late never.

gdk3+ simplified process of retrieving pixbuf gdkwindow. thus, code should follows:

#!/usr/bin/python gi.repository import gdk, gdkpixbuf  w = gdk.get_default_root_window() sz = w.get_geometry()[2:4] #print "the size of window %d x %d" % sz pb = gdk.pixbuf_get_from_window(w, 0, 0, sz[0], sz[1]) if (pb != none):     pb.savev("screenshot.png","png", [], [])     print "screenshot saved screenshot.png." else:     print "unable screenshot." 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -