0

Like the title says, I'd like to slurp in the entire 1920x1080 background wallpaper image into a readable object regardless of what windows, panels, launchers, etc. may currently be on top of it.

Python, because I like it, but I'll take what I can get. I can do C/C++. I'd rather not do Java. Please, not java. This is a small utility, not a weapons-grade application.

Why, you ask?

I want to look at a couple 100 or so random pixels from the image, try to find a common colour, then manipulate the current gtk3 theme's CSS file to change @dark_bg_color to my calculated colour, and then, somehow, reload the theme.

The final result will be that when the wallpaper changes, windows' title bar colours will change to "match".

I'm pretty sure I can do everything except step 1... getting the current wallpaper into a readable object. There are plenty of tutorials on how to change/set the wallpaper, but not much on getting it.

Whoa, you say! You don't KNOW what your desktop wallpaper is? No. I use variety and it's always downloading new wallpapers AND using my personal collection, randomly changing it every 10 minutes or so.

  • If your problem has been solved, mark the answer as accepted. Please do not add "solved", etc. to the title. – muru May 29 '16 at 19:01
1

This should do it:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import random
from PIL import Image
from gi.repository import Gio

def get_wallpaper_uri():
    settings = Gio.Settings.new("org.gnome.desktop.background")
    uri = settings.get_string("picture-uri")
    return uri

def uri_to_path(uri):
    return uri.lstrip("file:")

def get_random_coordinates(x_max, y_max, num):
    x_values = random.sample(range(x_max), num)
    y_values = random.sample(range(y_max), num)
    return zip(x_values, y_values)

def main():
    uri = get_wallpaper_uri()
    path = uri_to_path(uri)
    image = Image.open(path)
    width, height = image.size
    coordinates = get_random_coordinates(width, height, 10)
    pixels = image.load()
    for coordinate in coordinates:
        pixel_value = pixels[coordinate]
        print(pixel_value)

if __name__ == "__main__":
    main()
0

@Timo above described the way of getting it in GNOME and Unity, here is how in Xfce.

import subprocess

xfce_wall_cmd = subprocess.Popen('xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/workspace0/last-image', shell=True, stdout=subprocess.PIPE)

xfce_wall, xfce_wall_errs = xfce_wall_cmd.communicate()

xfce_wall = xfce_wall.decode('utf-8').replace('\n', '')

print(xfce_wall)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.