blob: 7170cd7a34164c2f09898dc1d53cc082183f4b38 [file] [log] [blame]
Just van Rossum40f9b7b1999-01-30 22:39:17 +00001import os
Jack Jansen5a6fdcd2001-08-25 12:15:04 +00002from Carbon import Qd
3from Carbon import Win
4from Carbon import Qt, QuickTime
Just van Rossum40f9b7b1999-01-30 22:39:17 +00005import W
6import macfs
Jack Jansen5a6fdcd2001-08-25 12:15:04 +00007from Carbon import Evt, Events
Just van Rossum40f9b7b1999-01-30 22:39:17 +00008
9_moviesinitialized = 0
10
11def EnterMovies():
12 global _moviesinitialized
13 if not _moviesinitialized:
14 Qt.EnterMovies()
15 _moviesinitialized = 1
16
17class Movie(W.Widget):
18
19 def __init__(self, possize):
20 EnterMovies()
21 self.movie = None
22 self.running = 0
23 W.Widget.__init__(self, possize)
24
25 def adjust(self, oldbounds):
26 self.SetPort()
Jack Jansen73023402001-01-23 14:58:20 +000027 self.GetWindow().InvalWindowRect(oldbounds)
28 self.GetWindow().InvalWindowRect(self._bounds)
Just van Rossum40f9b7b1999-01-30 22:39:17 +000029 self.calcmoviebox()
30
31 def set(self, path_or_fss, start = 0):
32 self.SetPort()
33 if self.movie:
Jack Jansen73023402001-01-23 14:58:20 +000034 #self.GetWindow().InvalWindowRect(self.movie.GetMovieBox())
Just van Rossum40f9b7b1999-01-30 22:39:17 +000035 Qd.PaintRect(self.movie.GetMovieBox())
36 if type(path_or_fss) == type(''):
37 path = path_or_fss
38 fss = macfs.FSSpec(path)
39 else:
40 path = path_or_fss.as_pathname()
41 fss = path_or_fss
42 self.movietitle = os.path.basename(path)
43 movieResRef = Qt.OpenMovieFile(fss, 1)
44 self.movie, dummy, dummy = Qt.NewMovieFromFile(movieResRef, 0, QuickTime.newMovieActive)
45 self.moviebox = self.movie.GetMovieBox()
46 self.calcmoviebox()
47 Qd.ObscureCursor() # XXX does this work at all?
48 self.movie.GoToBeginningOfMovie()
49 if start:
50 self.movie.StartMovie()
51 self.running = 1
52 else:
53 self.running = 0
54 self.movie.MoviesTask(0)
55
56 def get(self):
57 return self.movie
58
59 def getmovietitle(self):
60 return self.movietitle
61
62 def start(self):
63 if self.movie:
64 Qd.ObscureCursor()
65 self.movie.StartMovie()
66 self.running = 1
67
68 def stop(self):
69 if self.movie:
70 self.movie.StopMovie()
71 self.running = 0
72
73 def rewind(self):
74 if self.movie:
75 self.movie.GoToBeginningOfMovie()
76
77 def calcmoviebox(self):
78 if not self.movie:
79 return
80 ml, mt, mr, mb = self.moviebox
81 wl, wt, wr, wb = widgetbox = self._bounds
82 mheight = mb - mt
83 mwidth = mr - ml
84 wheight = wb - wt
85 wwidth = wr - wl
86 if (mheight * 2 < wheight) and (mwidth * 2 < wwidth):
87 scale = 2
88 elif mheight > wheight or mwidth > wwidth:
89 scale = min(float(wheight) / mheight, float(wwidth) / mwidth)
90 else:
91 scale = 1
92 mwidth, mheight = mwidth * scale, mheight * scale
93 ml, mt = wl + (wwidth - mwidth) / 2, wt + (wheight - mheight) / 2
94 mr, mb = ml + mwidth, mt + mheight
95 self.movie.SetMovieBox((ml, mt, mr, mb))
96
97 def idle(self, *args):
98 if self.movie:
99 if not self.movie.IsMovieDone() and self.running:
100 Qd.ObscureCursor()
101 while 1:
102 self.movie.MoviesTask(0)
103 gotone, event = Evt.EventAvail(Events.everyEvent)
104 if gotone or self.movie.IsMovieDone():
105 break
106 elif self.running:
107 box = self.movie.GetMovieBox()
108 self.SetPort()
Jack Jansen73023402001-01-23 14:58:20 +0000109 self.GetWindow().InvalWindowRect(box)
Just van Rossum40f9b7b1999-01-30 22:39:17 +0000110 self.movie = None
111 self.running = 0
112
113 def draw(self, visRgn = None):
114 if self._visible:
115 Qd.PaintRect(self._bounds)
116 if self.movie:
117 self.movie.UpdateMovie()
118 self.movie.MoviesTask(0)
119