[core] Each module can now access theme data

Add a method "theme()" to the generic module to have access to the theme
information.

Specifically, "theme().get(widget, attribute, default_value)" can be
used to retrieve theming for a widget with an arbitrary attribute.

This is in response to #412 - thanks to @bbernhard for the suggestion!
This commit is contained in:
Tobias Witek 2019-08-01 20:41:13 +02:00
parent 93606315e3
commit eb72d59ed1
2 changed files with 10 additions and 0 deletions

View file

@ -41,6 +41,7 @@ class Module(object):
self.error = None
self._next = int(time.time())
self._default_interval = 0
self._engine = engine
self._configFile = None
for cfg in [os.path.expanduser("~/.bumblebee-status.conf"), os.path.expanduser("~/.config/bumblebee-status.conf")]:
@ -56,6 +57,9 @@ class Module(object):
if widgets:
self._widgets = widgets if isinstance(widgets, list) else [widgets]
def theme(self):
return self._engine.theme()
def widgets(self, widgets=None):
"""Return the widgets to draw for this module"""
if widgets:
@ -160,6 +164,9 @@ class Engine(object):
self.input.start()
def theme(self):
return self._theme
def _toggle_minimize(self, event):
for module in self._modules:
widget = module.widget_by_id(event["instance"])

View file

@ -105,6 +105,9 @@ class Theme(object):
if icon is None:
return self._get(widget, "prefix", None)
def get(self, widget, attribute, default_value=""):
return self._get(widget, attribute, default_value)
def padding(self, widget):
"""Return padding for widget"""
return self._get(widget, "padding", "")