Using remote
This commit is contained in:
commit
0b86b3df8c
16 changed files with 257 additions and 144 deletions
|
@ -1,5 +1,4 @@
|
|||
# pylint: disable=C0111,R0903
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Displays information about the current song in cmus.
|
||||
|
||||
|
@ -69,10 +68,6 @@ class Module(bumblebee.engine.Module):
|
|||
return returns.get(widget.name, self._status)
|
||||
|
||||
def _eval_line(self, line):
|
||||
# not a typo, use decode detection to see whether we are
|
||||
# dealing with Python2 or Python3
|
||||
if hasattr(line, "decode"):
|
||||
line = line.encode("utf-8", "replace")
|
||||
name, key, value = (line.split(" ", 2) + [None, None])[:3]
|
||||
|
||||
if name == "status":
|
||||
|
|
|
@ -8,6 +8,13 @@ Requires the following python packages:
|
|||
|
||||
Parameters:
|
||||
* currency.interval: Interval in minutes between updates, default is 1.
|
||||
* currency.source: Source currency (defaults to "GBP")
|
||||
* currency.destination: Comma-separated list of destination currencies (defaults to "USD,EUR")
|
||||
* currency.sourceformat: String format for source formatting; Defaults to "{}: {}" and has two variables,
|
||||
the base symbol and the rate list
|
||||
* currency.destinationdelimiter: Delimiter used for separating individual rates (defaults to "|")
|
||||
|
||||
Note: source and destination names right now must correspond to the names used by the API of http://fixer.io
|
||||
"""
|
||||
|
||||
import bumblebee.input
|
||||
|
@ -21,40 +28,43 @@ try:
|
|||
except ImportError:
|
||||
pass
|
||||
|
||||
SYMBOL = {
|
||||
"GBP": u"£", "EUR": u"€", "USD": u"$"
|
||||
}
|
||||
|
||||
class Module(bumblebee.engine.Module):
|
||||
def __init__(self, engine, config):
|
||||
super(Module, self).__init__(engine, config,
|
||||
bumblebee.output.Widget(full_text=self.price)
|
||||
)
|
||||
self._price = "-"
|
||||
self._interval = int(self.parameter("interval", "1"))
|
||||
self._data = {}
|
||||
self._interval = int(self.parameter("interval", 1))
|
||||
self._base = self.parameter("source", "GBP")
|
||||
self._symbols = self.parameter("destination", "USD,EUR")
|
||||
self._nextcheck = 0
|
||||
self._valid = False
|
||||
|
||||
def price(self, widget):
|
||||
if not self._valid:
|
||||
return u"?"
|
||||
return self._price
|
||||
if self._data == {}:
|
||||
return "?"
|
||||
|
||||
rates = []
|
||||
for sym in self._data["rates"]:
|
||||
rates.append(u"{}{}".format(self._data["rates"][sym], SYMBOL[sym] if sym in SYMBOL else sym))
|
||||
|
||||
basefmt = u"{}".format(self.parameter("sourceformat", "{}: {}"))
|
||||
ratefmt = u"{}".format(self.parameter("destinationdelimiter", "|"))
|
||||
|
||||
return basefmt.format(SYMBOL[self._base] if self._base in SYMBOL else self._base, ratefmt.join(rates))
|
||||
|
||||
def update(self, widgets):
|
||||
timestamp = int(time.time())
|
||||
if self._nextcheck < int(time.time()):
|
||||
self._data = {}
|
||||
self._nextcheck = int(time.time()) + self._interval*60
|
||||
url = "http://api.fixer.io/latest?symbols={}&base={}".format(self._symbols, self._base)
|
||||
try:
|
||||
self._nextcheck = int(time.time()) + self._interval*60
|
||||
price_url = "http://api.fixer.io/latest?symbols=USD,EUR&base=GBP"
|
||||
try:
|
||||
price_json = json.loads( requests.get(price_url).text )
|
||||
gbpeur = str(price_json['rates']['EUR'])
|
||||
gbpusd = str(price_json['rates']['USD'])
|
||||
except ValueError:
|
||||
gbpeur = "-"
|
||||
gbpusd = "-"
|
||||
|
||||
self._price = u"£/€ " + gbpeur + u" | £/$ " + gbpusd
|
||||
self._valid = True
|
||||
except RequestException:
|
||||
self._price = u"£/€ - | £/$ -"
|
||||
self._valid = True
|
||||
self._data = json.loads(requests.get(url).text)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ class Module(bumblebee.engine.Module):
|
|||
url = "https://api.github.com/notifications"
|
||||
while True:
|
||||
notifications = self._requests.get(url)
|
||||
self._count += len(filter(lambda notification: notification.get("unread", False), notifications.json()))
|
||||
self._count += len(list(filter(lambda notification: notification['unread'], notifications.json())))
|
||||
next_link = notifications.links.get('next')
|
||||
if next_link is not None:
|
||||
url = next_link.get('url')
|
||||
|
|
|
@ -4,9 +4,6 @@
|
|||
|
||||
Requires the following executable:
|
||||
* setxkbmap
|
||||
|
||||
Parameters:
|
||||
* layout.lang: pipe-separated list of languages to cycle through (e.g. us|rs|de). Default: en
|
||||
"""
|
||||
|
||||
import bumblebee.util
|
||||
|
@ -17,58 +14,59 @@ import bumblebee.engine
|
|||
class Module(bumblebee.engine.Module):
|
||||
def __init__(self, engine, config):
|
||||
super(Module, self).__init__(engine, config,
|
||||
bumblebee.output.Widget(full_text=self.layout)
|
||||
bumblebee.output.Widget(full_text=self.current_layout)
|
||||
)
|
||||
self._languages = self.parameter("lang", "us").split("|")
|
||||
self._idx = 0
|
||||
|
||||
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
||||
cmd=self._next_keymap)
|
||||
engine.input.register_callback(self, button=bumblebee.input.RIGHT_MOUSE,
|
||||
cmd=self._prev_keymap)
|
||||
|
||||
def _next_keymap(self, event):
|
||||
self._idx = (self._idx + 1) % len(self._languages)
|
||||
self._set_keymap()
|
||||
self._set_keymap(1)
|
||||
|
||||
def _prev_keymap(self, event):
|
||||
self._idx = self._idx - 1 if self._idx > 0 else len(self._languages) - 1
|
||||
self._set_keymap()
|
||||
self._set_keymap(-1)
|
||||
|
||||
def _set_keymap(self, rotation):
|
||||
layouts = self.get_layouts()
|
||||
if len(layouts) == 1: return # nothing to do
|
||||
layouts = layouts[rotation:] + layouts[:rotation]
|
||||
|
||||
layout_list = []
|
||||
variant_list = []
|
||||
for l in layouts:
|
||||
tmp = l.split(":")
|
||||
layout_list.append(tmp[0])
|
||||
variant_list.append(tmp[1] if len(tmp) > 1 else "")
|
||||
|
||||
def _set_keymap(self):
|
||||
tmp = self._languages[self._idx].split(":")
|
||||
layout = tmp[0]
|
||||
variant = ""
|
||||
if len(tmp) > 1:
|
||||
variant = "-variant {}".format(tmp[1])
|
||||
try:
|
||||
bumblebee.util.execute("setxkbmap -layout {} {}".format(layout, variant))
|
||||
bumblebee.util.execute("setxkbmap -layout {} -variant {}".format(",".join(layout_list), ",".join(variant_list)))
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
||||
def layout(self, widget):
|
||||
def get_layouts(self):
|
||||
try:
|
||||
res = bumblebee.util.execute("setxkbmap -query")
|
||||
except RuntimeError:
|
||||
return "n/a"
|
||||
layout = ""
|
||||
variant = None
|
||||
return ["n/a"]
|
||||
layouts = []
|
||||
variants = []
|
||||
for line in res.split("\n"):
|
||||
if not line:
|
||||
continue
|
||||
if not line: continue
|
||||
if "layout" in line:
|
||||
layout = line.split(":")[1].strip()
|
||||
layouts = line.split(":")[1].strip().split(",")
|
||||
if "variant" in line:
|
||||
variant = line.split(":")[1].strip()
|
||||
if variant:
|
||||
layout += ":" + variant
|
||||
variants = line.split(":")[1].strip().split(",")
|
||||
|
||||
if layout in self._languages:
|
||||
self._idx = self._languages.index(layout)
|
||||
else:
|
||||
self._languages.append(layout)
|
||||
self._idx = len(self._languages) - 1
|
||||
result = []
|
||||
for idx, layout in enumerate(layouts):
|
||||
if len(variants) > idx and variants[idx]:
|
||||
layout = "{}:{}".format(layout, variants[idx])
|
||||
result.append(layout)
|
||||
return result if len(result) > 0 else ["n/a"]
|
||||
|
||||
return layout
|
||||
def current_layout(self, widget):
|
||||
layouts = self.get_layouts()
|
||||
return layouts[0]
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||
|
|
|
@ -9,22 +9,24 @@ Parameters:
|
|||
* memory.usedonly: Only show the amount of RAM in use (defaults to False). Same as memory.format="{used}"
|
||||
"""
|
||||
|
||||
try:
|
||||
import psutil
|
||||
except ImportError:
|
||||
pass
|
||||
import re
|
||||
|
||||
import bumblebee.util
|
||||
import bumblebee.input
|
||||
import bumblebee.output
|
||||
import bumblebee.engine
|
||||
|
||||
class Container(object):
|
||||
def __init__(self, **kwargs):
|
||||
self.__dict__.update(kwargs)
|
||||
|
||||
class Module(bumblebee.engine.Module):
|
||||
def __init__(self, engine, config):
|
||||
super(Module, self).__init__(engine, config,
|
||||
bumblebee.output.Widget(full_text=self.memory_usage)
|
||||
)
|
||||
self._mem = psutil.virtual_memory()
|
||||
self.update(None)
|
||||
|
||||
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
||||
cmd="gnome-system-monitor")
|
||||
|
||||
|
@ -36,18 +38,30 @@ class Module(bumblebee.engine.Module):
|
|||
return self.parameter("format", "{used}/{total} ({percent:05.02f}%)")
|
||||
|
||||
def memory_usage(self, widget):
|
||||
used = bumblebee.util.bytefmt(self._mem.total - self._mem.available)
|
||||
total = bumblebee.util.bytefmt(self._mem.total)
|
||||
|
||||
return self._format.format(used=used, total=total, percent=self._mem.percent)
|
||||
return self._format.format(**self._mem)
|
||||
|
||||
def update(self, widgets):
|
||||
self._mem = psutil.virtual_memory()
|
||||
data = {}
|
||||
with open("/proc/meminfo", "r") as f:
|
||||
for line in f:
|
||||
tmp = re.split(r"[:\s]+", line)
|
||||
value = int(tmp[1])
|
||||
if tmp[2] == "kB": value = value*1024
|
||||
if tmp[2] == "mB": value = value*1024*1024
|
||||
if tmp[2] == "gB": value = value*1024*1024*1024
|
||||
data[tmp[0]] = value
|
||||
self._mem = {
|
||||
"total": bumblebee.util.bytefmt(data["MemTotal"]),
|
||||
"available": bumblebee.util.bytefmt(data["MemAvailable"]),
|
||||
"free": bumblebee.util.bytefmt(data["MemFree"]),
|
||||
"used": bumblebee.util.bytefmt(data["MemTotal"] - data["MemFree"] - data["Buffers"] - data["Cached"] - data["Slab"]),
|
||||
"percent": (float(data["MemTotal"] - data["MemAvailable"])/data["MemTotal"])*100
|
||||
}
|
||||
|
||||
def state(self, widget):
|
||||
if self._mem.percent > float(self.parameter("critical", 90)):
|
||||
if self._mem["percent"] > float(self.parameter("critical", 90)):
|
||||
return "critical"
|
||||
if self._mem.percent > float(self.parameter("warning", 80)):
|
||||
if self._mem["percent"] > float(self.parameter("warning", 80)):
|
||||
return "warning"
|
||||
return None
|
||||
|
||||
|
|
|
@ -38,7 +38,9 @@ class Module(bumblebee.engine.Module):
|
|||
else:
|
||||
self._state = "transition"
|
||||
transition = " ".join(line.split(" ")[2:])
|
||||
self._text = "{} {}".format(temp, transition)
|
||||
self._text = temp
|
||||
if transition:
|
||||
self._text = "{} {}".format(temp, transition)
|
||||
|
||||
def state(self, widget):
|
||||
return self._state
|
||||
|
|
67
bumblebee/modules/title.py
Normal file
67
bumblebee/modules/title.py
Normal file
|
@ -0,0 +1,67 @@
|
|||
# pylint: disable=C0111,R0903
|
||||
|
||||
"""Displays focused i3 window title.
|
||||
|
||||
Requirements:
|
||||
* i3ipc
|
||||
|
||||
Parameters:
|
||||
* title.max : Maximum character length for title before truncating. Defaults to 64.
|
||||
* title.placeholder : Placeholder text to be placed if title was truncated. Defaults to "...".
|
||||
* title.scroll : Boolean flag for scrolling title. Defaults to False
|
||||
"""
|
||||
|
||||
try:
|
||||
import i3ipc
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
import bumblebee.util
|
||||
import bumblebee.input
|
||||
import bumblebee.output
|
||||
import bumblebee.engine
|
||||
|
||||
from bumblebee.output import scrollable
|
||||
|
||||
class Module(bumblebee.engine.Module):
|
||||
"""Window title module."""
|
||||
|
||||
def __init__(self, engine, config):
|
||||
super(Module, self).__init__(
|
||||
engine,
|
||||
config,
|
||||
bumblebee.output.Widget(full_text=self.get_title)
|
||||
)
|
||||
try:
|
||||
self._i3 = i3ipc.Connection()
|
||||
self._full_title = self._i3.get_tree().find_focused().name
|
||||
except Exception:
|
||||
self._full_title = "n/a"
|
||||
|
||||
def get_title(self, widget):
|
||||
if bumblebee.util.asbool(self.parameter("scroll", False)):
|
||||
return self.scrolling_focused_title(widget)
|
||||
else:
|
||||
return self.focused_title(widget)
|
||||
|
||||
def focused_title(self, widget):
|
||||
title = self._full_title[0:self.parameter("max", 64)]
|
||||
placeholder = self.parameter("placeholder", "...")
|
||||
if title != self._full_title:
|
||||
title = self._full_title[0:self.parameter("max", 64) - len(placeholder)]
|
||||
title = "{}{}".format(title, placeholder)
|
||||
|
||||
return title
|
||||
|
||||
@scrollable
|
||||
def scrolling_focused_title(self, widget):
|
||||
return self._full_title
|
||||
|
||||
def update(self, widgets):
|
||||
"""Update current title."""
|
||||
try:
|
||||
self._full_title = self._i3.get_tree().find_focused().name
|
||||
except Exception:
|
||||
self._full_title = "n/a"
|
||||
|
||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
|
@ -5,6 +5,7 @@
|
|||
Parameters:
|
||||
* traffic.exclude: Comma-separated list of interface prefixes to exclude (defaults to "lo,virbr,docker,vboxnet,veth")
|
||||
* traffic.states: Comma-separated list of states to show (prefix with "^" to invert - i.e. ^down -> show all devices that are not in state down)
|
||||
* traffic.showname: If set to False, hide network interface name (defaults to True)
|
||||
"""
|
||||
|
||||
import re
|
||||
|
@ -23,7 +24,7 @@ class Module(bumblebee.engine.Module):
|
|||
self._exclude = tuple(filter(len, self.parameter("exclude", "lo,virbr,docker,vboxnet,veth").split(",")))
|
||||
self._status = ""
|
||||
|
||||
self._showname = self.parameter("showname", "True")
|
||||
self._showname = bumblebee.util.asbool(self.parameter("showname", True))
|
||||
self._prev = {}
|
||||
self._states = {}
|
||||
self._states["include"] = []
|
||||
|
@ -86,13 +87,13 @@ class Module(bumblebee.engine.Module):
|
|||
}
|
||||
|
||||
name = "traffic-{}".format(interface)
|
||||
|
||||
if self._showname != "False":
|
||||
self.create_widget(widgets, name, interface)
|
||||
|
||||
if self._showname:
|
||||
self.create_widget(widgets, name, interface)
|
||||
|
||||
for direction in ["rx", "tx"]:
|
||||
name = "traffic.{}-{}".format(direction, interface)
|
||||
widget = self.create_widget(widgets, name, attributes={"theme.minwidth": "100.00MB"})
|
||||
widget = self.create_widget(widgets, name, attributes={"theme.minwidth": "1000.00MB"})
|
||||
prev = self._prev.get(name, 0)
|
||||
speed = bumblebee.util.bytefmt(int(data[direction]) - int(prev))
|
||||
widget.full_text(speed)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue