From 0e66d469670e44aa99558006e9e52ec3a6d0598e Mon Sep 17 00:00:00 2001 From: Adriano Grieb Date: Mon, 25 Jan 2016 12:45:00 -0200 Subject: [PATCH] Added multiple screenshot option. --- README.rst | 77 ++++++++++++++++++++++++++++++++---------------- escrotum/main.py | 46 +++++++++++++++++++++++------ 2 files changed, 89 insertions(+), 34 deletions(-) diff --git a/README.rst b/README.rst index 002983e..ffbe318 100644 --- a/README.rst +++ b/README.rst @@ -16,34 +16,61 @@ Features * window screenshot(click to select) * screenshot by xid * store the image to the clipboard +* make multiple screenshots (every x seconds) :: - Usage: escrotum [filename] - - Options: - -h, --help show this help message and exit - -v, --version output version information and exit - -s, --select interactively choose a window or rectangle with the mouse, - cancels with Esc or Rigth Click - -x XID, --xid=XID take a screenshot of the xid window - - -d DELAY, --delay=DELAY wait DELAY seconds before taking a shot - -c, --countdown show a countdown before taking the shot - -C, --clipboard store the image on the clipboard - SPECIAL STRINGS - filename parameters can take format specifiers - that are expanded by escrotum when encountered. - There are two types of format specifier. Characters preceded by a '%' - are interpretted by strftime(2). See man strftime for examples. - These options may be used to refer to the current date and time. - The second kind are internal to escrotum and are prefixed by '$' - The following specifiers are recognised: - $w image width - $h image height - Example: - escrotum '%Y-%m-%d_$wx$h_scrotum.png' - Creates a file called something like 2013-06-17-082335_263x738_escrotum.png + usage: escrotum [-h] [-v] [-s] [-x XID] [-d DELAY] + [--selection-delay SELECTION_DELAY] [-c] [-r REPEAT] [-k] [-C] + [-e COMMAND] + [FILENAME] + + Minimalist screenshot capture program inspired by scrot. + + positional arguments: + FILENAME image filename, default is + %Y-%m-%d-%H%M%S_$wx$h_escrotum.png + + optional arguments: + -h, --help show this help message and exit + -v, --version output version information and exit + -s, --select interactively choose a window or rectangle with the + mouse, cancels with Esc or Right Click + -x XID, --xid XID take a screenshot of the xid window + -d DELAY, --delay DELAY + wait DELAY seconds before taking a shot + --selection-delay SELECTION_DELAY + delay in milliseconds between selection/screenshot + -c, --countdown show a countdown before taking the shot (requires + delay) + -r REPEAT, --repeat REPEAT + number of screenshots to take, waiting DELAY each time + -C, --clipboard store the image on the clipboard + -e COMMAND, --exec COMMAND + run the command after the image is taken + + SPECIAL STRINGS + Both the --exec and filename parameters can take format specifiers + that are expanded by escrotum when encountered. + + There are two types of format specifier. Characters preceded by a '%' + are interpreted by strftime(2). See man strftime for examples. + These options may be used to refer to the current date and time. + + The second kind are internal to escrotum and are prefixed by '$' + The following specifiers are recognised: + $f image path/filename (ignored when used in the filename) + $w image width + $h image height + Example: + escrotum '%Y-%m-%d_$wx$h_escrotum.png' + Creates a file called something like 2013-06-17-082335_263x738_escrotum.png + + EXIT STATUS CODES + 1 can't get the window by xid + 2 invalid pixbuf + 3 can't save the image + 4 user canceled selection Install ------- diff --git a/escrotum/main.py b/escrotum/main.py index ee27cbd..81bee58 100755 --- a/escrotum/main.py +++ b/escrotum/main.py @@ -24,7 +24,7 @@ class Escrotum(gtk.Window): def __init__(self, filename=None, selection=False, xid=None, delay=None, selection_delay=250, countdown=False, use_clipboard=False, - command=None): + command=None, repeat=False): super(Escrotum, self).__init__(gtk.WINDOW_POPUP) self.started = False @@ -49,6 +49,14 @@ def __init__(self, filename=None, selection=False, xid=None, delay=None, self.xid = xid self.countdown = countdown + if repeat: + if not delay: + print "--delay is needed for --repeat" + exit() + self.repeat = repeat + self.repeat_delay = delay + else: self.repeat = None + if not xid: self.root = gtk.gdk.get_default_root_window() else: @@ -69,6 +77,7 @@ def __init__(self, filename=None, selection=False, xid=None, delay=None, if countdown: sys.stdout.write("Taking shot in ..%s" % delay) sys.stdout.flush() + self.delay -= 1 gobject.timeout_add(1000, self.start) else: self.start() @@ -227,6 +236,14 @@ def wait(): gobject.timeout_add(10, wait) def screenshot(self): + if self.repeat: + self.repeat -= 1 + self.do_screenshot() + gobject.timeout_add(1000 * self.repeat_delay, self.do_screenshot) + else: + self.do_screenshot() + + def do_screenshot(self): """ Capture the screenshot based on the window size or the selected window """ @@ -269,6 +286,12 @@ def screenshot(self): else: self.save_file(pb, width, height) + if self.repeat: + self.repeat -= 1 + return True + else: + return False + def get_geometry(self): monitors = self.screen.get_n_monitors() return [self.screen.get_monitor_geometry(m) for m in range(monitors)] @@ -352,24 +375,26 @@ def save_file(self, pb, width, height): if not self.filename: self.filename = "%Y-%m-%d-%H%M%S_$wx$h_escrotum.png" - self.filename = self._expand_argument(width, height, self.filename) + filename = self._expand_argument(width, height, self.filename) filetype = "png" - if "." in self.filename: - filetype = self.filename.rsplit(".", 1)[1] + if "." in filename: + filetype = filename.rsplit(".", 1)[1] try: - pb.save(self.filename, filetype) - print self.filename + pb.save(filename, filetype) + print filename except Exception, error: print error exit(EXIT_CANT_SAVE_IMAGE) if self.command: - command = self.command.replace("$f", self.filename) + command = self.command.replace("$f", filename) command = self._expand_argument(width, height, command) subprocess.call(command, shell=True) - exit() + + if not self.repeat: + exit() def set_rect_size(self, event): """ @@ -447,6 +472,9 @@ def get_options(): parser.add_argument( '-c', '--countdown', default=False, action="store_true", help='show a countdown before taking the shot (requires delay)') + parser.add_argument( + '-r', '--repeat', default=False, type=int, + help='number of screenshots to take, waiting DELAY each time') parser.add_argument( '-C', '--clipboard', default=False, action="store_true", help='store the image on the clipboard') @@ -478,7 +506,7 @@ def run(): Escrotum(filename=args.FILENAME, selection=args.select, xid=args.xid, delay=args.delay, selection_delay=args.selection_delay, countdown=args.countdown, use_clipboard=args.clipboard, - command=args.command) + repeat=args.repeat, command=args.command) try: gtk.main()