Reputation: 10650
So i have a python script which generates an image, and saves over the old image which used to be the background image.
I tried to make it run using crontab
, but couldn't get that to work, so now i just have a bash script which runs once in my .bashrc
whdn i first log in (i have a if [ firstRun ]
kind of thing in there).
The problem is, that every now and then, when the background updates, it flashes black before it does - which is not very nice!
I currently have it running once a second, but i don't think it's the python that is causing the black screens, and more the way the image is changed over...
Is there a way I can prevent these ugly black screens between updates?
Here's all the code to run it, if you want to try it out...
from PIL import Image, ImageDraw, ImageFilter import colorsys from random import gauss
xSize, ySize = 1600,900
im = Image.new('RGBA', (xSize, ySize), (0, 0, 0, 0))
draw = ImageDraw.Draw(im)
class Cube(object):
def __init__(self):
self.tl = (0,0)
self.tm = (0,0)
self.tr = (0,0)
self.tb = (0,0)
self.bl = (0,0)
self.bm = (0,0)
self.br = (0,0)
def intify(self):
for prop in [self.tl, self.tm, self.tr, self.tb, self.bl, self.bm, self.br]:
prop = [int(i) for i in prop]
def drawCube((x,y), size, colour=(255,0,0)):
p = Cube()
colours = [list(colorsys.rgb_to_hls(*[c/255.0 for c in colour])) for _ in range(3)]
colours[0][1] -= 0
colours[1][1] -= 0.2
colours[2][1] -= 0.4
colours = [tuple([int(i*255) for i in colorsys.hls_to_rgb(*colour)]) for colour in colours]
p.tl = x,y #Top Left
p.tm = x+size/2, y-size/4 #Top Middle
p.tr = x+size, y #Top Right
p.tb = x+size/2, y+size/4 #Top Bottom
p.bl = x, y+size/2 #Bottom Left
p.bm = x+size/2, y+size*3/4 #Bottom Middle
p.br = x+size, y+size/2 #Bottom Right
p.intify()
draw.polygon((p.tl, p.tm, p.tr, p.tb), fill=colours[0])
draw.polygon((p.tl, p.bl, p.bm, p.tb), fill=colours[1])
draw.polygon((p.tb, p.tr, p.br, p.bm), fill=colours[2])
lineColour = (0,0,0)
lineThickness = 2
draw.line((p.tl, p.tm), fill=lineColour, width=lineThickness)
draw.line((p.tl, p.tb), fill=lineColour, width=lineThickness)
draw.line((p.tm, p.tr), fill=lineColour, width=lineThickness)
draw.line((p.tb, p.tr), fill=lineColour, width=lineThickness)
draw.line((p.tl, p.bl), fill=lineColour, width=lineThickness)
draw.line((p.tb, p.bm), fill=lineColour, width=lineThickness)
draw.line((p.tr, p.br), fill=lineColour, width=lineThickness)
draw.line((p.bl, p.bm), fill=lineColour, width=lineThickness)
draw.line((p.bm, p.br), fill=lineColour, width=lineThickness)
# -------- Actually do the drawing
size = 100
#Read in file of all colours, and random walk them
with open("/home/will/Documents/python/cubeWall/oldColours.dat") as coloursFile:
for line in coloursFile:
oldColours = [int(i) for i in line.split()]
oldColours = [int(round(c + gauss(0,1.5)))%255 for c in oldColours]
colours = [[ int(c*255) for c in colorsys.hsv_to_rgb(i/255.0, 1, 1)] for i in oldColours]
with open("/home/will/Documents/python/cubeWall/oldColours.dat", "w") as coloursFile:
coloursFile.write(" ".join([str(i) for i in oldColours]) + "\n")
for i in range(xSize/size+2):
for j in range(2*ySize/size+2):
if j%3 == 0:
drawCube((i*size,j*size/2), size, colour=colours[(i+j)%3])
elif j%3 == 1:
drawCube(((i-0.5)*size,(0.5*j+0.25)*size), size, colour=colours[(i+j)%3])
im2 = im.filter(ImageFilter.SMOOTH)
im2.save("cubes.png")
#im2.show()
and then just run this:
#!/bin/sh
while [ 1 ]
do
python drawCubes.py
sleep 1
done
And set the desktop image to be cubes.png
Upvotes: 0
Views: 278
Reputation: 11399
If you're using MATE, you're using a fork of Gnome 2.x. The method I found for Gnome 2 is : gconftool-2 --set --type string --set /desktop/gnome/background/picture_filename <absolute image path>
.
The method we tried before would have worked in Gnome Shell.
Upvotes: 1
Reputation: 11399
Well, you can change the current wallaper (in Gnome 3 compatible desktops) by running
import os
os.system("gsettings set org.gnome.desktop.background picture-uri file://%(path)s" % {'path':absolute_path})
os.system("gsettings set org.gnome.desktop.background picture-options wallpaper")
Upvotes: 2