1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 __maintainer__ = 'Lionel Martin <lionel@fluendo.com>'
19 __maintainer2__ = 'Florian Boucault <florian@fluendo.com>'
20
21
22 from elisa.core.utils import classinit
23 from elisa.core import log
24
26 """
27 A backend holds all the data that has to be rendered in order to display a
28 complete Elisa user interface. It does so by storing a tree of
29 L{elisa.base_components.controller.Controller}s and keeping track of the
30 focus amongst them.
31
32 Multiple L{elisa.core.frontend.Frontend}s can be connected to a backend
33 through the L{elisa.core.interface_controller.InterfaceController} and
34 render the content of the tree of controllers.
35
36 L{elisa.base_components.input_provider.InputProvider}s can be associated
37 with a backend so that all the L{elisa.core.input_event.InputEvent}s are
38 passed on to the backend's tree of controllers.
39 Input events are forwarded to the controller that has the focus:
40 L{focused_controller}.
41
42
43 @ivar root_controller: root controller associated to the backend
44 @type root_controller: L{elisa.base_components.controller.Controller}
45 @ivar focused_controller: controller which currently has the focus
46 @type focused_controller: L{elisa.base_components.controller.Controller}
47 @ivar mvc_config: MVC associations config
48 @type mvc_config: L{elisa.core.config.Config}
49 """
50
51 __metaclass__ = classinit.ClassInitMeta
52 __classinit__ = classinit.build_properties
53
59
64
66 return self._root_controller
67
69 return self._focused_controller
70
87
89 """
90 Return all the parents of a controller and the controller itself. The
91 list is ordered starting with the deepest controller in the branch and
92 going to the root.
93 """
94 branch = []
95 current_controller = controller
96
97 while current_controller != None:
98 branch.append(current_controller)
99 current_controller = current_controller.parent
100
101 return branch
102
103
126
128 """
129 Retrieve the path of the controller associated with given
130 model's path.
131
132 @param model_path: path of the Model for which we need a
133 Controller
134 @type model_path: string
135 @keyword content_type: content-type stored in the model
136 @type content_type: None or string
137 @raises UndefinedMVCAssociation: if the backend's MVC mappings don't
138 define any association for the given
139 model
140 """
141 config = self.mvc_config
142 self.debug("Looking in %r for a controller for %r with content_type %r",
143 config.get_filename(), model_path, content_type)
144
145 controller_path = None
146 if content_type:
147 section = "%s/%s" % (model_path, content_type)
148 controller_path = config.get_option('controller', section=section)
149
150 if controller_path == None:
151 section = model_path
152 controller_path = config.get_option('controller', section=section)
153
154 if controller_path == None:
155 from elisa.core.interface_controller import UndefinedMVCAssociation
156 msg = "No controller path for %r" % model_path
157 raise UndefinedMVCAssociation(msg)
158 else:
159 self.debug("Found %r", controller_path)
160 return controller_path
161