/usr/share/pyshared/libavg/utils.py is in python-libavg 1.7.1-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | # libavg - Media Playback Engine.
# Copyright (C) 2003-2011 Ulrich von Zadow
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Current versions can be found at www.libavg.de
#
# Original author of this file is Martin Heistermann <mh at sponc dot de>
#
import os
import weakref, new
from libavg import avg, mathutil
g_Player = avg.Player.get()
def getMediaDir(_file_, subdir='media'):
"""call with _file_=__file__"""
myDir = os.path.dirname(_file_)
mediaDir = os.path.join(myDir, subdir)
return os.path.abspath(mediaDir)
def getMediaDirFromNode(node, path=''):
'''
Recursively build the mediadir path, starting from the given node.
'''
if node.getParent():
if type(node) in (avg.DivNode, avg.AVGNode):
return getMediaDirFromNode(node.getParent(), os.path.join(node.mediadir, path))
else:
return getMediaDirFromNode(node.getParent(), path)
else:
return path
def createImagePreviewNode(maxSize, absHref):
node = g_Player.createNode('image', {'href': absHref})
node.size = mathutil.getScaledDim(node.size, max = maxSize)
return node
def initFXCache(numFXNodes):
nodes = []
mediadir = os.path.join(os.path.dirname(__file__), 'data')
for i in range(numFXNodes):
node = avg.ImageNode(href=mediadir+"/black.png",
parent=g_Player.getRootNode())
node.setEffect(avg.NullFXNode())
nodes.append(node)
for node in nodes:
node.unlink(True)
class methodref(object):
# From Python Cookbook
""" Wraps any callable, most importantly a bound method, in a way that allows a bound
method's object to be GC'ed, while providing the same interface as a normal weak
reference."""
def __init__(self, fn):
try:
# Try getting object, function and class
o, f, c = fn.im_self, fn.im_func, fn.im_class
except AttributeError:
# It's not a bound method
self._obj = None
self._func = fn
self._clas = None
else:
# Bound method
if o is None: # ... actually UN-bound
self._obj = None
else:
self._obj = weakref.ref(o)
self._func = f
self._clas = c
def __call__(self):
if self._obj is None:
return self._func
elif self._obj() is None:
return None
return new.instancemethod(self._func, self._obj(), self._clas)
def callWeakRef(ref, *args, **kwargs):
func = ref()
if func is None:
return
else:
return func(*args, **kwargs)
|