blob: ec4beaec1496f544ab2896998a89dcde6e500543 [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():
21 # 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
Jack Jansena1542622003-03-26 14:36:25 +000026 if len(sys.argv) > 1:
27 filename = sys.argv[1]
28 else:
29 filename = EasyDialogs.AskFileForOpen() # Was: QuickTime.MovieFileType
30 if not filename:
Jack Jansen9cfea101995-12-09 14:05:56 +000031 sys.exit(0)
32
33 # Open the window
34 bounds = (175, 75, 175+160, 75+120)
Jack Jansena1542622003-03-26 14:36:25 +000035 theWindow = Win.NewCWindow(bounds, os.path.split(filename)[1], 1, 0, -1, 0, 0)
Jack Jansen9cfea101995-12-09 14:05:56 +000036 Qd.SetPort(theWindow)
37 # XXXX Needed? SetGWorld((CGrafPtr)theWindow, nil)
38
Jack Jansena1542622003-03-26 14:36:25 +000039 playMovieInWindow(theWindow, filename, theWindow.GetWindowPort().GetPortBounds())
Jack Jansen9cfea101995-12-09 14:05:56 +000040
41def playMovieInWindow(theWindow, theFile, movieBox):
42 """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
63def loadMovie(theFile):
64 """Load a movie given an fsspec. Return the movie object"""
65 movieResRef = Qt.OpenMovieFile(theFile, 1)
Jack Jansen1836a621997-04-09 15:54:54 +000066 movie, d1, d2 = Qt.NewMovieFromFile(movieResRef, 0, QuickTime.newMovieActive)
Jack Jansen9cfea101995-12-09 14:05:56 +000067 return movie
68
69if __name__ == '__main__':
70 main()
71