ยปCore Development>Code coverage>Mac/Demo/quicktime/VerySimplePlayer.py

Python code coverage for Mac/Demo/quicktime/VerySimplePlayer.py

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