Merge branch 'master' of git://github.com/tobi-wan-kenobi/bumblebee-status

This commit is contained in:
Max Pivo 2020-02-27 12:20:02 -08:00
commit 4fdba0be19
13 changed files with 167 additions and 42 deletions

View file

@ -295,8 +295,15 @@ class Engine(object):
self._current_module = module
module.update_wrapper(module.widgets())
if module.error is None:
widget_ids = []
if module.parameter('id'):
widget_ids = module.parameter('id').split(',')
idx = 0
for widget in module.widgets():
widget.link_module(module)
if idx < len(widget_ids):
widget.id = widget_ids[idx]
idx = idx + 1
self._output.draw(widget=widget, module=module, engine=self)
else:
self._output.draw(widget=module.errorWidget(), module=module, engine=self)

View file

@ -1,9 +1,11 @@
"""Input classes"""
import os
import sys
import json
import uuid
import time
import socket
import select
import logging
import threading
@ -23,38 +25,62 @@ def is_terminated():
return True
return False
class CommandSocket(object):
def __init__(self):
self._name = "/tmp/.bumblebee-status.{}".format(os.getpid())
self._socket = None
def __enter__(self):
self._socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self._socket.bind(self._name)
self._socket.listen(5)
return self._socket
def __exit__(self, type, value, traceback):
self._socket.close()
os.unlink(self._name)
def read_input(inp):
"""Read i3bar input and execute callbacks"""
poll = select.poll()
poll.register(sys.stdin.fileno(), select.POLLIN)
log.debug("starting click event processing")
while inp.running:
if is_terminated():
return
try:
events = poll.poll(1000)
except Exception:
continue
for fileno, event in events:
line = "["
while line.startswith("["):
line = sys.stdin.readline().strip(",").strip()
log.debug("new event: {}".format(line))
inp.has_event = True
with CommandSocket() as cmdsocket:
poll = select.poll()
poll.register(sys.stdin, select.POLLIN)
poll.register(cmdsocket, select.POLLIN)
log.debug("starting click event processing")
while inp.running:
if is_terminated():
return
try:
event = json.loads(line)
if "instance" in event:
inp.callback(event)
inp.redraw()
events = poll.poll(1000)
except Exception:
continue
for fileno, event in events:
if fileno == cmdsocket.fileno():
tmp, _ = cmdsocket.accept()
line = tmp.recv(4096).decode()
tmp.close()
else:
log.debug("field 'instance' missing in input, not processing the event")
except ValueError as e:
log.debug("failed to parse event: {}".format(e))
log.debug("exiting click event processing")
poll.unregister(sys.stdin.fileno())
inp.has_event = True
inp.clean_exit = True
line = "["
while line.startswith("["):
line = sys.stdin.readline().strip(",").strip()
log.debug("new event: {}".format(line))
inp.has_event = True
try:
event = json.loads(line)
if "instance" in event:
inp.callback(event)
inp.redraw()
else:
log.debug("field 'instance' missing in input, not processing the event")
except ValueError as e:
log.debug("failed to parse event: {}".format(e))
log.debug("exiting click event processing")
poll.unregister(sys.stdin.fileno())
inp.has_event = True
inp.clean_exit = True
class I3BarInput(object):
"""Process incoming events from the i3bar"""

View file

@ -240,7 +240,7 @@ class Module(bumblebee.engine.Module):
def state(self, widget):
state = []
capacity = widget.get("capacity")
capacity = widget.get("capacity", -1)
if capacity < 0:
return ["critical", "unknown"]

View file

@ -91,17 +91,16 @@ class Module(bumblebee.engine.Module):
def cpuload(self, _):
return "{}%".format(self._cpuload)
@staticmethod
def add_color(bar):
def add_color(self, bar):
"""add color as pango markup to a bar"""
if bar in ["", ""]:
color = "green"
color = self.theme().color("green", "green")
elif bar in ["", ""]:
color = "yellow"
color = self.theme().color("yellow", "yellow")
elif bar in ["", ""]:
color = "orange"
color = self.theme().color("orange", "orange")
elif bar in ["", ""]:
color = "red"
color = self.theme().color("red", "red")
colored_bar = "<span foreground='{}'>{}</span>".format(color, bar)
return colored_bar

View file

@ -142,12 +142,12 @@ class Module(bumblebee.engine.Module):
vol, bumblebee.output.hbar(float(self._left)))
return vol
else:
vol = "{}%/{}%".format(self._left, self._right)
if self._showbars:
vol = "{} {}{}".format(
vol,
bumblebee.output.hbar(float(self._left)),
bumblebee.output.hbar(float(self._right)))
vol = "{}%/{}%".format(self._left, self._right)
return vol
def update(self, widgets):

View file

@ -18,6 +18,7 @@ import logging
import bumblebee.input
import bumblebee.output
import bumblebee.engine
import bumblebee.popup_v2
import functools
class Module(bumblebee.engine.Module):
@ -76,7 +77,7 @@ class Module(bumblebee.engine.Module):
try:
bumblebee.util.execute("nmcli c up \"{vpn}\""
.format(vpn=self._connected_vpn_profile))
.format(vpn=self._selected_vpn_profile))
self._connected_vpn_profile = name
except Exception as e:
logging.exception("Couldn't establish VPN connection")

View file

@ -72,6 +72,12 @@ def scrollable(func):
if width < 0:
return text
if len(text) <= width:
# do alignment
align = module.parameter("theme.align", "left")
if align == "right":
text = "{:>{}}".format(text, width)
if align == "center":
text = "{:^{}}".format(text, width)
return text
# we need to shorten

View file

@ -186,9 +186,14 @@ class Theme(object):
result[key] = colors[field][key]
return result
def color(self, color_name, default=None):
return self._colorset.get(color_name, default)
def _load_colors(self, name):
"""Load colors for a theme"""
try:
if isinstance(name, dict):
return name
if name.lower() == "wal":
return self._load_wal_colors()
except Exception as err:
@ -285,7 +290,7 @@ class Theme(object):
if isinstance(value, (dict, list)):
return value
return self._colorset.get(value, value)
return self.color(value, value)
# algorithm copied from
# http://blog.impressiver.com/post/31434674390/deep-merge-multiple-python-dicts