Unix可以无缝地更改桌面背景



所以我有一个python脚本,它生成一个图像,并保存在过去作为背景图像的旧图像上。

我试着让它使用crontab运行,但无法实现,所以现在我只有一个bash脚本,它在我第一次登录时在我的.bashrc中运行一次(我有一个if [ firstRun ]之类的东西)。

问题是,当背景不时更新时,它会在更新之前闪烁黑色——这不是很好!

我目前每秒运行一次,但我不认为是蟒蛇导致了黑屏,更重要的是图像的变化方式。。。

有没有办法在更新之间防止这些丑陋的黑屏?

如果你想尝试一下,下面是运行它的所有代码。。。

从PIL导入图像,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

好吧,你可以通过运行来更改当前的壁纸(在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")

如果您使用MATE,那么您使用的是Gnome 2.x的分叉。我为Gnome 2找到的方法是:gconftool-2 --set --type string --set /desktop/gnome/background/picture_filename <absolute image path>

我们之前尝试过的方法在Gnome Shell中会起作用。

最新更新