tags:

views:

287

answers:

1

For background, I'm running Debian Lenny, and have tried this with both GNOME and Fluxbox.

Anyway, I've been looking at how to draw on the desktop, and I found and tried this code here: http://blog.prashanthellina.com/2007/08/24/drawing-on-your-desktop/

It worked fine, except upon terminating it (by hitting control C), X loses it's ability to create new windows.

I had thought that maybe the problem was pygame not releasing some resource, so I added in a block of code to trap the kill signal, giving me the following:

"""
Run the following command in the shell before executing this script
export SDL_WINDOWID=`xwininfo -root|grep "id:"|sed 's/^.*id: //'|sed 's/ (.*$//'`
"""
import pygame
import sys
import random
import time
import signal





pygame.init()

window = pygame.display.set_mode((1280, 1024))
screen = pygame.display.get_surface()


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 C^C Interupts
signal.signal(signal.SIGINT, handle_sigint)


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(.03)
    rect = pygame.draw.circle(screen, (col_r, col_g, col_b), (x,y), radius)
    pygame.display.update(rect)

And so I tried again. The print statement in the interrupt handler tells me that the handler does run when I quit, but I still have the same problem. And even more interestingly, X has no problems while it's running. It's only after terminating it.

Might anybody out there have any idea what's happening, and what I can do to fix the code so it doesn't wreck my X session? Thanks in advance.

+1  A: 

Questions, ideas & things to try:

  1. If you have a terminal up before you try a -c, can you still type in it after? If yes, there's likely a problem in your session or window manager, not the x server.
  2. Have you tried Ctrl-Alt-Backspace? Does this fix your problem?
  3. Are gtk-window-decorator and x-session-manager still running?

pygame is typically run out of a window and is normally going to try to cleanup after itself. You've added an explicit call to pygame.display.quit(), but I don't think this changes anything - pygame tries to delete the window referred to by the SDL_WINDOWID variable. Actually succeeding in deleting your root window is probably a bad thing. I'm going to guess that the guy you got this from, running ubuntu, pygame fails to delete the window because he doesn't have permission. You might on your OS.

Since killing your root window is bad, how about just restoring control of the root window back to nautilus (gnome)? something like gconftool-2 --type bool --set /apps/nautilus/preferences/show_desktop true?

DaveParillo
In answer to the questions:1.) I can still type in the terminal, although odd stuff starts to happen. For example, as I type this comment in Firefox, I don't have a cursor.2.) Yes, that fixes the problem.3.) I'm not sure how to tell. I've tried ps ax | grep gtk and ps ax | grep session, but I don't see either of those processes.And really, running in fluxbox, I'm not using nautilus, so the stuff pertaining to gconftool seems irrelevant. But in any case, thanks for the advice.
BigBeagle
DaveParillo