0

tl;dr The usual way of using python to set the desktop background using ctypes is too slow for animation purposes. I'm wondering if I have any options to set the background at O(5fps) without destroying my computer's performance.

~~~~

Howdy folks!

The other day I got excited about this idea I had: I wanted to make my desktop background cycle through the most recent images of the Sun (from SDO), as downloaded from a NASA website. And it worked! I have a code that runs in the background on my computer, and updates my desktop every thirty seconds to the newest image from the internet (it also cycles through the wavelengths. Very fun!.) And it is really cool! Looking at it every day and seeing how the sun changes is cool. So that's a success.

But the Sun also has a lot of short term dynamics that I'd like to be able to observe as well! So, I thought, the solution is easy enough! Just keep the last 30 images you downloaded and serve them up rapid fire! The loop is easy enough (distilled to the base components):

import os
import ctypes
import time

#Get the filepaths of all pictures in a folder
folderPath = fromGod()
items = os.listdir(folderPath)  
listOfFiles = [folderPath + item for item in items]

frameTime = 0.25 #second
runFor = 30 #seconds

#Cycle through the pictures 
startTime = time.time()
while time.time() - startTime < runFor:
    for file in listOfFiles:
        ctypes.windll.user32.SystemParametersInfoW(20, 0, file , 0)
        time.sleep(frameTime)

This actually does work! It looks pretty nice, and I would even settle for the 4 fps it seems capable of before it just stops working at all. The problem is that every call to the ctypes function causes the whole system to {freeze?. stutter?, slow down?}. It totally kills the idea, because there is no way I can let this code run in the background. It makes my mouse stutter across my screen.

But I see that programs exist that can make the desktop background be a movie, so I'm hoping there is some other way I can do this on my own in python. I guess I just don't understand why this function should have such a drain on the system. But searching here on stack overflow and on google has not been fruitful in terms of alternate ways to do this.

I am on a Dell Windows 10 laptop, running python 3.6.5 in Anaconda form.

Gilly Gumption
  • 111
  • 1
  • 7
  • What is the size of each images you download and prepare to be set as wallpaper ? try to reduce the image size and resolution and test the code. – Mojtaba Tajik Sep 10 '18 at 02:55
  • Originally I was using 2048x2048, but I just tried 1024 and 512, and it doesn't seem to affect it. – Gilly Gumption Sep 10 '18 at 03:05
  • For starters have you tried writing the above code in *C* to see if *Python* is really the problem? (which I kind of doubt). What in your program takes so long? Remember that you shouldn't `time.sleep(frameTime)`, but yoyu should subtract the time needed for `SystemParametersInfoW` to complete. Actually you don't even need the `for` loop. How many files are we talking about (in `folderPath`)? *BTW* are you using the computer to look at the desktop? Wouldn't make more sense to install an app that would cycle the images only when you want to look at them? Doesn't *Win* have a slideshow option? – CristiFati Sep 10 '18 at 08:35
  • I have several monitors and one of them is clear often enough that it is fun to have a live view of the sun there. Generally I'm thinking 10-30 files at most. – Gilly Gumption Sep 11 '18 at 04:56

0 Answers0