所以我有一个生成图像的python脚本,并保存过去曾经是背景图像的旧图像。
我试图让它使用crontab
运行,但无法使其工作,所以现在我只有一个bash脚本在我的.bashrc
whdn中运行一次我首次登录(i那里有if [ firstRun ]
种东西。)
问题是,不时地,当背景更新时,它会在它之前闪烁黑色 - 这不是很好!
我目前每秒运行一次,但我认为这不是导致黑屏的python,而是图像更改的方式......
有没有办法可以在更新之间阻止这些丑陋的黑屏?
以下是运行它的所有代码,如果你想尝试一下......
来自PIL import Image,ImageDraw,ImageFilter 导入colorsys 来自随机进口高斯
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()
然后运行:
#!/ bin / sh的
while [ 1 ]
do
python drawCubes.py
sleep 1
done
并将桌面图像设置为cubes.png
答案 0 :(得分:2)
嗯,您可以通过运行
更改当前壁纸(在Gnome 3兼容桌面中)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")
答案 1 :(得分:1)
如果您正在使用MATE,那么您正在使用Gnome 2.x的分支。我在Gnome 2中找到的方法是:gconftool-2 --set --type string --set /desktop/gnome/background/picture_filename <absolute image path>
。
我们之前尝试过的方法可以在Gnome Shell中使用。