473,834 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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, 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()
Aug 10 '08 #1
1 1371
On Aug 9, 9:20�pm, teh_sAbEr <teh.sa...@gmai l.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, 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?
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_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 afternew
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 anattempt 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()
Aug 10 '08 #2

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

Similar topics

4
1451
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 be added. The client wants an admin function that will allow him to add these attributes when needed. My instinct is that this is wrong and that bad things will happen if we build this. However, when I went to write up the reasons, all I
15
10426
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 should I be looking at applets ?
6
6589
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 using this library and to familiarise myself writing small tests with each of the ciphers. When I hit Crypto.Cipher.ARC4 I've
3
2286
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 typedef unsigned long int uint32; /* 32 bits */ // Up to 36 request flags, so this will take up to 3
7
1412
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 custom message back so that you can provide some useful information to the application user? It seems we dont have much room for manouever. Example:
10
1873
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& r2){ //Postcondition: sum of r1 and r2 are returned int numerator; int denominator;
18
2348
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. Here's the scenario: We have a base class with all virtual functions. We'll call this the Animal class. We then make two classes Fish and Bird that both inherit from Animal. In the program, we have a single array of Animal pointers that will...
8
2481
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 throw an exception, though. My guess is the encoding is wrong, but I've tried UTF 8, and use binary. Any thoughts? This comes from the MSDN documentation:
23
2378
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 replies to it.) I'm making a bignum package for use in a program I've got (this is something different from the pi program you may have heard about). The package is going to support manipulating long floating point numbers.
5
2009
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 so. I have worked with dynamically generated DataTables with customized DataRows. However, these classes are usually pretty limited. For instance, you are limited to a select few data types and you can't deal with nulls as well as desired (in...
0
9799
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9646
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10510
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10548
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9331
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7758
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5794
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3081
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.