2013-08-09 7 views
0

그래서 저는 이미지를 생성하는 파이썬 스크립트를 가지고 있으며, 배경 이미지로 사용되었던 이전 이미지를 저장합니다. 유닉스는 데스크톱 배경을 바꿀 수 있습니다.

나는 그래서 지금 난 그냥 한 번 실행하는 bash는 스크립트를 가지고, 그것은 crontab를 사용하여 실행하도록했지만, 그 일을 가져올 수 없습니다 내 .bashrc 내가 먼저 로그인 whdn (나는 일의 if [ firstRun ] 종류가 그곳에).

문제는 때마다 백그라운드 업데이트가 실행되기 전에 검은 색으로 깜박입니다. 아주 좋지 않습니다!

나는 현재는 초에 한번씩 실행,하지만 나는 그것이 검은 화면을 일으키는 파이썬 생각하지 않으며,

는 방법은 이미지를 통해 변경되는 방식을 ... 거기에 더 I 업데이 트 사이에 이러한 못생긴 검은 화면을 방지 할 수 있습니까?

여기 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() 

및 ! 다음 그냥 실행/빈/SH

#을

while [ 1 ] 
do 
    python drawCubes.py 
sleep 1 
done 

그리고 cubes.png

답변

2

음으로 바탕 화면 이미지를 설정, 당신은, 당신은을 사용하고 당신이 MATE를 사용하는 경우

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") 
+0

배경에 현재 사용되고있는 파일을 변경하는 것보다 더 좋을 것이라고 생각하십니까? – will

+0

실제로 파일을 덮어 쓰는 것만으로도 최악의 방법 일 수 있습니다. 테스트되지 않은 gsettings를 사용하면 그림 사이에 부드러운 색조가 보일 확률이 훨씬 높아집니다. –

+0

그래, 나중에 이것이 사실일지도 모른다는 것을 깨달았습니다. 분명히 gsettings는 어떤 종류의 신호를 보낼 것입니다. 나는 그것을 시도 할 것이다. 건배. – will

1

를 실행하여 (그놈 3 호환 데스크탑) 현재 wallaper을 변경할 수 있습니다 Gnome 2.x의 포크. Gnome 2에서 찾은 방법은 gconftool-2 --set --type string --set /desktop/gnome/background/picture_filename <absolute image path>입니다.

이전에 시도한 방법은 Gnome Shell에서 작동했을 것입니다.

+0

불행히도 아직 작동하지 않습니다 ... – will

+0

정말 이상합니다 ... –

관련 문제