1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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
35 return "View of type %s is not supported by transition of type %s" \
36 % (self.view_path, self.transition_path)
37
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
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
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