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 import common, plugin_registry
22 from elisa.core.plugin_registry import PluginNotFound, ComponentNotFound
23 from elisa.core.media_uri import MediaUri
24
25 from elisa.extern.translation import gettexter, N_
26 T_ = gettexter('elisa-theme-switcher')
27
28 from switch_theme_action import SwitchThemeAction
29
30
31 MenuActivityClass = plugin_registry.get_component_class('base:menu_activity')
32
34 """
35 Manages a list of themes that the user can switch between.
36 """
37 config_doc = {'themes': "a list of themes (eg. ['classic:theme',"
38 "'poblenou:tango_theme'])"}
39 default_config = {'themes': []}
40
41 menu_name = T_(N_("Themes"))
42 media_types = []
43
45 """
46 Returns a menu_node_model for the Theme menu
47 """
48 registry = common.application.plugin_registry
49 main_node = MenuActivityClass.get_model(self)
50 main_node.theme_icon = "theme_switcher_icon"
51 main_node.children = registry.create_component("base:list_model")
52
53 for theme_path in self.config.get("themes" , []):
54 try:
55 component = registry.create_component(theme_path)
56 except (PluginNotFound, ComponentNotFound), error:
57 self.warning(error)
58 else:
59 self.log("Component %r with menu model %r", component, \
60 component.name)
61 label = component.name.split('_')[0].capitalize()
62 menu_model = self._create_menu_model(label, 'theme')
63 path = component.get_media('theme_icon')
64 thumbnail = MediaUri( {'scheme' : 'file', 'path' : path} )
65 menu_model.thumbnail_source = thumbnail
66 action = SwitchThemeAction()
67 action.theme_path = theme_path
68 menu_model.activate_action = action
69 menu_model.activity = self
70
71 if menu_model != None:
72 self.log("menu model: %r", menu_model)
73 main_node.children.append(menu_model)
74 else:
75 self.debug("menu_model %r should have got %r appended",
76 main_node, component.name)
77
78 main_node.has_children = len(main_node.children) > 0
79
80 return main_node
81