Package elisa :: Package base_components :: Module theme
[hide private]
[frames] | no frames]

Source Code for Module elisa.base_components.theme

  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.component import Component 
 22  from elisa.core import common, config 
 23   
24 -class Theme(Component):
25 """ 26 DOCME 27 28 @ivar config_file: DOCME 29 @type config_file: 30 @cvar default_theme: DOCME 31 @type default_theme: 32 """ 33 34 default_theme = None 35
36 - def __init__(self):
37 Component.__init__(self) 38 self._config_file = None 39 self._theme_config = None
40 41
42 - def initialize(self):
43 Component.initialize(self) 44 self.config_file = self.default_theme
45
46 - def config_file__get(self):
47 return self._config_file
48
49 - def config_file__set(self, config_file):
50 if config_file: 51 self._config_file = config_file 52 file_path = self._get_file_path(config_file) 53 self._theme_config = config.Config(file_path)
54 55
56 - def _get_file_path(self, plugin_path):
57 file_path = plugin_path 58 parts = plugin_path.split(':') 59 if len(parts) == 2: 60 plugin_name = parts[0] 61 relative_path = parts[1] 62 63 plugin_registry = common.application.plugin_registry 64 plugin = plugin_registry.plugin_classes[plugin_name] 65 file_path = plugin.get_resource_file(relative_path) 66 return file_path
67
68 - def get_media(self, key, default_plugin_path=None):
69 """ 70 Return the absolute path to a file in the theme. 71 72 @param key: key (name) for the file 73 @type key: string 74 @param default_plugin_path: if the theme found None, use this one 75 @type default_plugin_path: string 76 @rtype: string 77 """ 78 # the format of default_plugin_path is plugin:directory/file 79 plugin_path = self._theme_config.get_option(key, 80 section='general', 81 default=None) 82 83 if plugin_path==None: 84 if default_plugin_path==None: 85 self.debug("Couldn't find '%s' returning unknown_icon" % key) 86 plugin_path = self._theme_config.get_option('unknown_icon', 87 section='general', 88 default=None) 89 else: 90 self._theme_config.set_option(key, 91 default_plugin_path, 92 section='general') 93 plugin_path=default_plugin_path 94 95 return self._get_file_path(plugin_path)
96 97
98 - def save_config(self, application_config):
99 """ 100 DOCME 101 """ 102 if self._theme_config: 103 self._theme_config.write() 104 Component.save_config(self, application_config)
105