mirror of
https://github.com/powerline/powerline.git
synced 2025-07-25 14:54:54 +02:00
Make it use existing shutdown events
Also adds check to powerline-lint that "args" dictionary does not set shutdown_event, segment_info or pl keyword arguments, this will lead to problems
This commit is contained in:
parent
f45084057a
commit
f0e5f43d48
@ -235,6 +235,7 @@ class Powerline(object):
|
|||||||
'ext': self.ext,
|
'ext': self.ext,
|
||||||
'common_config': self.common_config,
|
'common_config': self.common_config,
|
||||||
'run_once': self.run_once,
|
'run_once': self.run_once,
|
||||||
|
'shutdown_event': self.shutdown_event,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,7 +34,6 @@ class ThreadedSegment(MultiRunnedThread):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(ThreadedSegment, self).__init__()
|
super(ThreadedSegment, self).__init__()
|
||||||
self.shutdown_event = Event()
|
|
||||||
self.run_once = True
|
self.run_once = True
|
||||||
self.skip = False
|
self.skip = False
|
||||||
self.crashed_value = None
|
self.crashed_value = None
|
||||||
@ -98,8 +97,9 @@ class ThreadedSegment(MultiRunnedThread):
|
|||||||
interval = interval or getattr(self, 'interval')
|
interval = interval or getattr(self, 'interval')
|
||||||
self.interval = interval
|
self.interval = interval
|
||||||
|
|
||||||
def set_state(self, interval=None, update_first=True, **kwargs):
|
def set_state(self, interval=None, update_first=True, shutdown_event=None, **kwargs):
|
||||||
self.set_interval(interval)
|
self.set_interval(interval)
|
||||||
|
self.shutdown_event = shutdown_event or Event()
|
||||||
self.updated = not (update_first and self.update_first)
|
self.updated = not (update_first and self.update_first)
|
||||||
|
|
||||||
def startup(self, pl, **kwargs):
|
def startup(self, pl, **kwargs):
|
||||||
@ -177,8 +177,9 @@ class KwThreadedSegment(ThreadedSegment):
|
|||||||
|
|
||||||
return update_value
|
return update_value
|
||||||
|
|
||||||
def set_state(self, interval=None, **kwargs):
|
def set_state(self, interval=None, shutdown_event=None, **kwargs):
|
||||||
self.set_interval(interval)
|
self.set_interval(interval)
|
||||||
|
self.shutdown_event = shutdown_event or Event()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def render_one(update_state, **kwargs):
|
def render_one(update_state, **kwargs):
|
||||||
|
@ -242,6 +242,11 @@ class Spec(object):
|
|||||||
msg_func))
|
msg_func))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def error(self, msg):
|
||||||
|
self.checks.append(('check_func', lambda *args: (True, True, True),
|
||||||
|
lambda value: msg.format(value)))
|
||||||
|
return self
|
||||||
|
|
||||||
def either(self, *specs):
|
def either(self, *specs):
|
||||||
start = len(self.specs)
|
start = len(self.specs)
|
||||||
self.specs.extend(specs)
|
self.specs.extend(specs)
|
||||||
@ -788,6 +793,9 @@ def check_segment_data_key(key, data, context, echoerr):
|
|||||||
args_spec = Spec(
|
args_spec = Spec(
|
||||||
interval=Spec().either(Spec().type(float), Spec().type(int)).optional(),
|
interval=Spec().either(Spec().type(float), Spec().type(int)).optional(),
|
||||||
update_first=Spec().type(bool).optional(),
|
update_first=Spec().type(bool).optional(),
|
||||||
|
shutdown_event=Spec().error('Shutdown event must be set by powerline').optional(),
|
||||||
|
pl=Spec().error('pl object must be set by powerline').optional(),
|
||||||
|
segment_info=Spec().error('Segment info dictionary must be set by powerline').optional(),
|
||||||
).unknown_spec(Spec(), Spec()).optional().copy
|
).unknown_spec(Spec(), Spec()).optional().copy
|
||||||
highlight_group_spec = Spec().type(unicode).copy
|
highlight_group_spec = Spec().type(unicode).copy
|
||||||
segment_module_spec = Spec().type(unicode).func(check_segment_module).optional().copy
|
segment_module_spec = Spec().type(unicode).func(check_segment_module).optional().copy
|
||||||
|
@ -22,7 +22,14 @@ def requires_segment_info(func):
|
|||||||
|
|
||||||
|
|
||||||
class Theme(object):
|
class Theme(object):
|
||||||
def __init__(self, ext, theme_config, common_config, pl, top_theme_config=None, run_once=False):
|
def __init__(self,
|
||||||
|
ext,
|
||||||
|
theme_config,
|
||||||
|
common_config,
|
||||||
|
pl,
|
||||||
|
top_theme_config=None,
|
||||||
|
run_once=False,
|
||||||
|
shutdown_event=None):
|
||||||
self.dividers = theme_config.get('dividers', common_config['dividers'])
|
self.dividers = theme_config.get('dividers', common_config['dividers'])
|
||||||
self.spaces = theme_config.get('spaces', common_config['spaces'])
|
self.spaces = theme_config.get('spaces', common_config['spaces'])
|
||||||
self.segments = {
|
self.segments = {
|
||||||
@ -44,7 +51,7 @@ class Theme(object):
|
|||||||
if not run_once:
|
if not run_once:
|
||||||
if segment['startup']:
|
if segment['startup']:
|
||||||
try:
|
try:
|
||||||
segment['startup'](pl=pl, **segment['args'])
|
segment['startup'](pl=pl, shutdown_event=shutdown_event, **segment['args'])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pl.error('Exception during {0} startup: {1}', segment['name'], str(e))
|
pl.error('Exception during {0} startup: {1}', segment['name'], str(e))
|
||||||
continue
|
continue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user