def do_arm(self, node, same=0): self.__ready = 0 node.__type = '' self.__maxsoundlevel = 1.0 if node.type != 'ext': self.errormsg(node, 'Node must be external.') return 1 url = self.getfileurl(node) if not url: self.errormsg(node, 'No URL set on node.') return 1 mtype = node.GetAttrDef('type', None) if not mtype: import urlcache mtype = urlcache.mimetype(url) if mtype and mtype.find('real') >= 0: node.__type = 'real' if self.__rc is None: try: self.__rc = RealChannel.RealChannel(self) except RealChannel.error, msg: # can't do RealAudio ## self.__rc = 0 # don't try again self.errormsg(node, msg) if self.__rc: if self.__rc.prepare_player(node): self.__ready = 1
def getintrinsicduration(node, wanterror): if node.GetType() not in ('ext', 'imm'): # catch all for brush, prefetch, etc. return 0 url = node.GetFile() cache = urlcache.urlcache[url] dur = cache.get('duration') if dur is not None: return dur # we hadn't cached the duration, do the hard work # first figure out MIME type mtype = urlcache.mimetype(url) if mtype is None: # MIME type can't be found return 0 maintype, subtype = mtype.split('/') # now figure out duration depending on type if string.find(subtype, 'real') >= 0 or string.find(subtype, 'shockwave') >= 0: if platform == 'win32': import RealDuration try: dur = RealDuration.get(url) except IOError, msg: if wanterror: raise IOError, msg if __debug__: print url, msg return 0 else: import realsupport info = realsupport.getinfo(url) dur = info.get('duration', 0)
def getfullinfo(url): import urlcache cache = urlcache.urlcache[url] duration = cache.get('duration') if duration is None: mtype = urlcache.mimetype(url) if mtype and (mtype.find('x-aiff') >= 0 or mtype.find('quicktime') >= 0): import winqt if winqt.HasQtSupport(): try: fn = MMurl.urlretrieve(url)[0] except IOError, arg: print arg else: player = winqt.QtPlayer() player.open(fn) duration = player.getDuration() if not duration: url = MMurl.canonURL(url) url = MMurl.unquote(url) import win32dxm duration = win32dxm.GetMediaDuration(url) if duration < 0: duration = 0 cache['duration'] = duration
def do_arm(self, node, same=0): self.__ready = 0 node.__type = '' if node.type != 'ext': self.errormsg(node, 'Node must be external.') return 1 if debug: print 'SoundChannel: arm', node fn = self.getfileurl(node) if not fn: self.errormsg(node, 'No URL set on node.') return 1 mtype = node.GetAttrDef('type', None) if not mtype: import urlcache mtype = urlcache.mimetype(fn) if mtype and string.find(mtype, 'real') >= 0: node.__type = 'real' if self.__rc is None: import RealChannel try: self.__rc = RealChannel.RealChannel(self) except RealChannel.error, msg: # can't do RealAudio ## self.__rc = 0 # don't try again self.errormsg(node, msg) if self.__rc: if self.__rc.prepare_player(node): self.__ready = 1 return 1
def dropfile(self, arg, window, event, value): x,y,filename=value url=MMurl.pathname2url(filename) import urlcache, windowinterface mimetype = urlcache.mimetype(url) if mimetype in ('application/x-grins-project', 'application/smil', 'application/smil+xml', 'application/x-grins-cmif'): self.openURL_callback(url) else: windowinterface.showmessage('Only GRiNS or SMIL files can be dropped.')
def dropeffect(self, dummy, window, event, params): x,y,filename=params url=MMurl.pathname2url(filename) import urlcache, windowinterface mimetype = urlcache.mimetype(url) if mimetype in ('application/x-grins-project', 'application/smil', 'application/smil+xml', 'application/x-grins-cmif'): return windowinterface.DROPEFFECT_COPY else: return windowinterface.DROPEFFECT_NONE
def dropfile(self, arg, window, event, value): if not self.canopennewtop(): return x, y, filename = value url = self.__path2url(filename) import urlcache mimetype = urlcache.mimetype(url) if mimetype in ('application/x-grins-project', 'application/smil', 'application/smil+xml'): self.openURL_callback(url) else: import windowinterface windowinterface.showmessage( 'Only GRiNS or SMIL files can be dropped.')
def GetSize(url, maintype=None, subtype=None): if not url: return 0, 0 cache = urlcache.urlcache[url] width = cache.get('width') height = cache.get('height') if width is not None and height is not None: return width, height u = None if maintype is None: mtype = urlcache.mimetype(url) if not mtype: return 0, 0 maintype, subtype = mtype.split('/') if string.find(string.lower(subtype), 'real') >= 0 or string.find( subtype, 'shockwave') >= 0: # any RealMedia type import realsupport info = realsupport.getinfo(url, u) width = info.get('width', 0) height = info.get('height', 0) elif maintype == 'image': if u is not None: u.close() del u import ChannelMap if ChannelMap.channelmap.has_key('svg') and subtype == 'svg-xml': width, height = GetSvgSize(url) else: try: file = MMurl.urlretrieve(url)[0] except IOError: return 0, 0 width, height = GetImageSize(file) elif maintype == 'video': if u is not None: u.close() del u width, height = GetVideoSize(url) else: width = height = 0 if width != 0 and height != 0: cache['width'] = width cache['height'] = height return width, height
def do_arm(self, node, same=0): self.__ready = 0 if same and self.armed_display: self.__ready = 1 return 1 node.__type = '' node.__subtype = '' if node.type != 'ext': self.errormsg(node, 'Node must be external.') return 1 url = self.getfileurl(node) if not url: self.errormsg(node, 'No URL set on node.') return 1 mtype = node.GetAttrDef('type', None) if not mtype: import urlcache mtype = urlcache.mimetype(url) if mtype and (mtype.find('real') >= 0 or mtype.find('flash') >= 0 or mtype.find('image') >= 0): node.__type = 'real' if mtype not in ('image/vnd.rn-realpix', 'text/vnd.rn-realtext'): self.__windowless_real_rendering = 0 if mtype.find('flash') >= 0: node.__subtype = 'flash' elif mtype and mtype.find('quicktime') >= 0: node.__type = 'qt' else: node.__type = 'wm' if mtype and mtype.find('x-ms-asf') >= 0: node.__subtype = 'asf' if not self._exporter: self.__windowless_wm_rendering = 0 if node.__type == 'real': if self.__rc is None: try: self.__rc = RealChannel.RealChannel(self) except RealChannel.error, msg: # can't do RealAudio ## self.__rc = 0 # don't try again self.errormsg(node, msg) if self.__rc: if self.__rc.prepare_player(node): self.__ready = 1
def __dragfile(self, dummy, window, event, params): # event handler for mouse moves while dragging a file over the window. self.droppable_widget = None x, y, filename = params if not (0 <= x < 1 and 0 <= y < 1): self.draw() return windowinterface.DROPEFFECT_NONE x = x * self.mcanvassize[0] y = y * self.mcanvassize[1] obj = self.whichhit(x, y) # On the grey area we fail if not obj: rv = windowinterface.DROPEFFECT_NONE self.draw() return obj = obj.get_mmwidget() node = obj.get_node() # If the node accepts only certain mimetypes # we check for that too. mimetypes = node.getAllowedMimeTypes() if mimetypes: if event == WMEVENTS.DropFile: url = MMurl.pathname2url(filename) else: url = filename import urlcache mimetype = urlcache.mimetype(url) if mimetype: mimetype = string.split(mimetype, '/')[0] if not mimetype in mimetypes: if __debug__: print 'Type', mimetype, 'not in', mimetypes self.draw() return windowinterface.DROPEFFECT_NONE # All seems fine. Return copy or link depending on # the node type. if node.GetType() in MMNode.playabletypes: self.droppable_widget = obj rv = windowinterface.DROPEFFECT_LINK else: self.droppable_widget = obj rv = windowinterface.DROPEFFECT_COPY self.draw() return rv
def get(url): import urlcache cache = urlcache.urlcache[url] dur = cache.get('duration') if dur is None: mtype = urlcache.mimetype(url) if mtype and mtype.find('quicktime') >= 0: import winqt if winqt.HasQtSupport(): try: fn = MMurl.urlretrieve(url)[0] except IOError, arg: print arg return 0 player = winqt.QtPlayer() player.open(fn) dur = player.getDuration() if dur is None: # still unknown dur = win32dxm.GetMediaDuration(url)
def get(url): import urlcache cache = urlcache.urlcache[url] dur = cache.get('duration') if dur is None: mtype = urlcache.mimetype(url) if mtype and mtype.find('mpeg') >= 0: try: fn = MMurl.urlretrieve(url)[0] except IOError, arg: print arg dur = 10 else: try: windowinterface.setwaiting() dur = winmm.GetVideoDuration(fn) except winmm.error, msg: print msg dur = 10
def getstreamdata(node, target=0): ntype = node.GetType() if ntype not in ('ext', 'slide'): # Nodes that are not external consume no bandwidth return 0, 0, 0, 0 if ntype == 'slide': raise Error, 'Cannot compute bandwidth for slide.' context = node.GetContext() ctype = node.GetChannelType() if ntype == 'ext' and ctype == 'RealPix': # Get information from the attributes bitrate = MMAttrdefs.getattr(node, 'bitrate') # XXX Incorrect return 0, bitrate, bitrate, 0 url = MMAttrdefs.getattr(node, 'file') if not url or url == '#': # Special case for empty URLs return 0, 0, 0, 0 url = context.findurl(url) val = urlcache.urlcache[url].get('bandwidth') if val is not None: return val # We skip bandwidth retrieval for nonlocal urls (too expensive) type, rest = MMurl.splittype(url) if type and type != 'file': ## print "DBG: Bandwidth.get: skip nonlocal", url return None, None, None, None host, rest = MMurl.splithost(rest) if host and host != 'localhost': ## print "DBG: Bandwidth.get: skip nonlocal", url return None, None, None, None mtype = urlcache.mimetype(url) if not mtype: raise Error, 'Cannot open: %s' % url maintype, subtype = mtype.split('/') if string.find(subtype, 'real') >= 0: # For real channels we parse the header and such # XXXX If we want to do real-compatible calculations # we have to take preroll time and such into account. import realsupport info = realsupport.getinfo(url) bandwidth = 0 if info.has_key('bitrate'): bandwidth = info['bitrate'] if info.has_key('preroll'): prerolltime = info['preroll'] else: prerolltime = DEFAULT_STREAMING_MEDIA_PRELOAD prerollbits = prerolltime * bandwidth ## print "DBG: Bandwidth.get: real:", url, prearm, bandwidth urlcache.urlcache[url][ 'bandwidth'] = prerollbits, prerolltime, bandwidth, bandwidth return prerollbits, prerolltime, bandwidth, bandwidth if maintype == 'audio' or maintype == 'video': targets = MMAttrdefs.getattr(node, 'project_targets') bitrate = TARGET_BITRATES[0] # default: 28k8 modem for i in range(len(TARGET_BITRATES)): if targets & (1 << i): bitrate = TARGET_BITRATES[i] # don't cache since the result depends on project_targets prerollseconds = DEFAULT_STREAMING_MEDIA_PRELOAD prerollbits = prerollseconds * bitrate return prerollbits, prerollseconds, bitrate, bitrate # XXXX Need to pass more args (crop, etc) attrs = {'project_quality': MMAttrdefs.getattr(node, 'project_quality')} filesize = GetSize(url, target, attrs, MMAttrdefs.getattr(node, 'project_convert')) if filesize is None: return None, None, None, None ## print 'DBG: Bandwidth.get: discrete',filename, filesize, float(filesize)*8 bits = float(filesize) * 8 prerollbitrate = MMAttrdefs.getattr(node, 'strbitrate') ## Don't cache: user may change strbitrate property ## urlcache.urlcache[url]['bandwidth'] = bits, None, prerollbitrate, None return bits, None, prerollbitrate, None
def jumptoexternal(self, srcanchor, anchor, atype, stype=A_SRC_PLAY, dtype=A_DEST_PLAY): # XXXX Should check that document isn't active already, # XXXX and, if so, should jump that instance of the # XXXX document. if type(anchor) is type(''): url, aid = MMurl.splittag(anchor) url = MMurl.basejoin(self.filename, url) # Check whether it's a control anchor proto, command = MMurl.splittype(url) if proto == 'grins': return self.commandurl(command) else: url = self.filename for aid, uid in self.root.SMILidmap.items(): if uid == anchor.GetUID(): break else: # XXX can't find the SMIL name, guess... aid = MMAttrdefs.getattr(anchor, 'name') # by default, the document target will be handled by GRiNS # note: this varib allow to manage correctly the sourcePlaystate attribute # as well, even if the target document is not handled by GRiNS grinsTarget = 1 for top in self.main.tops: if top is not self and top.is_document(url): break else: try: # if the destination document is not a smil/grins document, # it's handle by an external application import urlcache mtype = urlcache.mimetype(url) utype, url2 = MMurl.splittype(url) if mtype in ( 'application/smil', 'application/smil+xml', 'application/x-grins-project', ## 'application/x-grins-cmif', ): # in this case, the document is handle by grins top = TopLevel(self.main, url) else: grinsTarget = 0 windowinterface.shell_execute(url) except: msg = sys.exc_value if type(msg) is type(self): if hasattr(msg, 'strerror'): msg = msg.strerror else: msg = msg.args[0] windowinterface.showmessage('Cannot open: ' + url + '\n\n' + ` msg `) return 0 if grinsTarget: top.show() # update the recent list. if self.main != None: self.main._update_recent(None) node = top.root if hasattr(node, 'SMILidmap') and node.SMILidmap.has_key(aid): uid = node.SMILidmap[aid] node = node.context.mapuid(uid) if dtype == A_DEST_PLAY: top.player.show() top.player.playfromanchor(node) elif dtype == A_DEST_PAUSE: top.player.show() top.player.playfromanchor(node) top.player.pause(1) else: print 'jump to external: invalid destination state' if atype == TYPE_JUMP: if grinsTarget: self.close() else: # The hide method doesn't work fine. # So, for now stop only the player, instead to hide the window self.player.stop() elif atype == TYPE_FORK: if stype == A_SRC_PLAY: pass elif stype == A_SRC_PAUSE: self.player.pause(1) elif stype == A_SRC_STOP: self.player.stop() else: print 'jump to external: invalid source state' return 1
def read_it(self): ## import time self.changed = 0 ## print 'parsing', self.filename, '...' ## t0 = time.time() import urlcache mtype = urlcache.mimetype(self.filename) if mtype not in ('application/x-grins-project', 'application/smil', 'application/smil+xml', 'application/x-grins-binary-project') and ( not hasattr(windowinterface, 'is_embedded') or not windowinterface.is_embedded()): ans = windowinterface.GetYesNoCancel( 'MIME type not application/smil or application/x-grins-project.\nOpen as SMIL document anyway?' ) if ans == 0: # yes mtype = 'application/smil' elif ans == 2: # cancel raise IOError('user request') if mtype in ('application/x-grins-project', 'application/smil', 'application/smil+xml'): # init progress dialog if mtype in ('application/smil', 'application/smil+xml'): self.progress = windowinterface.ProgressDialog("Loading") self.progressMessage = "Loading SMIL document..." else: self.progress = windowinterface.ProgressDialog("Loading") self.progressMessage = "Loading GRiNS document..." try: import SMILTreeRead self.root = SMILTreeRead.ReadFile(self.filename, self.printfunc, \ progressCallback=(self.progressCallback, 0)) except (UserCancel, IOError): # the progress dialog will desapear self.progress = None # re-raise raise sys.exc_type # just update that the loading is finished self.progressCallback(1.0) # the progress dialog will disappear if sys.platform == 'wince': self.progress.close() self.progress = None elif mtype == 'application/x-grins-binary-project': self.progress = windowinterface.ProgressDialog("Loading") self.progressMessage = "Loading GRiNS document..." import QuickRead self.root = QuickRead.ReadFile( self.filename, progressCallback=(self.progressCallback, 0.5)) self.progressCallback(1.0) if sys.platform == 'wince': self.progress.close() self.progress = None ## elif mtype == 'application/x-grins-cmif': ## import MMRead ## self.root = MMRead.ReadFile(self.filename) else: from MediaRead import MediaRead self.root = MediaRead(self.filename, mtype, self.printfunc) ## t1 = time.time() ## print 'done in', round(t1-t0, 3), 'sec.' self.context = self.root.GetContext() if sys.platform == 'wince': errors = self.context.getParseErrors() if errors is not None: if errors.getType() == 'fatal': msg = 'Fatal error' else: msg = 'Error' logfile = r'\My Documents\GRiNS Error Log.txt' f = open(logfile, 'w') f.write(errors.getFormatedErrorsMessage()) f.close() windowinterface.showmessage('%s logged in %s' % (msg, logfile))