473,327 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

The wrong approach to things

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, SystemParametersInfo() 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 SystemParametersInfo(), 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_SETDESKWALLPAPER = 20 #It took me WAY too long to find them.
SPI_GETDESKWALLPAPER = 115 #I should keep these handy.

def RandomlySelectWallpaper(filePaths):
CurrentWallpaper =
win32gui.SystemParametersInfo(SPI_GETDESKWALLPAPER )
while True:
index = random.randint(0,len(filePaths)-1)
RandomlySelectedWallpaper = filePaths[index]
if RandomlySelectedWallpaper <CurrentWallpaper:
break
print RandomlySelectedWallpaper
return RandomlySelectedWallpaper #it should be a string...

def ChangeDesktopWallpaper(RandomlySelectedWallpaper):
#so the RIGHT way to do this would be to use
#win32gui.SystemParametersInfo() to change the wallpaper.
#1) we convert the image to .bmp.
#Delete the old wallpaper, actual delete occurs after new
wallpaper has been set.
pathToCurrentWall =
win32gui.SystemParametersInfo(SPI_GETDESKWALLPAPER )
root,extension = os.path.splitext(RandomlySelectedWallpaper)
newFileName = root + '.bmp'
print "Wallpaper to delete: ", pathToCurrentWall
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(RandomlySelectedWallpaper).save(newFile Name)
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.SystemParametersInfo(SPI_SETDESKWALLPAPER ,newFileName,
1+2)
print "Removing: ", pathToCurrentWall
os.remove(pathToCurrentWall)

def Main():
#woot.
listOfWallpaperPaths = GenerateListOfWallpapers()
RandomlySelectedWall =
RandomlySelectWallpaper(listOfWallpaperPaths)
ChangeDesktopWallpaper(RandomlySelectedWall)

Main()
Aug 10 '08 #1
1 1351
On Aug 9, 9:20�pm, teh_sAbEr <teh.sa...@gmail.comwrote:
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, SystemParametersInfo() 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 SystemParametersInfo(), 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?
Why not rename the file instead of deleting it?
>
#random wallpaper changer!
import win32gui #use this to change the wallpaper.
import os
import os.path
import random
import Image
SPI_SETDESKWALLPAPER = 20 �#It took me WAY too long to find them.
SPI_GETDESKWALLPAPER = 115 #I should keep these handy.

def RandomlySelectWallpaper(filePaths):
� � CurrentWallpaper =
win32gui.SystemParametersInfo(SPI_GETDESKWALLPAPER )
� � while True:
� � � � index = random.randint(0,len(filePaths)-1)
� � � � RandomlySelectedWallpaper = filePaths[index]
� � � � if RandomlySelectedWallpaper <CurrentWallpaper:
� � � � � � break
� � print RandomlySelectedWallpaper
� � return RandomlySelectedWallpaper #it should be a string...

def ChangeDesktopWallpaper(RandomlySelectedWallpaper):
� � #so the RIGHT way to do this would be to use
� � #win32gui.SystemParametersInfo() to change the wallpaper.
� � #1) we convert the image to .bmp.
� � #Delete the old wallpaper, actual delete occurs afternew
wallpaper has been set.
� � pathToCurrentWall =
win32gui.SystemParametersInfo(SPI_GETDESKWALLPAPER )
� � root,extension = os.path.splitext(RandomlySelectedWallpaper)
� � newFileName = root + '.bmp'
� � print "Wallpaper to delete: ", pathToCurrentWall
� � 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(RandomlySelectedWallpaper).save(newFile Name)
� � � � print "File saved!"
� � except IOError:
� � � � print "Error while converting, please check filepath and
permissions."
� � � � print "Program will restart in anattempt to generate a
correct wallpaper."
� � � � Main()
� � win32gui.SystemParametersInfo(SPI_SETDESKWALLPAPER ,newFileName,
1+2)
� � print "Removing: ", pathToCurrentWall
� � os.remove(pathToCurrentWall)

def Main():
� � #woot.
� � listOfWallpaperPaths = GenerateListOfWallpapers()
� � RandomlySelectedWall =
RandomlySelectWallpaper(listOfWallpaperPaths)
� � ChangeDesktopWallpaper(RandomlySelectedWall)

Main()
Aug 10 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Karen Sundquist | last post by:
I have a client who wants to build a database with a user extensible schema. The client wants to model an entity with about 100 numeric attributes. As time goes on, more numeric attributes will...
15
by: charlie fortune | last post by:
I'm quite new to HTML, and have seen <marquee> get bad press here. What's wrong with using it. I wanted to have the contents of a .txt file scrolling for news items, can I do this with marquee, or...
6
by: Michael Sparks | last post by:
Hi, I suspect this is a bug with AMK's Crypto package from http://www.amk.ca/python/code/crypto , but want to check to see if I'm being dumb before posting a bug report. I'm looking at...
3
by: mrhicks | last post by:
Hello all, I have a question regarding efficeny and how to find the best approach when trying to find flag with in a structure of bit fields. I have several structures which look similar to ...
7
by: Simon | last post by:
Hi everyone, I'm wondering what you're supposed to do when you call a method that is required to perform some action but that action subsequently fails. More specifically, how do you get a...
10
by: andrew browning | last post by:
i have overlaoded all of my arithmetic operators but all are functioning as multiplication. below is a sample of the addition operator: Rational operator + (const Rational& r1, const Rational&...
18
by: bsruth | last post by:
I tried for an hour to find some reference to concrete information on why this particular inheritance implementation is a bad idea, but couldn't. So I'm sorry if this has been answered before....
8
by: ForrestPhoto | last post by:
Hi, I must be missing something stupid. This works fine for text files, but uploads about half of images ( jpg & png ) before cutting out, and leaving a useless file on the server. It doesn't...
23
by: mike3 | last post by:
Hi. (posted to both newsgroups since I was not sure of which would be appropriate for this question or how specific to the given language it is. If one of them is inappropriate, just don't send...
5
by: jehugaleahsa | last post by:
Hello: I am trying to find what is the very best approach to business objects in Windows Forms. Windows Forms presents an awesome opportunity to use DataTables and I would like to continue doing...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.