summaryrefslogtreecommitdiffstats
path: root/Mac/Tools/IDE/Wquicktime.py
blob: a33462a9b68b137fb187101da14fa932df6b1dc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import os
import Qd
import Win
import Qt, QuickTime
import W
import macfs
import Evt, Events

_moviesinitialized = 0

def EnterMovies():
	global _moviesinitialized
	if not _moviesinitialized:
		Qt.EnterMovies()
		_moviesinitialized = 1

class Movie(W.Widget):
	
	def __init__(self, possize):
		EnterMovies()
		self.movie = None
		self.running = 0
		W.Widget.__init__(self, possize)
	
	def adjust(self, oldbounds):
		self.SetPort()
		Win.InvalRect(oldbounds)
		Win.InvalRect(self._bounds)
		self.calcmoviebox()
	
	def set(self, path_or_fss, start = 0):
		self.SetPort()
		if self.movie:
			#Win.InvalRect(self.movie.GetMovieBox())
			Qd.PaintRect(self.movie.GetMovieBox())
		if type(path_or_fss) == type(''):
			path = path_or_fss
			fss = macfs.FSSpec(path)
		else:
			path = path_or_fss.as_pathname()
			fss = path_or_fss
		self.movietitle = os.path.basename(path)
		movieResRef = Qt.OpenMovieFile(fss, 1)
		self.movie, dummy, dummy = Qt.NewMovieFromFile(movieResRef, 0, QuickTime.newMovieActive)
		self.moviebox = self.movie.GetMovieBox()
		self.calcmoviebox()
		Qd.ObscureCursor()	# XXX does this work at all?
		self.movie.GoToBeginningOfMovie()
		if start:
			self.movie.StartMovie()
			self.running = 1
		else:
			self.running = 0
			self.movie.MoviesTask(0)
	
	def get(self):
		return self.movie
	
	def getmovietitle(self):
		return self.movietitle
	
	def start(self):
		if self.movie:
			Qd.ObscureCursor()
			self.movie.StartMovie()
			self.running = 1
	
	def stop(self):
		if self.movie:
			self.movie.StopMovie()
			self.running = 0
	
	def rewind(self):
		if self.movie:
			self.movie.GoToBeginningOfMovie()
	
	def calcmoviebox(self):
		if not self.movie:
			return
		ml, mt, mr, mb = self.moviebox
		wl, wt, wr, wb = widgetbox = self._bounds
		mheight = mb - mt
		mwidth = mr - ml
		wheight = wb - wt
		wwidth = wr - wl
		if (mheight * 2 < wheight) and (mwidth * 2 < wwidth):
			scale = 2
		elif mheight > wheight or mwidth > wwidth:
			scale = min(float(wheight) / mheight, float(wwidth) / mwidth)
		else:
			scale = 1
		mwidth, mheight = mwidth * scale, mheight * scale
		ml, mt = wl + (wwidth - mwidth) / 2, wt + (wheight - mheight) / 2
		mr, mb = ml + mwidth, mt + mheight
		self.movie.SetMovieBox((ml, mt, mr, mb))
	
	def idle(self, *args):
		if self.movie:
			if not self.movie.IsMovieDone() and self.running:
				Qd.ObscureCursor()
				while 1:
					self.movie.MoviesTask(0)
					gotone, event = Evt.EventAvail(Events.everyEvent)
					if gotone or self.movie.IsMovieDone():
						break
			elif self.running:
				box = self.movie.GetMovieBox()
				self.SetPort()
				Win.InvalRect(box)
				self.movie = None
				self.running = 0
	
	def draw(self, visRgn = None):
		if self._visible:
			Qd.PaintRect(self._bounds)
			if self.movie:
				self.movie.UpdateMovie()
				self.movie.MoviesTask(0)