Jack Jansen | 9cfea10 | 1995-12-09 14:05:56 +0000 | [diff] [blame] | 1 | """VerySimplePlayer 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 | 9cfea10 | 1995-12-09 14:05:56 +0000 | [diff] [blame] | 14 | import macfs |
| 15 | import sys |
| 16 | |
| 17 | # XXXX maxbounds = (40, 40, 1000, 1000) |
| 18 | |
| 19 | def main(): |
| 20 | print 'hello world' # XXXX |
| 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 | fss, ok = macfs.StandardGetFile(QuickTime.MovieFileType) |
| 27 | if not ok: |
| 28 | sys.exit(0) |
| 29 | |
| 30 | # Open the window |
| 31 | bounds = (175, 75, 175+160, 75+120) |
| 32 | theWindow = Win.NewCWindow(bounds, fss.as_tuple()[2], 0, 0, -1, 1, 0) |
| 33 | # XXXX Needed? SetGWorld((CGrafPtr)theWindow, nil) |
| 34 | Qd.SetPort(theWindow) |
| 35 | |
| 36 | # Get the movie |
| 37 | theMovie = loadMovie(fss) |
| 38 | |
| 39 | # Relocate to (0, 0) |
| 40 | bounds = theMovie.GetMovieBox() |
| 41 | bounds = 0, 0, bounds[2]-bounds[0], bounds[3]-bounds[1] |
| 42 | theMovie.SetMovieBox(bounds) |
| 43 | |
| 44 | # Create a controller |
| 45 | theController = theMovie.NewMovieController(bounds, QuickTime.mcTopLeftMovie) |
| 46 | |
| 47 | # Get movie size and update window parameters |
| 48 | rv, bounds = theController.MCGetControllerBoundsRect() |
| 49 | theWindow.SizeWindow(bounds[2], bounds[3], 0) # XXXX or [3] [2]? |
| 50 | Qt.AlignWindow(theWindow, 0) |
| 51 | theWindow.ShowWindow() |
| 52 | |
| 53 | # XXXX MCDoAction(theController, mcActionSetGrowBoxBounds, &maxBounds) |
| 54 | theController.MCDoAction(QuickTime.mcActionSetKeysEnabled, '1') |
| 55 | |
| 56 | # XXXX MCSetActionFilterWithRefCon(theController, movieControllerEventFilter, (long)theWindow) |
| 57 | |
| 58 | done = 0 |
| 59 | while not done: |
Jack Jansen | 19f273c | 2001-06-25 08:48:05 +0000 | [diff] [blame] | 60 | gotone, evt = Evt.WaitNextEvent(0xffff, 0) |
Jack Jansen | 9cfea10 | 1995-12-09 14:05:56 +0000 | [diff] [blame] | 61 | (what, message, when, where, modifiers) = evt |
| 62 | ## print what, message, when, where, modifiers # XXXX |
| 63 | |
| 64 | if theController.MCIsPlayerEvent(evt): |
| 65 | continue |
| 66 | |
| 67 | if what == Events.mouseDown: |
| 68 | part, whichWindow = Win.FindWindow(where) |
| 69 | if part == Windows.inGoAway: |
| 70 | done = whichWindow.TrackGoAway(where) |
| 71 | elif part == Windows.inDrag: |
| 72 | Qt.DragAlignedWindow(whichWindow, where, (0, 0, 4000, 4000)) |
| 73 | elif what == Events.updateEvt: |
| 74 | whichWindow = Win.WhichWindow(message) |
| 75 | if not whichWindow: |
| 76 | # Probably the console window. Print something, hope it helps. |
| 77 | print 'update' |
| 78 | else: |
| 79 | Qd.SetPort(whichWindow) |
| 80 | whichWindow.BeginUpdate() |
| 81 | Qd.EraseRect(whichWindow.GetWindowPort().portRect) |
| 82 | whichWindow.EndUpdate() |
| 83 | |
| 84 | def loadMovie(theFile): |
| 85 | """Load a movie given an fsspec. Return the movie object""" |
| 86 | movieResRef = Qt.OpenMovieFile(theFile, 1) |
Jack Jansen | 1836a62 | 1997-04-09 15:54:54 +0000 | [diff] [blame] | 87 | movie, d1, d2 = Qt.NewMovieFromFile(movieResRef, 0, QuickTime.newMovieActive) |
Jack Jansen | 9cfea10 | 1995-12-09 14:05:56 +0000 | [diff] [blame] | 88 | return movie |
| 89 | |
| 90 | if __name__ == '__main__': |
| 91 | main() |
| 92 | |