mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-08-03 09:44:28 +02:00
wallpaper: also provide symlinks to the used images
Useful if something want a random wallpaper.
This commit is contained in:
parent
01d65673ca
commit
ebf43cbbc5
1 changed files with 14 additions and 5 deletions
|
@ -19,9 +19,9 @@ import Image
|
||||||
|
|
||||||
parser = optparse.OptionParser()
|
parser = optparse.OptionParser()
|
||||||
parser.add_option("-d", "--directory", dest="directory", default=".",
|
parser.add_option("-d", "--directory", dest="directory", default=".",
|
||||||
help="search for images in DIRECTORY", metavar="DIRECTORY")
|
help="search for images in DIRECTORY", metavar="DIRECTORY")
|
||||||
parser.add_option("-t", "--target", dest="target", default="background.jpg",
|
parser.add_option("-t", "--target", dest="target", default="background.jpg",
|
||||||
help="write background to FILE", metavar="FILE")
|
help="write background to FILE", metavar="FILE")
|
||||||
parser.add_option("-c", "--crop", dest="crop", action="store_true",
|
parser.add_option("-c", "--crop", dest="crop", action="store_true",
|
||||||
help="crop image instead of centering them")
|
help="crop image instead of centering them")
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
|
@ -57,8 +57,16 @@ for root, _, files in os.walk(os.path.join(options.directory)):
|
||||||
images.append(os.path.join(root, i))
|
images.append(os.path.join(root, i))
|
||||||
images = random.sample(images, len(screens))
|
images = random.sample(images, len(screens))
|
||||||
images = [Image.open(image) for image in images]
|
images = [Image.open(image) for image in images]
|
||||||
print "wallpaper: %s" % " + ".join(["`%s`" % x.filename[(len(options.directory) + 1):]
|
print("wallpaper: {}".format(" + ".join(
|
||||||
for x in images])
|
["`%s`" % x.filename[(len(options.directory) + 1):]
|
||||||
|
for x in images])))
|
||||||
|
|
||||||
|
# Link chosen wallpapers
|
||||||
|
for idx, image in enumerate(images):
|
||||||
|
target = "{}.{}".format(options.target, idx)
|
||||||
|
if os.path.lexists(target):
|
||||||
|
os.remove(target)
|
||||||
|
os.symlink(os.path.abspath(image.filename), target)
|
||||||
|
|
||||||
for index in range(len(screens)):
|
for index in range(len(screens)):
|
||||||
x, y, offsetx, offsety = screens[index]
|
x, y, offsetx, offsety = screens[index]
|
||||||
|
@ -82,7 +90,8 @@ for index in range(len(screens)):
|
||||||
|
|
||||||
# Save
|
# Save
|
||||||
assert background, "Don't know the size of the display area"
|
assert background, "Don't know the size of the display area"
|
||||||
with tempfile.NamedTemporaryFile(delete=False,
|
with tempfile.NamedTemporaryFile(
|
||||||
|
delete=False,
|
||||||
dir=os.path.dirname(os.path.realpath(options.target))) as tmp:
|
dir=os.path.dirname(os.path.realpath(options.target))) as tmp:
|
||||||
background.save(tmp, "png")
|
background.save(tmp, "png")
|
||||||
os.rename(tmp.name, options.target)
|
os.rename(tmp.name, options.target)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue