Package libavg :: Module AVGAppUtil

Source Code for Module libavg.AVGAppUtil

 1  # libavg - Media Playback Engine. 
 2  # Copyright (C) 2003-2008 Ulrich von Zadow 
 3  # 
 4  # This library is free software; you can redistribute it and/or 
 5  # modify it under the terms of the GNU Lesser General Public 
 6  # License as published by the Free Software Foundation; either 
 7  # version 2 of the License, or (at your option) any later version. 
 8  # 
 9  # This library is distributed in the hope that it will be useful, 
10  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12  # Lesser General Public License for more details. 
13  # 
14  # You should have received a copy of the GNU Lesser General Public 
15  # License along with this library; if not, write to the Free Software 
16  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
17  # 
18  # Current versions can be found at www.libavg.de 
19  # 
20  # Original author of this file is Martin Heistermann <mh at sponc dot de> 
21  # 
22   
23  import os 
24  from libavg import avg 
25  from . import mathutil 
26   
27  g_player = avg.Player.get() 
28   
29 -def getMediaDir(_file_, subdir='media'):
30 """call with _file_=__file__""" 31 myDir = os.path.dirname(_file_) 32 mediaDir = os.path.join(myDir, subdir) 33 return os.path.abspath(mediaDir)
34
35 -def getMediaDirFromNode(node, path=''):
36 ''' 37 Recursively build the mediadir path, starting from the given node. 38 ''' 39 if node.getParent(): 40 return getMediaDirFromNode(node.getParent(), os.path.join(node.mediadir, path)) 41 else: 42 return path
43
44 -def createImagePreviewNode(maxSize, absHref):
45 node = g_player.createNode('image', {'href': absHref}) 46 node.size = mathutil.getScaledDim(node.size, max = maxSize) 47 return node
48