[core] Generic collapsible widgets

Each widget can now be collapsed and expanded using the middle mouse
click, by default.
This commit is contained in:
Tobias Witek 2018-09-15 14:40:52 +02:00
parent 8bb1d14ddf
commit 7152bb17f2
2 changed files with 10 additions and 24 deletions

View file

@ -41,9 +41,6 @@ class Module(object):
self.error = None self.error = None
self._next = int(time.time()) self._next = int(time.time())
self._default_interval = 0 self._default_interval = 0
self._minimized = False
self._minimizedWidget = bumblebee.output.Widget(full_text=u"\u2026")
self._configFile = None self._configFile = None
for cfg in [os.path.expanduser("~/.bumblebee-status.conf"), os.path.expanduser("~/.config/bumblebee-status.conf")]: for cfg in [os.path.expanduser("~/.bumblebee-status.conf"), os.path.expanduser("~/.config/bumblebee-status.conf")]:
@ -59,12 +56,6 @@ class Module(object):
if widgets: if widgets:
self._widgets = widgets if isinstance(widgets, list) else [widgets] self._widgets = widgets if isinstance(widgets, list) else [widgets]
def toggle_minimize(self):
self._minimized = not self._minimized
def minimized(self):
return self._minimized
def widgets(self): def widgets(self):
"""Return the widgets to draw for this module""" """Return the widgets to draw for this module"""
return self._widgets return self._widgets
@ -77,9 +68,6 @@ class Module(object):
if widget.name == name: if widget.name == name:
return widget return widget
def minimizedWidget(self):
return self._minimizedWidget
def errorWidget(self): def errorWidget(self):
msg = self.error msg = self.error
if len(msg) > 10: if len(msg) > 10:
@ -90,8 +78,6 @@ class Module(object):
for widget in self._widgets: for widget in self._widgets:
if widget.id == uid: if widget.id == uid:
return widget return widget
if self._minimizedWidget.id == uid:
return self._minimizedWidget
return None return None
def update(self, widgets): def update(self, widgets):
@ -174,9 +160,10 @@ class Engine(object):
def _toggle_minimize(self, event): def _toggle_minimize(self, event):
for module in self._modules: for module in self._modules:
if module.widget_by_id(event["instance"]): widget = module.widget_by_id(event["instance"])
if widget:
log.debug("module {} found - toggle minimize".format(module.id)) log.debug("module {} found - toggle minimize".format(module.id))
module.toggle_minimize() widget.toggle_minimize()
def _prev_workspace(self, event): def _prev_workspace(self, event):
self._change_workspace(-1) self._change_workspace(-1)
@ -289,13 +276,6 @@ class Engine(object):
self._current_module = module self._current_module = module
module.update_wrapper(module.widgets()) module.update_wrapper(module.widgets())
if module.error is None: if module.error is None:
if module.minimized():
widget = module.minimizedWidget()
widget.link_module(module)
if self._theme:
icon = self._theme.icon(widget)
self._output.draw(widget=widget, module=module, engine=self)
else:
for widget in module.widgets(): for widget in module.widgets():
widget.link_module(module) widget.link_module(module)
self._output.draw(widget=widget, module=module, engine=self) self._output.draw(widget=widget, module=module, engine=self)

View file

@ -37,12 +37,16 @@ class Widget(bumblebee.store.Store):
self._full_text = full_text self._full_text = full_text
self.module = None self.module = None
self._module = None self._module = None
self._minimized = False
self.name = name self.name = name
self.id = str(uuid.uuid4()) self.id = str(uuid.uuid4())
def get_module(self): def get_module(self):
return self._module return self._module
def toggle_minimize(self):
self._minimized = not self._minimized
def link_module(self, module): def link_module(self, module):
"""Set the module that spawned this widget """Set the module that spawned this widget
@ -70,6 +74,8 @@ class Widget(bumblebee.store.Store):
if value: if value:
self._full_text = value self._full_text = value
else: else:
if self._minimized:
return u"\u2026"
if callable(self._full_text): if callable(self._full_text):
return self._full_text(self) return self._full_text(self)
else: else: