[core/module] Add error widgets if a module throws
Module should have to care less about thrown exceptions.
This commit is contained in:
parent
cb3482ae27
commit
a1aec8fff6
7 changed files with 36 additions and 4 deletions
|
@ -38,6 +38,14 @@ class Module(core.input.Object):
|
|||
def update(self):
|
||||
pass
|
||||
|
||||
def update_wrapper(self):
|
||||
try:
|
||||
self.update()
|
||||
except Exception as e:
|
||||
module = Error(self._config, 'error', str(e))
|
||||
self._widgets = [module.widgets()[0]]
|
||||
self.update = module.update
|
||||
|
||||
def name(self):
|
||||
return self._name if self._name else self.module_name()
|
||||
|
||||
|
|
|
@ -6,14 +6,20 @@ import core.theme
|
|||
import core.event
|
||||
|
||||
class i3(object):
|
||||
def __init__(self, theme=core.theme.Theme()):
|
||||
def __init__(self, theme=core.theme.Theme(), config=None):
|
||||
self._modules = []
|
||||
self._status = {}
|
||||
self._theme = theme
|
||||
self._config = config
|
||||
core.event.register('start', self.draw, 'start')
|
||||
core.event.register('update', self.draw, 'statusline')
|
||||
core.event.register('stop', self.draw, 'stop')
|
||||
|
||||
def theme(self, new_theme=None):
|
||||
if new_theme:
|
||||
self._theme = new_theme
|
||||
return self._theme
|
||||
|
||||
def modules(self, modules=None):
|
||||
if not modules:
|
||||
return self._modules
|
||||
|
@ -96,7 +102,7 @@ class i3(object):
|
|||
for module in self._modules:
|
||||
if affected_modules and not module.id() in affected_modules:
|
||||
continue
|
||||
module.update()
|
||||
module.update_wrapper()
|
||||
for widget in module.widgets():
|
||||
self._status[widget] = widget.full_text()
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import core.input
|
||||
import core.decorators
|
||||
import util.store
|
||||
|
||||
class Widget(util.store.Store, core.input.Object):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue