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
20
21 from elisa.core.utils import classinit, signal
22 from elisa.core import log
23 from elisa.base_components.theme import Theme
24 from elisa.core import common
25 from elisa.extern.translation import Translatable
26
27 from twisted.internet import defer
28
29
31 """
32 A frontend can be connected to a L{elisa.core.backend.Backend} in order to
33 render its content. It does so by holding the root of a tree
34 L{elisa.base_components.view.View}s that render the
35 L{elisa.base_components.controller.Controller}s hold by the backend. The
36 rendering is done in a context which is unique to a frontend.
37
38 A L{elisa.base_components.theme.Theme} can be used in order to change the
39 set of icons used by the views for their rendering.
40
41 @ivar view: root view associated to the frontend
42 @type view: L{elisa.base_components.view.View}
43 @ivar context: context in which the root view is rendered
44 @type context: L{elisa.base_components.context.Context}
45 @ivar theme: theme used by the frontend at rendering
46 @type theme: L{elisa.base_components.theme.Theme}
47 @ivar languages: the translation to use
48 @type languages: list
49 @ivar mvc_config: MVC associations config
50 @type mvc_config: L{elisa.core.config.Config}
51
52 DOCME: ivar name; see below.
53 """
54
55 __metaclass__ = classinit.ClassInitMeta
56 __classinit__ = classinit.build_properties
57
58 theme_changed = signal.Signal('theme_changed', Theme)
59
60
61 name = None
62
64 log.Loggable.__init__(self)
65 self.view = None
66 self.context = None
67 self._theme = None
68 self._languages = []
69 self.mvc_config = mvc_config
70
74
77
80
91
93 return self._languages
94
104
105 - def translate_text(self, text):
106 """
107 Convert a translatable text to a text in the languages
108 supported by the frontend.
109
110 @param text: text to translate
111 @type text: string or L{elisa.extern.translator.Translatable}
112 @rtype: unicode
113 """
114 self.info("Translating text %r", text)
115 translated = text
116 trans = common.application.translator
117 if isinstance(text, Translatable):
118 translated = trans.translateTranslatable(text, self._languages)
119 else:
120 self.debug("%r is not a Translatable", text)
121 return translated
122
124 """
125 Cleanup the frontend. Once done, no rendering will be possible.
126
127 @rtype: L{twisted.internet.defer.Deferred}
128 """
129
130 dfr = defer.Deferred()
131 dfr.addCallback(lambda x: self.view.clean())
132 dfr.addCallback(lambda x: self._theme.clean())
133 dfr.addCallback(lambda x: self.context.clean())
134 dfr.callback(None)
135 return dfr
136
138 """
139 Retrieve the path of the view associated with given model
140
141 @param model_path: path of the Model we're looking a View for
142 @type model_path: string
143 @keyword content_type: content-type stored in the model
144 @type content_type: None or string
145 @raises UndefinedMVCAssociation: if the frontend's MVC mappings don't
146 define any association for the given
147 model
148 """
149 config = self.mvc_config
150 self.debug("Looking in %r for a view for %r with content_type %r",
151 config.get_filename(), model_path, content_type)
152
153 view_path = None
154 if content_type:
155 section = "%s/%s" % (model_path, content_type)
156 view_path = config.get_option('view', section=section)
157
158 if view_path == None:
159 section = model_path
160 view_path = config.get_option('view', section=section)
161
162 if view_path == None:
163 from elisa.core.interface_controller import UndefinedMVCAssociation
164 msg = "No view path for %r" % model_path
165 raise UndefinedMVCAssociation(msg)
166 else:
167 self.debug("Found %r", view_path)
168 return view_path
169