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 |
| 17 | |
| 18 | |
| 19 | def 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 Jansen | b340acf | 2003-01-26 21:40:00 +0000 | [diff] [blame^] | 25 | fss = EasyDialogs.AskFileForOpen(wanted=File.FSSpec) # Was: QuickTime.MovieFileType |
| 26 | if not fss: |
Jack Jansen | 9cfea10 | 1995-12-09 14:05:56 +0000 | [diff] [blame] | 27 | 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 Jansen | 362c7cd0 | 2002-11-30 00:01:29 +0000 | [diff] [blame] | 35 | playMovieInWindow(theWindow, fss, theWindow.GetWindowPort().GetPortBounds()) |
Jack Jansen | 9cfea10 | 1995-12-09 14:05:56 +0000 | [diff] [blame] | 36 | |
| 37 | def 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 | |
| 59 | def loadMovie(theFile): |
| 60 | """Load a movie given an fsspec. Return the movie object""" |
| 61 | movieResRef = Qt.OpenMovieFile(theFile, 1) |
Jack Jansen | 1836a62 | 1997-04-09 15:54:54 +0000 | [diff] [blame] | 62 | movie, d1, d2 = Qt.NewMovieFromFile(movieResRef, 0, QuickTime.newMovieActive) |
Jack Jansen | 9cfea10 | 1995-12-09 14:05:56 +0000 | [diff] [blame] | 63 | return movie |
| 64 | |
| 65 | if __name__ == '__main__': |
| 66 | main() |
| 67 | |