Package elisa :: Package plugins :: Package good :: Package theme_switcher :: Module theme_switcher_activity
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.good.theme_switcher.theme_switcher_activity

 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 3. 
 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__ = '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   
33 -class ThemeSwitcherActivity(MenuActivityClass):
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
44 - def get_model(self):
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