Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added multiple screenshot option. #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 52 additions & 25 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
46 changes: 37 additions & 9 deletions escrotum/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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()
Expand Down Expand Up @@ -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
"""
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand Down