1# -*- coding: utf-8 -*- 2# 3# PhotoFilmStrip - Creates movies out of your pictures. 4# 5# Copyright (C) 2011 Jens Goepfert 6# 7 8import random 9 10from photofilmstrip.action.IAction import IAction 11 12from photofilmstrip.core.Aspect import Aspect 13from photofilmstrip.core import PILBackend 14 15 16class ActionAutoPath(IAction): 17 18 def __init__(self, picture, aspect): 19 self.__picture = picture 20 self.__aspect = aspect 21 22 def GetName(self): 23 return _(u'Random motion') 24 25 def Execute(self): 26 try: 27 width, height = PILBackend.GetImageSize( 28 self.__picture.GetFilename()) 29 except: 30 return 31 32 if self.__picture.GetWidth() == -1: 33 # FIXME: stupid if 34 self.__picture.SetWidth(width) 35 self.__picture.SetHeight(height) 36 37 ratio = Aspect.ToFloat(self.__aspect) 38 if width < height: 39 # portrait 40 startRect = (0, 0, width, width / ratio) 41 targetRect = (0, height - (width / ratio), width, width / ratio) 42 else: 43 scaledWidth = width * 0.75 44 startRect = (0, 0, width, width / ratio) 45 d = random.randint(0, 3) 46 if d == 0: 47 targetRect = (0, 0, scaledWidth, scaledWidth / ratio) 48 elif d == 1: 49 targetRect = (0, height - (scaledWidth / ratio), 50 scaledWidth, scaledWidth / ratio) 51 elif d == 2: 52 targetRect = (width - scaledWidth, 0, 53 scaledWidth, scaledWidth / ratio) 54 elif d == 3: 55 targetRect = (width - scaledWidth, 56 height - (scaledWidth / ratio), 57 scaledWidth, scaledWidth / ratio) 58 59 if random.randint(0, 1): 60 targetRect, startRect = startRect, targetRect 61 62 self.__picture.SetStartRect(startRect) 63 self.__picture.SetTargetRect(targetRect) 64