annotate Mac/Demo/quicktime/VerySimplePlayer.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents c3a096bfbd6b
children dcedd32f06de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3293
bafc105bc7cd It now actually works. Also, MovieInWindow and VerySimplePlayer
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 """VerySimplePlayer converted to python
bafc105bc7cd It now actually works. Also, MovieInWindow and VerySimplePlayer
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2
bafc105bc7cd It now actually works. Also, MovieInWindow and VerySimplePlayer
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 Jack Jansen, CWI, December 1995
bafc105bc7cd It now actually works. Also, MovieInWindow and VerySimplePlayer
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4 """
bafc105bc7cd It now actually works. Also, MovieInWindow and VerySimplePlayer
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5
19488
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18269
diff changeset
6 from Carbon import Qt
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18269
diff changeset
7 from Carbon import QuickTime
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18269
diff changeset
8 from Carbon import Qd
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18269
diff changeset
9 from Carbon import QuickDraw
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18269
diff changeset
10 from Carbon import Evt
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18269
diff changeset
11 from Carbon import Events
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18269
diff changeset
12 from Carbon import Win
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 18269
diff changeset
13 from Carbon import Windows
27406
caa6df9e0880 Use new file dialogs.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26466
diff changeset
14 from Carbon import File
caa6df9e0880 Use new file dialogs.
Jack Jansen <jack.jansen@cwi.nl>
parents: 26466
diff changeset
15 import EasyDialogs
3293
bafc105bc7cd It now actually works. Also, MovieInWindow and VerySimplePlayer
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
16 import sys
bafc105bc7cd It now actually works. Also, MovieInWindow and VerySimplePlayer
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17
bafc105bc7cd It now actually works. Also, MovieInWindow and VerySimplePlayer
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 # XXXX maxbounds = (40, 40, 1000, 1000)
bafc105bc7cd It now actually works. Also, MovieInWindow and VerySimplePlayer
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19
bafc105bc7cd It now actually works. Also, MovieInWindow and VerySimplePlayer
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20 def main():
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
21 print 'hello world' # XXXX
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
22 # skip the toolbox initializations, already done
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
23 # XXXX Should use gestalt here to check for quicktime version
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
24 Qt.EnterMovies()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
25
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
26 # Get the movie file
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
27 fss = EasyDialogs.AskFileForOpen(wanted=File.FSSpec) # Was: QuickTime.MovieFileType
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
28 if not fss:
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
29 sys.exit(0)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
30
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
31 # Open the window
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
32 bounds = (175, 75, 175+160, 75+120)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
33 theWindow = Win.NewCWindow(bounds, fss.as_tuple()[2], 0, 0, -1, 1, 0)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
34 # XXXX Needed? SetGWorld((CGrafPtr)theWindow, nil)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
35 Qd.SetPort(theWindow)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
36
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
37 # Get the movie
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
38 theMovie = loadMovie(fss)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
39
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
40 # Relocate to (0, 0)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
41 bounds = theMovie.GetMovieBox()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
42 bounds = 0, 0, bounds[2]-bounds[0], bounds[3]-bounds[1]
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
43 theMovie.SetMovieBox(bounds)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
44
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
45 # Create a controller
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
46 theController = theMovie.NewMovieController(bounds, QuickTime.mcTopLeftMovie)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
47
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
48 # Get movie size and update window parameters
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
49 rv, bounds = theController.MCGetControllerBoundsRect()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
50 theWindow.SizeWindow(bounds[2], bounds[3], 0) # XXXX or [3] [2]?
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
51 Qt.AlignWindow(theWindow, 0)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
52 theWindow.ShowWindow()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
53
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
54 # XXXX MCDoAction(theController, mcActionSetGrowBoxBounds, &maxBounds)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
55 theController.MCDoAction(QuickTime.mcActionSetKeysEnabled, '1')
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
56
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
57 # XXXX MCSetActionFilterWithRefCon(theController, movieControllerEventFilter, (long)theWindow)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
58
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
59 done = 0
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
60 while not done:
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
61 gotone, evt = Evt.WaitNextEvent(0xffff, 0)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
62 (what, message, when, where, modifiers) = evt
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
63 ## print what, message, when, where, modifiers # XXXX
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
64
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
65 if theController.MCIsPlayerEvent(evt):
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
66 continue
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
67
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
68 if what == Events.mouseDown:
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
69 part, whichWindow = Win.FindWindow(where)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
70 if part == Windows.inGoAway:
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
71 done = whichWindow.TrackGoAway(where)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
72 elif part == Windows.inDrag:
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
73 Qt.DragAlignedWindow(whichWindow, where, (0, 0, 4000, 4000))
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
74 elif what == Events.updateEvt:
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
75 whichWindow = Win.WhichWindow(message)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
76 if not whichWindow:
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
77 # Probably the console window. Print something, hope it helps.
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
78 print 'update'
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
79 else:
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
80 Qd.SetPort(whichWindow)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
81 whichWindow.BeginUpdate()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
82 Qd.EraseRect(whichWindow.GetWindowPort().GetPortBounds())
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
83 whichWindow.EndUpdate()
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
84
3293
bafc105bc7cd It now actually works. Also, MovieInWindow and VerySimplePlayer
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
85 def loadMovie(theFile):
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
86 """Load a movie given an fsspec. Return the movie object"""
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
87 movieResRef = Qt.OpenMovieFile(theFile, 1)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
88 movie, d1, d2 = Qt.NewMovieFromFile(movieResRef, 0, QuickTime.newMovieActive)
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
89 return movie
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
90
3293
bafc105bc7cd It now actually works. Also, MovieInWindow and VerySimplePlayer
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
91 if __name__ == '__main__':
32736
c3a096bfbd6b Whitespace normalization, via reindent.py.
Tim Peters <tim.peters@gmail.com>
parents: 27406
diff changeset
92 main()