Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gtk.gdk
- import os
- import time
- basedir = os.path.join(os.path.expanduser("~"), "screenguard")
- timeformat = '%d.%m.%Y %H:%M:%S'
- if not os.path.exists(basedir):
- os.mkdir(basedir)
- collect_size = 50
- collect_index = 0
- oldsec = time.localtime().tm_sec
- print time.localtime().tm_sec
- #feststellen, wo aufgehoert: dort weitermachen
- collect_index = 0 #begin after the last file
- while 1:
- if os.path.exists(os.path.join(basedir, "screenshot%04d.png" % collect_index)):
- collect_index += 1
- else:
- break
- #option: destination path
- while 1:
- w = gtk.gdk.get_default_root_window()
- sz = w.get_size()
- print sz
- print "The size of the window is %d x %d" % sz
- pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,1280,sz[1])
- pb = pb.get_from_drawable(w,w.get_colormap(),1280,0,0,0,1280,sz[1])
- newfilename = os.path.join(basedir, "screenshot%04d.png" % collect_index)
- if os.path.exists(newfilename): #delete old file before
- os.remove(newfilename)
- if (pb != None):
- pb.save(newfilename, "png") # option for file format # hier erst exension dazu (optparse)
- #pb.save(newfilename, "jpeg", {"quality":"40"}) #bringt eh nicht viel
- print "Screenshot saved to %s" % newfilename
- else:
- print "Unable to get the screenshot.", time.strftime(timeformat)
- collect_index += 1
- if collect_index >= collect_size:
- collect_index = 0
- while 1: #print one sreenshot each second
- if time.localtime().tm_sec != oldsec:
- break
- else:
- time.sleep(0.1) #give time for other things
- oldsec = time.localtime().tm_sec
- print time.localtime().tm_sec
- #todo keypress event: "q" oder "Q" oder "x" oder "X" => abbruch
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement