mirror of
https://github.com/powerline/powerline.git
synced 2025-07-23 13:55:45 +02:00
Fix shutdown function being always None
Problem reported by @IvanMalison
This commit is contained in:
parent
fa502281f3
commit
e9852fec37
@ -45,6 +45,18 @@ segment_getters = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_attr_func(contents_func, key, kwargs):
|
||||||
|
try:
|
||||||
|
func = getattr(contents_func, key)
|
||||||
|
except AttributeError:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
if kwargs is None:
|
||||||
|
return lambda : func()
|
||||||
|
else:
|
||||||
|
return lambda pl, shutdown_event: func(pl=pl, shutdown_event=shutdown_event, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def gen_segment_getter(pl, ext, path, theme_configs, default_module=None):
|
def gen_segment_getter(pl, ext, path, theme_configs, default_module=None):
|
||||||
data = {
|
data = {
|
||||||
'default_module': default_module or 'powerline.segments.' + ext,
|
'default_module': default_module or 'powerline.segments.' + ext,
|
||||||
@ -74,20 +86,17 @@ def gen_segment_getter(pl, ext, path, theme_configs, default_module=None):
|
|||||||
highlight_group = segment.get('highlight_group') or segment.get('name')
|
highlight_group = segment.get('highlight_group') or segment.get('name')
|
||||||
|
|
||||||
if segment_type == 'function':
|
if segment_type == 'function':
|
||||||
args = dict(((str(k), v) for k, v in get_key(segment, module, 'args', {}).items()))
|
kwargs = dict(((str(k), v) for k, v in get_key(segment, module, 'args', {}).items()))
|
||||||
try:
|
startup_func = get_attr_func(_contents_func, 'startup', kwargs)
|
||||||
_startup_func = _contents_func.startup
|
shutdown_func = get_attr_func(_contents_func, 'shutdown', None)
|
||||||
except AttributeError:
|
|
||||||
startup_func = None
|
|
||||||
else:
|
|
||||||
startup_func = lambda pl, shutdown_event: _startup_func(pl=pl, shutdown_event=shutdown_event, **args)
|
|
||||||
|
|
||||||
if hasattr(_contents_func, 'powerline_requires_segment_info'):
|
if hasattr(_contents_func, 'powerline_requires_segment_info'):
|
||||||
contents_func = lambda pl, segment_info: _contents_func(pl=pl, segment_info=segment_info, **args)
|
contents_func = lambda pl, segment_info: _contents_func(pl=pl, segment_info=segment_info, **kwargs)
|
||||||
else:
|
else:
|
||||||
contents_func = lambda pl, segment_info: _contents_func(pl=pl, **args)
|
contents_func = lambda pl, segment_info: _contents_func(pl=pl, **kwargs)
|
||||||
else:
|
else:
|
||||||
startup_func = None
|
startup_func = None
|
||||||
|
shutdown_func = None
|
||||||
contents_func = None
|
contents_func = None
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -109,8 +118,8 @@ def gen_segment_getter(pl, ext, path, theme_configs, default_module=None):
|
|||||||
'include_modes': segment.get('include_modes', []),
|
'include_modes': segment.get('include_modes', []),
|
||||||
'width': segment.get('width'),
|
'width': segment.get('width'),
|
||||||
'align': segment.get('align', 'l'),
|
'align': segment.get('align', 'l'),
|
||||||
'shutdown': getattr(contents_func, 'shutdown', None),
|
|
||||||
'startup': startup_func,
|
'startup': startup_func,
|
||||||
|
'shutdown': shutdown_func,
|
||||||
'_rendered_raw': '',
|
'_rendered_raw': '',
|
||||||
'_rendered_hl': '',
|
'_rendered_hl': '',
|
||||||
'_len': 0,
|
'_len': 0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user