blob: 0df30a4ac9306432af6161bdff127bcba7629898 [file] [log] [blame]
Jack Jansen9cfea101995-12-09 14:05:56 +00001"""MovieInWindow converted to python
2
3Jack Jansen, CWI, December 1995
4"""
5
Jack Jansen5a6fdcd2001-08-25 12:15:04 +00006from Carbon import Qt
7from Carbon import QuickTime
8from Carbon import Qd
9from Carbon import QuickDraw
10from Carbon import Evt
11from Carbon import Events
12from Carbon import Win
13from Carbon import Windows
Jack Jansenb340acf2003-01-26 21:40:00 +000014from Carbon import File
15import EasyDialogs
Jack Jansen9cfea101995-12-09 14:05:56 +000016import sys
17
18
19def main():
20 # skip the toolbox initializations, already done
21 # XXXX Should use gestalt here to check for quicktime version
22 Qt.EnterMovies()
23
24 # Get the movie file
Jack Jansenb340acf2003-01-26 21:40:00 +000025 fss = EasyDialogs.AskFileForOpen(wanted=File.FSSpec) # Was: QuickTime.MovieFileType
26 if not fss:
Jack Jansen9cfea101995-12-09 14:05:56 +000027 sys.exit(0)
28
29 # Open the window
30 bounds = (175, 75, 175+160, 75+120)
31 theWindow = Win.NewCWindow(bounds, fss.as_tuple()[2], 1, 0, -1, 0, 0)
32 Qd.SetPort(theWindow)
33 # XXXX Needed? SetGWorld((CGrafPtr)theWindow, nil)
34
Jack Jansen362c7cd02002-11-30 00:01:29 +000035 playMovieInWindow(theWindow, fss, theWindow.GetWindowPort().GetPortBounds())
Jack Jansen9cfea101995-12-09 14:05:56 +000036
37def playMovieInWindow(theWindow, theFile, movieBox):
38 """Play a movie in a window"""
39 # XXXX Needed? SetGWorld((CGrafPtr)theWindow, nil);
40
41 # Get the movie
42 theMovie = loadMovie(theFile)
43
44 # Set where we want it
45 theMovie.SetMovieBox(movieBox)
46
47 # Start at the beginning
48 theMovie.GoToBeginningOfMovie()
49
50 # Give a little time to preroll
51 theMovie.MoviesTask(0)
52
53 # Start playing
54 theMovie.StartMovie()
55
56 while not theMovie.IsMovieDone() and not Evt.Button():
57 theMovie.MoviesTask(0)
58
59def loadMovie(theFile):
60 """Load a movie given an fsspec. Return the movie object"""
61 movieResRef = Qt.OpenMovieFile(theFile, 1)
Jack Jansen1836a621997-04-09 15:54:54 +000062 movie, d1, d2 = Qt.NewMovieFromFile(movieResRef, 0, QuickTime.newMovieActive)
Jack Jansen9cfea101995-12-09 14:05:56 +000063 return movie
64
65if __name__ == '__main__':
66 main()
67