[core/output] Use __ for private variables
This commit is contained in:
parent
3aeec1c7e6
commit
a6eb6c3a11
1 changed files with 30 additions and 30 deletions
|
@ -7,23 +7,23 @@ import core.event
|
||||||
|
|
||||||
class i3(object):
|
class i3(object):
|
||||||
def __init__(self, theme=core.theme.Theme(), config=core.config.Config([])):
|
def __init__(self, theme=core.theme.Theme(), config=core.config.Config([])):
|
||||||
self._modules = []
|
self.__modules = []
|
||||||
self._status = {}
|
self.__status = {}
|
||||||
self._theme = theme
|
self.__theme = theme
|
||||||
self._config = config
|
self.__config = config
|
||||||
core.event.register('start', self.draw, 'start')
|
core.event.register('start', self.draw, 'start')
|
||||||
core.event.register('update', self.draw, 'statusline')
|
core.event.register('update', self.draw, 'statusline')
|
||||||
core.event.register('stop', self.draw, 'stop')
|
core.event.register('stop', self.draw, 'stop')
|
||||||
|
|
||||||
def theme(self, new_theme=None):
|
def theme(self, new_theme=None):
|
||||||
if new_theme:
|
if new_theme:
|
||||||
self._theme = new_theme
|
self.__theme = new_theme
|
||||||
return self._theme
|
return self.__theme
|
||||||
|
|
||||||
def modules(self, modules=None):
|
def modules(self, modules=None):
|
||||||
if not modules:
|
if not modules:
|
||||||
return self._modules
|
return self.__modules
|
||||||
self._modules = modules if isinstance(modules, list) else [ modules ]
|
self.__modules = modules if isinstance(modules, list) else [ modules ]
|
||||||
|
|
||||||
def draw(self, what, args=None):
|
def draw(self, what, args=None):
|
||||||
cb = getattr(self, what)
|
cb = getattr(self, what)
|
||||||
|
@ -45,38 +45,38 @@ class i3(object):
|
||||||
return { 'suffix': '\n]' }
|
return { 'suffix': '\n]' }
|
||||||
|
|
||||||
def __pad(self, module, widget, full_text):
|
def __pad(self, module, widget, full_text):
|
||||||
padding = self._theme.padding()
|
padding = self.__theme.padding()
|
||||||
if not full_text: return padding
|
if not full_text: return padding
|
||||||
return '{}{}{}'.format(padding, full_text, padding)
|
return '{}{}{}'.format(padding, full_text, padding)
|
||||||
|
|
||||||
def __decorate(self, module, widget, full_text):
|
def __decorate(self, module, widget, full_text):
|
||||||
if full_text is None: return None
|
if full_text is None: return None
|
||||||
return '{}{}{}'.format(
|
return '{}{}{}'.format(
|
||||||
self.__pad(module, widget, self._theme.prefix(widget)),
|
self.__pad(module, widget, self.__theme.prefix(widget)),
|
||||||
full_text,
|
full_text,
|
||||||
self.__pad(module, widget, self._theme.suffix(widget))
|
self.__pad(module, widget, self.__theme.suffix(widget))
|
||||||
)
|
)
|
||||||
|
|
||||||
def __common_attributes(self, module, widget):
|
def __common_attributes(self, module, widget):
|
||||||
return {
|
return {
|
||||||
'separator': self._theme.default_separators(),
|
'separator': self.__theme.default_separators(),
|
||||||
'separator_block_width': self._theme.separator_block_width(),
|
'separator_block_width': self.__theme.separator_block_width(),
|
||||||
'border_top': self._theme.border_top(),
|
'border_top': self.__theme.border_top(),
|
||||||
'border_left': self._theme.border_left(),
|
'border_left': self.__theme.border_left(),
|
||||||
'border_right': self._theme.border_right(),
|
'border_right': self.__theme.border_right(),
|
||||||
'border_bottom': self._theme.border_bottom(),
|
'border_bottom': self.__theme.border_bottom(),
|
||||||
'instance': widget.id,
|
'instance': widget.id,
|
||||||
'name': module.id,
|
'name': module.id,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __separator(self, module, widget):
|
def __separator(self, module, widget):
|
||||||
if not self._theme.separator():
|
if not self.__theme.separator():
|
||||||
return []
|
return []
|
||||||
attr = self.__common_attributes(module, widget)
|
attr = self.__common_attributes(module, widget)
|
||||||
attr.update({
|
attr.update({
|
||||||
'full_text': self._theme.separator(),
|
'full_text': self.__theme.separator(),
|
||||||
'color': self._theme.bg(widget),
|
'color': self.__theme.bg(widget),
|
||||||
'background': self._theme.bg('previous'),
|
'background': self.__theme.bg('previous'),
|
||||||
'_decorator': True,
|
'_decorator': True,
|
||||||
})
|
})
|
||||||
return [attr]
|
return [attr]
|
||||||
|
@ -85,11 +85,11 @@ class i3(object):
|
||||||
attr = self.__common_attributes(module, widget)
|
attr = self.__common_attributes(module, widget)
|
||||||
attr.update({
|
attr.update({
|
||||||
'full_text': self.__decorate(module, widget, text),
|
'full_text': self.__decorate(module, widget, text),
|
||||||
'color': self._theme.fg(widget),
|
'color': self.__theme.fg(widget),
|
||||||
'background': self._theme.bg(widget),
|
'background': self.__theme.bg(widget),
|
||||||
'min_width': self.__decorate(module, widget, widget.get('theme.minwidth')),
|
'min_width': self.__decorate(module, widget, widget.get('theme.minwidth')),
|
||||||
})
|
})
|
||||||
if (self._config.debug()):
|
if (self.__config.debug()):
|
||||||
attr.update({
|
attr.update({
|
||||||
'__state': ", ".join(module.state(widget))
|
'__state': ", ".join(module.state(widget))
|
||||||
})
|
})
|
||||||
|
@ -98,30 +98,30 @@ class i3(object):
|
||||||
def widgets(self, module):
|
def widgets(self, module):
|
||||||
widgets = []
|
widgets = []
|
||||||
for widget in module.widgets():
|
for widget in module.widgets():
|
||||||
if widget.module() and self._config.autohide(widget.module().name()):
|
if widget.module() and self.__config.autohide(widget.module().name()):
|
||||||
if not any(state in widget.state() for state in [ 'warning', 'critical']):
|
if not any(state in widget.state() for state in [ 'warning', 'critical']):
|
||||||
continue
|
continue
|
||||||
widgets += self.__separator(module, widget)
|
widgets += self.__separator(module, widget)
|
||||||
widgets += self.__main(module, widget, self._status[widget])
|
widgets += self.__main(module, widget, self.__status[widget])
|
||||||
core.event.trigger('next-widget')
|
core.event.trigger('next-widget')
|
||||||
return widgets
|
return widgets
|
||||||
|
|
||||||
def update(self, affected_modules=None):
|
def update(self, affected_modules=None):
|
||||||
now = time.time()
|
now = time.time()
|
||||||
for module in self._modules:
|
for module in self.__modules:
|
||||||
if affected_modules and not module.id in affected_modules:
|
if affected_modules and not module.id in affected_modules:
|
||||||
continue
|
continue
|
||||||
if not affected_modules and module.next_update:
|
if not affected_modules and module.next_update:
|
||||||
if now < module.next_update:
|
if now < module.next_update:
|
||||||
continue
|
continue
|
||||||
module.update_wrapper()
|
module.update_wrapper()
|
||||||
module.next_update = now + float(module.parameter('interval', self._config.interval()))
|
module.next_update = now + float(module.parameter('interval', self.__config.interval()))
|
||||||
for widget in module.widgets():
|
for widget in module.widgets():
|
||||||
self._status[widget] = widget.full_text()
|
self.__status[widget] = widget.full_text()
|
||||||
|
|
||||||
def statusline(self):
|
def statusline(self):
|
||||||
widgets = []
|
widgets = []
|
||||||
for module in self._modules:
|
for module in self.__modules:
|
||||||
widgets += self.widgets(module)
|
widgets += self.widgets(module)
|
||||||
return {
|
return {
|
||||||
'data': widgets,
|
'data': widgets,
|
||||||
|
|
Loading…
Reference in a new issue