[core] Add ability to "hide" a module with all its widgets
* A module can override the method "hidden" to specify when all it's widgets should be hidden. * Implement hidden for cmus and spotify * Fix problem that cmus widgets were not displayed correctly fixes #157
This commit is contained in:
parent
8376e406e5
commit
9f69cc6ae9
4 changed files with 15 additions and 2 deletions
|
@ -56,6 +56,9 @@ class Module(object):
|
||||||
"""Return the widgets to draw for this module"""
|
"""Return the widgets to draw for this module"""
|
||||||
return self._widgets
|
return self._widgets
|
||||||
|
|
||||||
|
def hidden(self):
|
||||||
|
return False
|
||||||
|
|
||||||
def widget(self, name):
|
def widget(self, name):
|
||||||
for widget in self._widgets:
|
for widget in self._widgets:
|
||||||
if widget.name == name:
|
if widget.name == name:
|
||||||
|
|
|
@ -49,6 +49,9 @@ class Module(bumblebee.engine.Module):
|
||||||
self._repeat = False
|
self._repeat = False
|
||||||
self._tags = defaultdict(lambda: '')
|
self._tags = defaultdict(lambda: '')
|
||||||
|
|
||||||
|
def hidden(self):
|
||||||
|
return self._status == None
|
||||||
|
|
||||||
@scrollable
|
@scrollable
|
||||||
def description(self, widget):
|
def description(self, widget):
|
||||||
return string.Formatter().vformat(self._fmt, (), self._tags)
|
return string.Formatter().vformat(self._fmt, (), self._tags)
|
||||||
|
@ -72,6 +75,7 @@ class Module(bumblebee.engine.Module):
|
||||||
try:
|
try:
|
||||||
info = bumblebee.util.execute("cmus-remote -Q")
|
info = bumblebee.util.execute("cmus-remote -Q")
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
|
self._status = None
|
||||||
pass
|
pass
|
||||||
self._tags = defaultdict(lambda: '')
|
self._tags = defaultdict(lambda: '')
|
||||||
for line in info.split("\n"):
|
for line in info.split("\n"):
|
||||||
|
|
|
@ -40,6 +40,9 @@ class Module(bumblebee.engine.Module):
|
||||||
def spotify(self, widget):
|
def spotify(self, widget):
|
||||||
return str(self._song)
|
return str(self._song)
|
||||||
|
|
||||||
|
def hidden(self):
|
||||||
|
return str(self._song) == ""
|
||||||
|
|
||||||
def update(self, widgets):
|
def update(self, widgets):
|
||||||
try:
|
try:
|
||||||
bus = dbus.SessionBus()
|
bus = dbus.SessionBus()
|
||||||
|
|
|
@ -11,6 +11,7 @@ import bumblebee.store
|
||||||
def scrollable(func):
|
def scrollable(func):
|
||||||
def wrapper(module, widget):
|
def wrapper(module, widget):
|
||||||
text = func(module, widget)
|
text = func(module, widget)
|
||||||
|
if not text: return text
|
||||||
width = widget.get("theme.width", module.parameter("width", 30))
|
width = widget.get("theme.width", module.parameter("width", 30))
|
||||||
widget.set("theme.minwidth", "A"*width)
|
widget.set("theme.minwidth", "A"*width)
|
||||||
if len(text) <= width:
|
if len(text) <= width:
|
||||||
|
@ -39,6 +40,9 @@ class Widget(bumblebee.store.Store):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.id = str(uuid.uuid4())
|
self.id = str(uuid.uuid4())
|
||||||
|
|
||||||
|
def get_module(self):
|
||||||
|
return self._module
|
||||||
|
|
||||||
def link_module(self, module):
|
def link_module(self, module):
|
||||||
"""Set the module that spawned this widget
|
"""Set the module that spawned this widget
|
||||||
|
|
||||||
|
@ -93,8 +97,7 @@ class I3BarOutput(object):
|
||||||
def draw(self, widget, module=None, engine=None):
|
def draw(self, widget, module=None, engine=None):
|
||||||
"""Draw a single widget"""
|
"""Draw a single widget"""
|
||||||
full_text = widget.full_text()
|
full_text = widget.full_text()
|
||||||
"""Don't draw it when we only have an empty text"""
|
if widget.get_module() and widget.get_module().hidden():
|
||||||
if full_text == "":
|
|
||||||
return
|
return
|
||||||
padding = self._theme.padding(widget)
|
padding = self._theme.padding(widget)
|
||||||
prefix = self._theme.prefix(widget, padding)
|
prefix = self._theme.prefix(widget, padding)
|
||||||
|
|
Loading…
Reference in a new issue