Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 29th, 2008, 5:34 AM   #1
cornjuliox
Newbie
 
Join Date: Jun 2008
Posts: 1
Rep Power: 0 cornjuliox is on a distinguished road
Changing wallpapers with Python

I'm trying to make a script that changes the desktop wallpaper (Windows XP) every time its run. To do this I wrote a script that edits a Registry value containing the path to the currently selected wallpaper, and it seems to be working, but the change doesn't take effect immediately, like it would through the Display Properties dialog. I have to open up the dialog myself and just hit 'Apply' (the wallpaper is already there in the list, selected). Is there a way to make the change take effect automatically, without having to restart the PC or anything?
Python Syntax (Toggle Plain Text)
  1. #random wallpaper changer!
  2. import _winreg
  3. from os import walk
  4. from os.path import exists
  5. from random import randint
  6.  
  7. #first grab a registry handle.
  8. #_winreg.KEY_SET_VALUE
  9. handle = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,r'Control Panel\Desktop',0,_winreg.KEY_WRITE)
  10. print "Registry Handle Created with KEY_SET_VALUE mask"
  11.  
  12. def GenerateListOfWallpapers():
  13. targetDir = 'C:\Documents and Settings\Enrico Jr\My Documents\Jr\'s Wallpapers'
  14. fileNames = []
  15. filePaths = []
  16. if exists(targetDir):
  17. #proceed to make the list of files
  18. for x,y,z in walk(targetDir):
  19. for name in z:
  20. fileNames.append(name)
  21. for item in fileNames:
  22. filePaths.append(targetDir + '\\' + item)
  23. return filePaths
  24.  
  25. def RandomlySelectWallpaper(filePaths):
  26. index = randint(0,len(filePaths)-1)
  27. RandomlySelectedWallpaper = filePaths[index]
  28. return RandomlySelectedWallpaper #it should be a string...
  29.  
  30. #now to edit the wallpaper registry key
  31. newWallpaper = RandomlySelectWallpaper(GenerateListOfWallpapers())
  32. print "Registry Handle Created."
  33. print "Random wallpaper selected."
  34. _winreg.SetValueEx(handle,'ConvertedWallpaper',0,_winreg.REG_SZ,newWallpaper)
  35. print "New wallpaper value set."
cornjuliox is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
python for newbie wizzkid Python 3 Jun 7th, 2006 7:31 PM
[tutorial] Python for programming beginners coldDeath Python 30 Dec 14th, 2005 11:35 AM
Convert Python script to C++ code clanotheduck Python 17 Sep 25th, 2005 8:55 AM
Advanced Python Tricks Arevos Python 19 Sep 24th, 2005 7:39 AM
Python - A Programmers Introduction coldDeath Python 17 Aug 19th, 2005 12:41 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:16 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC