pygame初始化帧缓冲区或x服务器 [英] pygame initialize framebuffer or x server
问题描述
我有一个检查合适的帧缓冲区的类,它工作正常.几台计算机(大多数是嵌入式旧板)上没有帧缓冲区,因此我删除了 init (self):函数并手动将其设置为在X下运行.每当我进行更改时,我都厌倦了移植它.
I have a class that checks for suitable framebuffer, and it works fine. One a couple of computers (mostly embedded older boards) there is no framebuffer, so I remove the init(self): function and manually set it to run under X. Both ways work on their respective systems, I'm just tired of porting it every time I make a change.
这是工作帧缓冲区代码:
Here is the working framebuffer code:
class wxdisplay :
screen = None;
def __init__(self):
"Ininitializes a new pygame screen using the framebuffer"
# Based on "Python GUI in Linux frame buffer"
# http://www.karoltomala.com/blog/?p=679
disp_no = os.getenv("DISPLAY")
if disp_no:
print "I'm running under X display = {0}".format(disp_no)
# Check which frame buffer drivers are available
# Start with fbcon since directfb hangs with composite output
drivers = ['fbcon', 'directfb', 'svgalib']
found = False
for driver in drivers:
# Make sure that SDL_VIDEODRIVER is set
if not os.getenv('SDL_VIDEODRIVER'):
os.putenv('SDL_VIDEODRIVER', driver)
try:
pygame.display.init()
except pygame.error:
print 'Driver: {0} failed.'.format(driver)
continue
found = True
break
if not found:
raise Exception('No suitable video driver found!')
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
print "Framebuffer size: %d x %d" % (size[0], size[1])
self.screen = pygame.display.set_mode(size, pygame.FULLSCREEN)class wxdisplay :
这是非帧缓冲版本:
class wxdisplay :
pygame.init()
size = (1024, 768)
screen = pygame.display.set_mode(size)
print "Framebuffer size: %d x %d" % (size[0], size[1])
我想尝试初始化帧缓冲区,如果失败,请尝试并在控制台上运行它.我尝试过的一切,如果尝试过或例外的都失败了...
I would like to try and initialize the framebuffer and if it fails, try and just run it on the console. Every thing I have try'd or if'd or excepted fails...
class wxdisplay :
def __init__(self):
# Try to use framebuffer, and use the local X server if not there
try:
screen = None;
"Ininitializes a new pygame screen using the framebuffer"
# Based on "Python GUI in Linux frame buffer"
# http://www.karoltomala.com/blog/?p=679
disp_no = os.getenv("DISPLAY")
print("disp_no " +disp_no)
if disp_no:
print "I'm running under X display = {0}".format(disp_no)
# Check which frame buffer drivers are available
# Start with fbcon since directfb hangs with composite output
drivers = ['fbcon', 'directfb', 'svgalib', 'xvfb', 'Xvfb']
found = False
for driver in drivers:
# Make sure that SDL_VIDEODRIVER is set
if not os.getenv('SDL_VIDEODRIVER'):
os.putenv('SDL_VIDEODRIVER', driver)
try:
print("Driver: "+driver)
pygame.display.init()
except pygame.error:
print 'Driver: {0} failed.'.format(driver)
continue
found = True
print("break")
break
if not found:
raise Exception('No suitable video driver found!')
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
print "Framebuffer size: %d x %d" % (size[0], size[1])
self.screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
except:
print('No suitable Framebuffer found!')
pygame.init()
size = (1024, 768)
print "X server size: %d x %d" % (size[0], size[1])
self.screen = pygame.display.set_mode(size)
失败:
starting from __main__ call
disp_no localhost:11.0
I'm running under X display = localhost:11.0
Driver: fbcon
Driver: fbcon failed.
Driver: directfb
commandline read: python
commandline read: ./PiWxDisplay.py
~~~~~~~~~~~~~~~~~~~~~~~~~~| DirectFB 1.2.10 |~~~~~~~~~~~~~~~~~~~~~~~~~~
(c) 2001-2008 The world wide DirectFB Open Source Community
(c) 2000-2004 Convergence (integrated media) GmbH
----------------------------------------------------------------
(*) DirectFB/Core: Single Application Core. (2012-05-20 13:17)
(!) Direct/Util: opening '/dev/fb0' and '/dev/fb/0' failed
--> No such file or directory
(!) DirectFB/FBDev: Error opening framebuffer device!
(!) DirectFB/FBDev: Use 'fbdev' option or set FRAMEBUFFER environment variable.
(!) DirectFB/Core: Could not initialize 'system_core' core!
--> Initialization error!
Driver: directfb failed.
Driver: svgalib
Driver: svgalib failed..
No suitable Framebuffer found!
X server size: 1024 x 768
Traceback (most recent call last):
File "./PiWxDisplay.py", line 366, in <module>
wxdisplay().start_screen()
File "./PiWxDisplay.py", line 66, in __init__
self.screen = pygame.display.set_mode(size)
pygame.error: No available video device
我显然不完全了解如何正确初始化pygame.我怎么去
I obviously don't fully understand how to initialize pygame correctly. How would I get it to
- 检查FB驱动程序
- 如果FB驱动程序检测失败,请使用X服务器
推荐答案
您已经将 SDL_VIDEODRIVER 环境更改为仅检查fb设备.
You have already changed the SDL_VIDEODRIVER environment to check only for fb devices.
我建议您在异常处理程序中的 pygame.init()调用之前使用此功能:
I'd suggest using this before your pygame.init() call in your exception handler:
os.putenv('SDL_VIDEODRIVER', 'x11')
或取消设置 SDL_VIDEODRIVER 环境变量,以使 pygame.init()认为尚未处理.
or unset the SDL_VIDEODRIVER environment var, so that pygame.init() doesn't think it's already dealt with.
请参阅: http://www.pygame.org/docs/ref/display.html#pygame.display.init
这篇关于pygame初始化帧缓冲区或x服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!