对于背景,我正在跑步 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)
所以我再试一次。中断处理程序中的print语句告诉我,当我退出时处理程序确实运行,但我仍然遇到同样的问题。更有趣的是,X在运行时没有任何问题。只有在终止它之后才会这样做。
可能有人在那里知道发生了什么,以及我可以做些什么来修复代码,这样它就不会破坏我的X会话?提前谢谢。
答案 0 :(得分:1)
问题,想法和要尝试的事情:
pygame通常会在窗口外运行,并且通常会尝试自行清理。你已经添加了对pygame.display.quit()的显式调用,但我不认为这会改变任何东西 - pygame尝试删除SDL_WINDOWID变量引用的窗口。实际上成功删除你的根窗口可能是一件坏事。我猜这个你从中得到这个的人,运行ubuntu,pygame无法删除窗口,因为他没有权限。你可能在你的操作系统上。
由于杀死你的根窗口很糟糕,如何将根窗口的控制恢复回nautilus(gnome)?类似于gconftool-2 --type bool --set /apps/nautilus/preferences/show_desktop true
?