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