Refactoring for fileConfig. Contributed by Shane Hathaway.
[python.git] / Mac / Tools / IDE / Wquicktime.py
blob671aa0964b3c2a3f3bde73c5ce485b9337ef3968
1 import os
2 from Carbon import Qd
3 from Carbon import Win
4 from Carbon import Qt, QuickTime
5 import W
6 from Carbon import File
7 from Carbon import Evt, Events
9 _moviesinitialized = 0
11 def EnterMovies():
12 global _moviesinitialized
13 if not _moviesinitialized:
14 Qt.EnterMovies()
15 _moviesinitialized = 1
17 class Movie(W.Widget):
19 def __init__(self, possize):
20 EnterMovies()
21 self.movie = None
22 self.running = 0
23 W.Widget.__init__(self, possize)
25 def adjust(self, oldbounds):
26 self.SetPort()
27 self.GetWindow().InvalWindowRect(oldbounds)
28 self.GetWindow().InvalWindowRect(self._bounds)
29 self.calcmoviebox()
31 def set(self, path_or_fss, start = 0):
32 self.SetPort()
33 if self.movie:
34 #self.GetWindow().InvalWindowRect(self.movie.GetMovieBox())
35 Qd.PaintRect(self.movie.GetMovieBox())
36 path = File.pathname(path)
37 self.movietitle = os.path.basename(path)
38 movieResRef = Qt.OpenMovieFile(path_or_fss, 1)
39 self.movie, dummy, dummy = Qt.NewMovieFromFile(movieResRef, 0, QuickTime.newMovieActive)
40 self.moviebox = self.movie.GetMovieBox()
41 self.calcmoviebox()
42 Qd.ObscureCursor() # XXX does this work at all?
43 self.movie.GoToBeginningOfMovie()
44 if start:
45 self.movie.StartMovie()
46 self.running = 1
47 else:
48 self.running = 0
49 self.movie.MoviesTask(0)
51 def get(self):
52 return self.movie
54 def getmovietitle(self):
55 return self.movietitle
57 def start(self):
58 if self.movie:
59 Qd.ObscureCursor()
60 self.movie.StartMovie()
61 self.running = 1
63 def stop(self):
64 if self.movie:
65 self.movie.StopMovie()
66 self.running = 0
68 def rewind(self):
69 if self.movie:
70 self.movie.GoToBeginningOfMovie()
72 def calcmoviebox(self):
73 if not self.movie:
74 return
75 ml, mt, mr, mb = self.moviebox
76 wl, wt, wr, wb = widgetbox = self._bounds
77 mheight = mb - mt
78 mwidth = mr - ml
79 wheight = wb - wt
80 wwidth = wr - wl
81 if (mheight * 2 < wheight) and (mwidth * 2 < wwidth):
82 scale = 2
83 elif mheight > wheight or mwidth > wwidth:
84 scale = min(float(wheight) / mheight, float(wwidth) / mwidth)
85 else:
86 scale = 1
87 mwidth, mheight = mwidth * scale, mheight * scale
88 ml, mt = wl + (wwidth - mwidth) / 2, wt + (wheight - mheight) / 2
89 mr, mb = ml + mwidth, mt + mheight
90 self.movie.SetMovieBox((ml, mt, mr, mb))
92 def idle(self, *args):
93 if self.movie:
94 if not self.movie.IsMovieDone() and self.running:
95 Qd.ObscureCursor()
96 while 1:
97 self.movie.MoviesTask(0)
98 gotone, event = Evt.EventAvail(Events.everyEvent)
99 if gotone or self.movie.IsMovieDone():
100 break
101 elif self.running:
102 box = self.movie.GetMovieBox()
103 self.SetPort()
104 self.GetWindow().InvalWindowRect(box)
105 self.movie = None
106 self.running = 0
108 def draw(self, visRgn = None):
109 if self._visible:
110 Qd.PaintRect(self._bounds)
111 if self.movie:
112 self.movie.UpdateMovie()
113 self.movie.MoviesTask(0)