4
Background Context Extractor commandline tool, automatic version for GNOME
6
Automatically takes one screenshot with white, and one with shadow-color
7
(usually black), background. Puts out a PNG image with transparent desktop.
9
This is usefull for evaluationg wallpapers that should go well with panels
10
and themes other than the one you are currently using.
12
Based on a bash script by Sergey Davidoff
14
Copyright 2010, 2011 Thorsten Wilms, Sergey Davidoff
15
License: GPLv3, see docs/COPYING
17
This program is free software: you can redistribute it and/or modify it under
18
the terms of the GNU General Public License as published by the Free Software
19
Foundation, either version 3 of the License, or (at your option) any later
22
This program is distributed in the hope that it will be useful, but WITHOUT
23
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
24
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
26
You should have received a copy of the GNU General Public License
27
along with this program. If not, see <http://www.gnu.org/licenses/>.
30
import argparse # Added with Python 2.7, not present in 3.0 but back in 3.2
32
from os.path import isdir, exists
33
from sys import stdout, stderr, exit
34
from time import sleep
36
from subprocess import call
39
from backtestground.cli_input import try_parse
40
import backtestground.extract_background_context as extract_background_context
44
"""Run program and handle command line options"""
46
# Default output filename
47
filename = "context.png"
48
help_text = """destination directory or filename. \".png\" will be appended
49
to given filename, if missing. Defaults to %s.""" % filename
52
parser = argparse.ArgumentParser(description="""Create image with
53
transparent desktop from 2 screenshots with white and shadow-color
54
(usually black) desktops.""")
55
parser.add_argument('-v', '--version',
57
version='%(prog)s 1.3',
58
help="print program version")
59
parser.add_argument('-o',
60
# no type=file, as that would require
61
# the file to exist beforehand.
63
metavar='path/filename',
66
parser.add_argument('-f', '--force',
69
help="""overwrite existing files,
70
do not creat a backup.""")
72
# Catch IOErrors to put out a _short_ error message
73
args = try_parse(parser)
75
# Special care for 'output'
76
if isdir(args.output):
77
# args.output specifies a directory, so append the default filename.
78
output = ''.join([args.output, "/", filename])
80
# args.output specifies a file,
81
# so make sure the name ends with ".png" (or ".PNG").
82
if args.output.endswith(".png") or args.output.endswith(".PNG"):
85
output = ''.join([args.output, ".png"])
88
client = gconf.client_get_default()
90
stderr.write("Can't access gconf. Maybe not running from within a GNOME session?\n")
94
stdout.write("Taking screenshots in 3 seconds\n")
96
for i in range(3, 0, -1):
97
stdout.write(''.join([str(i), "\n"]))
101
gconfs = ('/desktop/gnome/background/picture_filename',
102
'/desktop/gnome/background/color_shading_type',
103
'/desktop/gnome/background/primary_color')
105
# Save initial settings
106
before = map(client.get_string, gconfs)
108
# Find unused filenames
112
name = ''.join([name, str(n), '.png'])
113
if not exists(name): break
118
filename_seeds = ('on_white', 'on_black')
119
files = map(unused, filename_seeds)
121
# Switch to no-picture/solid/white, wait for transition,
123
values = ('', 'solid', '#ffffffffffff')
124
map(client.set_string, gconfs, values)
126
call("import -window root %s" % files[0], shell=True)
128
# Switch to black, wait for transition, take screenshot
129
client.set_string(gconfs[2], '#000000000000')
131
call("import -window root %s" % files[1], shell=True)
134
map(client.set_string, gconfs, before)
137
extract_background_context.extract(files[0], files[1],
138
output, args.overwrite)
144
if __name__ == '__main__':