PDA

View Full Version : [Python] Random desktop background chooser



bobng
05-25-2009, 09:21 PM
Windows only.
Run this at startup and it chooses a random desktop background from a folder. Allows you to cycle through them as well if you dont like the one chosen.

Needs:
-Python 2.5.4
-PIL (for the converter script only) = http://effbot.org/downloads/PIL-1.1.6.win32-py2.5.exe
-A brain

Also here is a converter script to convert all image files to jpeg, so they can be set as the background:
# Some help from http://www.velocityreviews.com/forums/t339757-convert-all-images-to-jpeg.html

# Input folder
path = 'C:\Users\Tom\Pictures\Images'
# Output folder
opath = 'C:\Users\Tom\Pictures\jpgs'

import glob
import Image
import os

file_list = glob.glob(path+'\*.*')

for image in file_list:
try:
out_path = os.path.split(image)[1].split('.')[0]
Image.open(image).convert('RGB').save(opath+'\\'+o ut_path+'.jpg','JPEG')
print 'Converting to '+opath+'\\'+out_path+'.jpg'
except Exception,e:
print e
Here is the changer code:
# Change the desktop background to something random
import ctypes
import sys
import glob
import random

path = r'C:\Users\Tom\Pictures\jpgs'

silent = False

# Change the shit
def set_wallpaper():
files = glob.glob(path+'\*.jpg')
choice = random.choice(files)
if not silent:
print 'File %s chosen'%choice
cs = ctypes.c_buffer(choice)
b = ctypes.windll.user32.SystemParametersInfoA(20 ,1, cs, 1)

set_wallpaper()

if not silent:
print 'Enter "1" to cycle through backgrounds'
if not raw_input() == "1":
sys.exit()
print 'Press enter to change it again'
while True:
raw_input()
set_wallpaper()

Dynamite
05-25-2009, 09:25 PM
Nice :)
Cheers for making and sharing.

T~M

Daniel
06-19-2009, 05:28 PM
Windows 7 already has this feature ;)

Mr.Klean
06-21-2009, 04:42 AM
XP Powertoys are fun. Anyways looks nice, although I am not trying it as I already have it handled.

ShowerThoughts
06-21-2009, 04:51 AM
Windows 7 copy cats everything, and gives developers no job, bad times, bad times...

Atm, you made some nice code, I am about to maybe, might, could, might, maybe, learn python too for a game server xD.

Btw, I made a wallpaper changer in the past too. with GUI :D.