Package elisa :: Package base_components :: Module transition
[hide private]
[frames] | no frames]

Source Code for Module elisa.base_components.transition

 1  # -*- coding: utf-8 -*- 
 2  # Elisa - Home multimedia server 
 3  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
 4  # All rights reserved. 
 5  # 
 6  # This file is available under one of two license agreements. 
 7  # 
 8  # This file is licensed under the GPL version 2. 
 9  # See "LICENSE.GPL" in the root of this distribution including a special 
10  # exception to use Elisa with Fluendo's plugins. 
11  # 
12  # The GPL part of Elisa is also available under a commercial licensing 
13  # agreement from Fluendo. 
14  # See "LICENSE.Elisa" in the root directory of this distribution package 
15  # for details on that license. 
16   
17   
18  __maintainer__ = 'Florian Boucault <florian@fluendo.com>' 
19   
20   
21  from elisa.core import common 
22  from elisa.core.component import Component 
23  from elisa.base_components.view import View 
24   
25  from twisted.internet import reactor 
26   
27   
28 -class ViewNotSupported(Exception):
29 - def __init__(self, view_path, transition_path):
30 Exception.__init__(self) 31 self.view_path = view_path 32 self.transition_path = transition_path
33
34 - def __str__(self):
35 return "View of type %s is not supported by transition of type %s" \ 36 % (self.view_path, self.transition_path)
37
38 -class Transition(Component):
39 """ 40 Embodies a visual transition between two states of a L{View}. 41 42 @cvar supported_views: path of views that are supported by the transition 43 read only 44 @type supported_views: list of strings 45 @ivar in_progress: True if the transition is ongoing, False otherwise 46 read only 47 @type in_progress: boolean 48 """ 49 50 supported_views = () 51
52 - def __init__(self):
53 Component.__init__(self) 54 self.in_progress = False 55 self._end_callback = None
56
57 - def apply(self, view, end_callback=None):
58 """ 59 Start the transition on L{view}. 60 61 If L{end_callback} is set, it will be called when the transition ends. 62 63 @param view: view on which the transition is applied 64 @type view: L{elisa.base_components.view.View} 65 @param end_callback: callback called at the end of the transition 66 @type end_callback: callable 67 68 @raise ViewNotSupported: if the transition cannot be applied to the 69 view 70 """ 71 if self.in_progress: 72 self.stop() 73 74 plugin_registry = common.application.plugin_registry 75 view_classes = [View] 76 for view_path in self.supported_views: 77 ViewClass = plugin_registry.get_component_class(view_path) 78 view_classes.append(ViewClass) 79 80 for ViewClass in view_classes: 81 if not isinstance(view, ViewClass): 82 raise ViewNotSupported(view.path, self.path) 83 84 self._end_callback = end_callback 85 self.in_progress = True
86
87 - def stop(self):
88 """ 89 Interrupt the transition where it is currently calling the end of 90 transition callback if set. 91 """ 92 self.in_progress = False 93 if self._end_callback != None: 94 reactor.callLater(0, self._end_callback)
95