This is related to the previous post and is meant in part to demonstrate how great Linux is for doing “weird” stuff
. This is what we are
trying to do.
The circles in the background have been drawn by the python script below. To get the script running you should have python and pygame installed. If you are on Ubuntu do this to install both otherwise you can get the binaries for your distribution/OS.
sudo apt-get install python pygame
The code:
import pygame
import sys
import random
import time
pygame.init()
window = pygame.display.set_mode((1280, 1024))
screen = pygame.display.get_surface()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit(0)
x = random.choice(range(640))
y = random.choice(range(480))
radius = random.choice(range(100))
col_r = random.choice(range(255))
col_g = random.choice(range(255))
col_b = random.choice(range(255))
time.sleep(.01)
rect = pygame.draw.circle(screen, (col_r, col_g, col_b), (x,y), radius)
pygame.display.update(rect)
Running the code:
This will set the environment variable “SDL_WINDOWID” so that the script will know what the root window is.
export SDL_WINDOWID=`xwininfo -root|grep "id:"|sed 's/^.*id: //'|sed 's/ (.*$//'`
We have to tell the window manager to stop drawing on the desktop. I use gnome where the “nautilus” process does the drawing. Let us ask it to stop drawing.
gconftool-2 --type bool --set /apps/nautilus/preferences/show_desktop false
Now run the script:
python desktop_circles.py
Tagged: desktop, gnome, graphics, linux, programming, python
No Trackbacks
5 Comments
cool stuff man!
Hi. Very interesting code.
I tried it out myself. It works, but it seems that once I stop it (like with control C), X loses the ability to make any new windows. In fact, attempting to call xcalc, it fails with:
X Error of failed request: BadMatch (invalid parameter attributes)
Major opcode of failed request: 1 (X_CreateWindow)
Serial number of failed request: 41
Current serial number in output stream: 44
I thought that maybe something wasn’t getting released, so I inserted the following code in before the loop, to catch and respond to the interrupt:
def handle_sigint(signum, frame):
“”"I want to ensure resources are released before bailing.”"”
print(“SIGINT received.”);
pygame.display.quit()
pygame.quit()
sys.exit(0)
# Set handler to catch Interupts
signal.signal(signal.SIGINT, handle_sigint)
Unfortunately, it didn’t seem to change anything. Do you have any ideas why that might be?
Oh yes, I’m running this under Debian/FluxBox, if that makes any difference.
Yes, once I restart X the problem goes away. I also tried this under GNOME just now with the same result. I don’t have an Ubuntu install handy to try it on though at the moment. This has me really curious now.
I tried this a while ago and had the same problem. Everything works as long as it’s running, but as soon as the script ends, X goes havoc.
I tried a few things but I too couldnt find a solution.
Running awesome3 on Arch Linux.
Just in case anyone reads this. Jamie, you are not alone