Jack Jansen | 9cfea10 | 1995-12-09 14:05:56 +0000 | [diff] [blame] | 1 | """MovieInWindow converted to python |
| 2 | |
| 3 | Jack Jansen, CWI, December 1995 |
| 4 | """ |
| 5 | |
Jack Jansen | 5a6fdcd | 2001-08-25 12:15:04 +0000 | [diff] [blame] | 6 | from Carbon import Qt |
| 7 | from Carbon import QuickTime |
| 8 | from Carbon import Qd |
| 9 | from Carbon import QuickDraw |
| 10 | from Carbon import Evt |
| 11 | from Carbon import Events |
| 12 | from Carbon import Win |
| 13 | from Carbon import Windows |
Jack Jansen | b340acf | 2003-01-26 21:40:00 +0000 | [diff] [blame] | 14 | from Carbon import File |
| 15 | import EasyDialogs |
Jack Jansen | 9cfea10 | 1995-12-09 14:05:56 +0000 | [diff] [blame] | 16 | import sys |
Jack Jansen | a154262 | 2003-03-26 14:36:25 +0000 | [diff] [blame] | 17 | import os |
Jack Jansen | 9cfea10 | 1995-12-09 14:05:56 +0000 | [diff] [blame] | 18 | |
| 19 | |
| 20 | def main(): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 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 |
| 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 Jansen | 9cfea10 | 1995-12-09 14:05:56 +0000 | [diff] [blame] | 41 | def playMovieInWindow(theWindow, theFile, movieBox): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 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 | |
Jack Jansen | 9cfea10 | 1995-12-09 14:05:56 +0000 | [diff] [blame] | 63 | def loadMovie(theFile): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 64 | """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 Jansen | 9cfea10 | 1995-12-09 14:05:56 +0000 | [diff] [blame] | 69 | if __name__ == '__main__': |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 70 | main() |