2007年9月4日火曜日

PyObjC x QTKit

PyObjCを介して簡単なFullScreenのQuicktimeプレイヤーを作る。
最終的にはwxPythonと組み合わせるために、Interface BuilderとXCodeは使わずに
直接プログラムを書いてウィンドウを作成し、QTMovieViewをウィンドウ内に配置する。

Interface BuilderとXCodeを使わずに(しかもPythonで)アプリケーションを作るサンプルが以外とない。以下Xcode, Interface Builderを使わないフルスクリーン表示プログラム

import objc
import QTKit
from AppKit import *
from Foundation import *
from PyObjCTools import AppHelper

app = NSApplication.sharedApplication()

#Fullscreen Setting
screenRect = NSScreen.mainScreen().frame()
NSMenu.setMenuBarVisible_(False)

#Quicktime Setting
size = screenRect.size
path = "./fireball.mov" #Movie path as FullPaht
movie = QTKit.QTMovie.alloc() #Create QTMovie Instance with alloc()
movie.initWithFile_error_(path) #Set MovieFile to movie
movview = QTMovieView.alloc().init() #Create MovieView Instance
movview.initWithFrame_(NSRect((0,0),size)) #Initialize Position and Size (It will be a subview of NSWindow)
movview.setControllerVisible_(False)
movview.setMovie_(movie) #Set movie to movieview
movview.play_(movie) #Play command from Movieview

#Window Setting
window = NSWindow.alloc() #Create NSWindow Instance
window.initWithContentRect_styleMask_backing_defer_(((0,0),size),0,2,0) #Initialize Windowstyle, position and size
window.setLevel_(3) #Depth of window
window.contentView().addSubview_(movview) #Add subview (Movieview) on NSWindow
window.display() #Show Window
window.orderFrontRegardless()

AppHelper.runEventLoop()

0 件のコメント: