Ok, so this isn't necessarily a programming issue, but anyways. I've
managed to write that random wallpaper changer i've been wanting to
make, but i've run into a little problem. According to the MS
Knowledge Base, SystemParameter sInfo() can't take a .jpg file as an
argument when changing the wallpaper (it doesn't work, i've tried it),
only .bmps so i'm stuck converting one of my many wallpapers from .jpg
to .bmp, passing that to SystemParameter sInfo(), and deleting the
previous .bmp so that i don't have any duplicates. The problem with
this is that other members of my family use this computer too, and
they sometimes set the desktop wallpaper to some other, usually funny
picture they've got stored on the HD, and when I run this little
script it'll delete whatever the current wallpaper is, regardless of
whether its one of mine or not. Any suggestions on how to work around
this problem?
#random wallpaper changer!
import win32gui #use this to change the wallpaper.
import os
import os.path
import random
import Image
SPI_SETDESKWALL PAPER = 20 #It took me WAY too long to find them.
SPI_GETDESKWALL PAPER = 115 #I should keep these handy.
def RandomlySelectW allpaper(filePa ths):
CurrentWallpape r =
win32gui.System ParametersInfo( SPI_GETDESKWALL PAPER)
while True:
index = random.randint( 0,len(filePaths )-1)
RandomlySelecte dWallpaper = filePaths[index]
if RandomlySelecte dWallpaper <CurrentWallpap er:
break
print RandomlySelecte dWallpaper
return RandomlySelecte dWallpaper #it should be a string...
def ChangeDesktopWa llpaper(Randoml ySelectedWallpa per):
#so the RIGHT way to do this would be to use
#win32gui.Syste mParametersInfo () to change the wallpaper.
#1) we convert the image to .bmp.
#Delete the old wallpaper, actual delete occurs after new
wallpaper has been set.
pathToCurrentWa ll =
win32gui.System ParametersInfo( SPI_GETDESKWALL PAPER)
root,extension = os.path.splitex t(RandomlySelec tedWallpaper)
newFileName = root + '.bmp'
print "Wallpaper to delete: ", pathToCurrentWa ll
try:
#every so often something goes wrong at this stage in the
script
#and I can't figure out what. Something raises an IOError.
Image.open(Rand omlySelectedWal lpaper).save(ne wFileName)
print "File saved!"
except IOError:
print "Error while converting, please check filepath and
permissions."
print "Program will restart in an attempt to generate a
correct wallpaper."
Main()
win32gui.System ParametersInfo( SPI_SETDESKWALL PAPER,newFileNa me,
1+2)
print "Removing: ", pathToCurrentWa ll
os.remove(pathT oCurrentWall)
def Main():
#woot.
listOfWallpaper Paths = GenerateListOfW allpapers()
RandomlySelecte dWall =
RandomlySelectW allpaper(listOf WallpaperPaths)
ChangeDesktopWa llpaper(Randoml ySelectedWall)
Main()
managed to write that random wallpaper changer i've been wanting to
make, but i've run into a little problem. According to the MS
Knowledge Base, SystemParameter sInfo() can't take a .jpg file as an
argument when changing the wallpaper (it doesn't work, i've tried it),
only .bmps so i'm stuck converting one of my many wallpapers from .jpg
to .bmp, passing that to SystemParameter sInfo(), and deleting the
previous .bmp so that i don't have any duplicates. The problem with
this is that other members of my family use this computer too, and
they sometimes set the desktop wallpaper to some other, usually funny
picture they've got stored on the HD, and when I run this little
script it'll delete whatever the current wallpaper is, regardless of
whether its one of mine or not. Any suggestions on how to work around
this problem?
#random wallpaper changer!
import win32gui #use this to change the wallpaper.
import os
import os.path
import random
import Image
SPI_SETDESKWALL PAPER = 20 #It took me WAY too long to find them.
SPI_GETDESKWALL PAPER = 115 #I should keep these handy.
def RandomlySelectW allpaper(filePa ths):
CurrentWallpape r =
win32gui.System ParametersInfo( SPI_GETDESKWALL PAPER)
while True:
index = random.randint( 0,len(filePaths )-1)
RandomlySelecte dWallpaper = filePaths[index]
if RandomlySelecte dWallpaper <CurrentWallpap er:
break
print RandomlySelecte dWallpaper
return RandomlySelecte dWallpaper #it should be a string...
def ChangeDesktopWa llpaper(Randoml ySelectedWallpa per):
#so the RIGHT way to do this would be to use
#win32gui.Syste mParametersInfo () to change the wallpaper.
#1) we convert the image to .bmp.
#Delete the old wallpaper, actual delete occurs after new
wallpaper has been set.
pathToCurrentWa ll =
win32gui.System ParametersInfo( SPI_GETDESKWALL PAPER)
root,extension = os.path.splitex t(RandomlySelec tedWallpaper)
newFileName = root + '.bmp'
print "Wallpaper to delete: ", pathToCurrentWa ll
try:
#every so often something goes wrong at this stage in the
script
#and I can't figure out what. Something raises an IOError.
Image.open(Rand omlySelectedWal lpaper).save(ne wFileName)
print "File saved!"
except IOError:
print "Error while converting, please check filepath and
permissions."
print "Program will restart in an attempt to generate a
correct wallpaper."
Main()
win32gui.System ParametersInfo( SPI_SETDESKWALL PAPER,newFileNa me,
1+2)
print "Removing: ", pathToCurrentWa ll
os.remove(pathT oCurrentWall)
def Main():
#woot.
listOfWallpaper Paths = GenerateListOfW allpapers()
RandomlySelecte dWall =
RandomlySelectW allpaper(listOf WallpaperPaths)
ChangeDesktopWa llpaper(Randoml ySelectedWall)
Main()
Comment