blob: 00f596e4720f531cf54c53ef1d5ddce12938220a [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
Jack Jansena1542622003-03-26 14:36:25 +000017import os
Jack Jansen9cfea101995-12-09 14:05:56 +000018
19
20def main():
Tim Peters182b5ac2004-07-18 06:16:08 +000021 # skip the toolbox initializations, already done
22 # XXXX Should use gestalt here to check for quicktime version
23 Qt.EnterMovies()
24
25 # Get the movie file
26 if len(sys.argv) > 1:
27 filename = sys.argv[1]
28 else:
29 filename = EasyDialogs.AskFileForOpen() # Was: QuickTime.MovieFileType
30 if not filename:
31 sys.exit(0)
32
33 # Open the window
34 bounds = (175, 75, 175+160, 75+120)
35 theWindow = Win.NewCWindow(bounds, os.path.split(filename)[1], 1, 0, -1, 0, 0)
36 Qd.SetPort(theWindow)
37 # XXXX Needed? SetGWorld((CGrafPtr)theWindow, nil)
38
39 playMovieInWindow(theWindow, filename, theWindow.GetWindowPort().GetPortBounds())
40
Jack Jansen9cfea101995-12-09 14:05:56 +000041def playMovieInWindow(theWindow, theFile, movieBox):
Tim Peters182b5ac2004-07-18 06:16:08 +000042 """Play a movie in a window"""
43 # XXXX Needed? SetGWorld((CGrafPtr)theWindow, nil);
44
45 # Get the movie
46 theMovie = loadMovie(theFile)
47
48 # Set where we want it
49 theMovie.SetMovieBox(movieBox)
50
51 # Start at the beginning
52 theMovie.GoToBeginningOfMovie()
53
54 # Give a little time to preroll
55 theMovie.MoviesTask(0)
56
57 # Start playing
58 theMovie.StartMovie()
59
60 while not theMovie.IsMovieDone() and not Evt.Button():
61 theMovie.MoviesTask(0)
62
Jack Jansen9cfea101995-12-09 14:05:56 +000063def loadMovie(theFile):
Tim Peters182b5ac2004-07-18 06:16:08 +000064 """Load a movie given an fsspec. Return the movie object"""
65 movieResRef = Qt.OpenMovieFile(theFile, 1)
66 movie, d1, d2 = Qt.NewMovieFromFile(movieResRef, 0, QuickTime.newMovieActive)
67 return movie
68
Jack Jansen9cfea101995-12-09 14:05:56 +000069if __name__ == '__main__':
Tim Peters182b5ac2004-07-18 06:16:08 +000070 main()