5

作为背景,我正在运行 Debian Lenny,并且已经在 GNOME 和 Fluxbox 上进行了尝试。

无论如何,我一直在研究如何在桌面上绘图,我在这里找到并尝试了这段代码:http: //blog.prashanthellina.com/2007/08/24/drawing-on-your-desktop/

它工作得很好,除了终止它(通过按控制 C),X 失去了创建新窗口的能力。

我原以为问题可能是 pygame 没有释放一些资源,所以我添加了一段代码来捕获 kill 信号,给了我以下信息:

"""
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)

所以我又试了一次。中断处理程序中的打印语句告诉我,当我退出时处理程序确实运行了,但我仍然遇到同样的问题。更有趣的是,X 在运行时没有任何问题。只有在终止它之后。

可能有人知道发生了什么,以及我可以做些什么来修复代码,这样它就不会破坏我的 X 会话?提前致谢。

4

1 回答 1

1

问题、想法和要尝试的事情:

  1. 如果您在尝试 -c 之前已经启动了终端,那么之后您还能输入吗?如果是,则可能是您的会话或窗口管理器有问题,而不是 x 服务器。
  2. 您是否尝试过 Ctrl-Alt-Backspace?这能解决您的问题吗?
  3. gtk-window-decorator 和 x-session-manager 还在运行吗?

pygame 通常会用完窗口,并且通常会尝试自行清理。您已经添加了对 pygame.display.quit() 的显式调用,但我认为这不会改变任何东西 - pygame 会尝试删除 SDL_WINDOWID 变量引用的窗口。实际上成功删除您的根窗口可能是一件坏事。我猜你从那个人那里得到这个,运行 ubuntu,pygame 无法删除窗口,因为他没有权限。你可能在你的操作系统上。

既然杀死你的根窗口是不好的,那么将根窗口的控制权恢复到 nautilus (gnome) 怎么样?像gconftool-2 --type bool --set /apps/nautilus/preferences/show_desktop true什么?

于 2009-09-15T03:01:37.403 回答