Addd “default_module” theme key support

Refs #3.
This commit is contained in:
ZyX 2013-01-16 22:04:43 +04:00 committed by Kim Silkebækken
parent 1557ff2c03
commit 78e54e0c84
3 changed files with 11 additions and 5 deletions

View File

@ -133,6 +133,11 @@ Themes
``name``
Name of the theme.
``default_module``
.. _config-themes-default_module:
Python module where segments will be looked by default.
``segments``
A dict with a ``left`` and a ``right`` list, consisting of segment
dicts. Each segment has the following options:
@ -161,7 +166,8 @@ Themes
.. _config-themes-seg-module:
Function module, only required for function segments. Defaults to
``core``.
``powerline.ext.{extension}.segments``. Default is overriden by
:ref:`theme option <config-themes-default_module>`.
``name``
.. _config-themes-seg-name:

View File

@ -30,7 +30,7 @@ class Powerline(object):
# Load and initialize extension theme
theme_config = self._load_theme_config(ext, self.config_ext.get('theme', 'default'))
path = [os.path.expanduser(path) for path in self.config.get('paths', [])]
get_segment = Segments(ext, path, colorscheme).get
get_segment = Segments(ext, path, colorscheme, theme_config.get('default_module')).get
self.get_matcher = Matchers(ext, path).get
theme_kwargs = {
'ext': ext,

View File

@ -5,15 +5,15 @@ import sys
class Segments(object):
def __init__(self, ext, path, colorscheme):
self.ext = ext
def __init__(self, ext, path, colorscheme, default_module=None):
self.default_module = default_module or 'powerline.ext.{0}.segments'.format(ext)
self.path = path
self.colorscheme = colorscheme
def get_function(self, segment):
oldpath = sys.path
sys.path = self.path + sys.path
segment_module = str(segment.get('module', 'powerline.ext.{0}.segments'.format(self.ext)))
segment_module = str(segment.get('module', self.default_module))
try:
return None, getattr(import_module(segment_module), segment['name']), '{0}.{1}'.format(segment_module, segment['name'])
finally: