2014-03-04 1 views
2

나는 다음과 같은 코드를 실행하려고 : Mac에서 PyGTK를 실행 중 : AttributeError : xid 속성이 지원되지 않습니까?

import os, sys 
import gtk 
import pygame 
from pygame.locals import * 
import gobject 

class GameWindow(gtk.Window): 
    def __init__(self): 
     gtk.Window.__init__(self) 
     self.set_title("TEST") 
     self.connect('delete-event', gtk.main_quit) 
     self.set_resizable(True) 

    def draw(self): 
     #menu stuff here 
     mb = gtk.MenuBar() 
     menu1 = gtk.Menu() 

     #anything in 'File' starts here 
     menu1sub1 = gtk.MenuItem("File") 
     menu1sub1.set_submenu(menu1) 
     exit = gtk.MenuItem("Exit") 
     exit.connect("activate", gtk.main_quit) 
     menu1.append(exit) 
     mb.append(menu1sub1) 

     #drawing area to hold pygame 
     da = gtk.DrawingArea() 
     da.set_app_paintable(True) 
     da.set_size_request(550,450) 
     da.connect("realize",self._realized) 

     #container that holds menu and drawing area 
     #gtk.Window can only hold one widget 
     #this always it to hold more 
     vbox = gtk.VBox(False, 2) 
     #packs menu then below that it will pack the drawing area 
     vbox.pack_start(mb) 
     vbox.pack_start(da) 
     self.add(vbox) 


     gtk.gdk.flush() 
     self.show_all() 

    def _realized(self, widget, data=None): 
     #an id is needed for the connection between da and pygame 
     os.putenv('SDL_WINDOWID', str(widget.window.xid)) 
     pygame.init() 
     pygame.display.set_mode((550,450), 0, 32) 
     self.screen = pygame.display.get_surface() 
     #every 200 milliseconds gobject calls game 
     gobject.timeout_add(200, self.game) 

    #this is code to initialize the game 
    def game(self): 
     self.cup = [pygame.image.load("cup.png"),pygame.image.load("cup.png"),pygame.image.load("cup.png"),pygame.image.load("cup.png")] 
     self.cupwidth = pygame.Surface.get_width(self.cup[0]) 
     self.cupheight = pygame.Surface.get_height(self.cup[0]) 
     self.cupx=[0,0,0,0] 
     self.cupy=[450-self.cupheight,450-self.cupheight-25,450-self.cupheight-50,450-self.cupheight-75] 
     self.screen.fill((0,0,0)) 
     self.screen.blit(self.cup[0],(self.cupx[0],self.cupy[0])) 
     pygame.display.update() 

if __name__ == "__main__": 
    wi = GameWindow() 
    wi.draw() 
    gtk.main() 

내가 위키 jhbuild를 튜토리얼에서 GTK를 설치, 나는 성공적으로 helloworld를 다른 사람의 몇 달렸다. 필자는 PyGame에 대해 PyGTK 래퍼를 사용하고 싶었습니다. 저는 두 사람과 함께 일하고 있으며, 그 중 한 명은 위의 코드를 테스트 해 보았습니다. 그것은 명백하게 실행됩니다 (그는 MintOS를 실행 중입니다). 내 Mac에

내가 얻을 :

me:Downloads Me$ python gamewindow.py 
Traceback (most recent call last): 
    File "gamewindow.py", line 48, in _realized 
    os.putenv('SDL_WINDOWID', str(widget.window.xid)) 
AttributeError: xid attribute not supported 

^CTraceback (most recent call last): 
    File "gamewindow.py", line 69, in <module> 
    gtk.main() 
KeyboardInterrupt 

오류가 치명적인하지, 난 그냥 빈 창을 얻는다. 나는 오류를 수정하는 방법을 궁금해. Mac에서 가능합니까?

답변

3

gtk from macport with or without x11osxvideosink: how to get the window id에 대한 응답을 읽으면서 설치된 PyGTK 버전이 X11 대신 Quartz를 지원하도록 컴파일되어 있기 때문에 문제가있는 것 같습니다. 이것이 사실이라면 OSX에서 window.xidwindow.nsview으로 바꿀 수 있습니다. 즉, 변경 :

os.putenv('SDL_WINDOWID', str(widget.window.xid)) 

뭔가에 다음과 같이 : 또한

if sys.platform == "darwin": 
    window_id = widget.window.nsview 
else: 
    window_id = widget.window.xid 
os.putenv('SDL_WINDOWID', str(window_id)) 

window.nsview 당신이 window.nswindow을 시도 할 수 작동하지 않는 경우.

+0

슬프게도, 더 이상 GTK3 gi 바인딩과 함께 작동하지 않습니다. – totaam

+1

@totaam 놀랄 필요가 없습니다. GTK3는 모든 유용한 설정과 속성을 천천히 제거합니다. – cpburnz

관련 문제