Merge branch 'tobi-wan-kenobi:main' into main

This commit is contained in:
Dhananjay Tanpure 2022-03-07 08:58:13 +05:30 committed by GitHub
commit 3de6f9f4b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 468 additions and 13 deletions

View file

@ -0,0 +1,141 @@
# pylint: disable=C0111,R0903
""" Displays the current default sink.
Left click opens a popup menu that lists all available sinks and allows to change the default sink.
Per default, this module uses the sink names returned by "pactl list sinks short"
sample output of "pactl list sinks short":
2 alsa_output.pci-0000_00_1f.3.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
3 alsa_output.usb-Logitech_Logitech_USB_Headset-00.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDE
As "alsa_output.usb-Logitech_Logitech_USB_Headset-00.analog-stereo" is not a particularly nice name, its possible to map the name to more a
user friendly name. e.g to map "alsa_output.usb-Logitech_Logitech_USB_Headset-00.analog-stereo" to the name "Headset", add the following
bumblebee-status config entry: pactl.alsa_output.usb-Logitech_Logitech_USB_Headset-00.analog-stereo=Headset
The module also allows to specify individual (unicode) icons for all the sinks. e.g in order to use the icon 🎧 for the
"alsa_output.usb-Logitech_Logitech_USB_Headset-00.analog-stereo" sink, add the following bumblebee-status config entry:
pactl.icon.alsa_output.usb-Logitech_Logitech_USB_Headset-00.analog-stereo=🎧
Requirements:
* pulseaudio
* pactl
"""
import logging
import functools
import core.module
import core.widget
import core.input
import util.cli
import util.popup
class Sink(object):
def __init__(self, id, internal_name, friendly_name, icon):
super().__init__()
self.__id = id
self.__internal_name = internal_name
self.__friendly_name = friendly_name
self.__icon = icon
@property
def id(self):
return self.__id
@property
def internal_name(self):
return self.__internal_name
@property
def friendly_name(self):
return self.__friendly_name
@property
def icon(self):
return self.__icon
@property
def display_name(self):
display_name = (
self.__icon + " " + self.__friendly_name
if self.__icon != ""
else self.__friendly_name
)
return display_name
class Module(core.module.Module):
def __init__(self, config, theme):
super().__init__(config, theme, core.widget.Widget(self.default_sink))
self.__default_sink = None
res = util.cli.execute("pactl list sinks short")
lines = res.splitlines()
self.__sinks = []
for line in lines:
info = line.split("\t")
try:
friendly_name = self.parameter(info[1], info[1])
icon = self.parameter("icon." + info[1], "")
self.__sinks.append(Sink(info[0], info[1], friendly_name, icon))
except:
logging.exception("Couldn't parse sink")
pass
core.input.register(self, button=core.input.LEFT_MOUSE, cmd=self.popup)
def __sink(self, internal_sink_name):
for sink in self.__sinks:
if internal_sink_name == sink.internal_name:
return sink
return None
def update(self):
try:
res = util.cli.execute("pactl info")
lines = res.splitlines()
self.__default_sink = None
for line in lines:
if not line.startswith("Default Sink:"):
continue
internal_sink_name = line.replace("Default Sink: ", "")
self.__default_sink = self.__sink(internal_sink_name)
break
except Exception as e:
logging.exception("Could not get pactl info")
self.__default_sink = None
def default_sink(self, widget):
if self.__default_sink is None:
return "unknown"
return self.__default_sink.display_name
def __on_sink_selected(self, sink):
try:
util.cli.execute("pactl set-default-sink {}".format(sink.id))
self.__default_sink = sink
except Exception as e:
logging.exception("Couldn't set default sink")
def popup(self, widget):
menu = util.popup.menu()
for sink in self.__sinks:
menu.add_menuitem(
sink.friendly_name,
callback=functools.partial(self.__on_sink_selected, sink),
)
menu.show(widget)
def state(self, widget):
return []
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -0,0 +1,45 @@
# pylint: disable=C0111,R0903
"""Displays the current date and time in Persian(Jalali) Calendar.
Requires the following python packages:
* jdatetime
Parameters:
* datetime.format: strftime()-compatible formatting string. default: "%A %d %B" e.g., "جمعه ۱۳ اسفند"
* datetime.locale: locale to use. default: "fa_IR"
"""
from __future__ import absolute_import
import jdatetime
import locale
import core.module
import core.widget
import core.input
class Module(core.module.Module):
def __init__(self, config, theme):
super().__init__(config, theme, core.widget.Widget(self.full_text))
l = ("fa_IR", "UTF-8")
lcl = self.parameter("locale", ".".join(l))
try:
locale.setlocale(locale.LC_ALL, lcl.split("."))
except Exception as e:
locale.setlocale(locale.LC_ALL, ("fa_IR", "UTF-8"))
def default_format(self):
return "%A %d %B"
def full_text(self, widget):
enc = locale.getpreferredencoding()
fmt = self.parameter("format", self.default_format())
retval = jdatetime.datetime.now().strftime(fmt)
if hasattr(retval, "decode"):
return retval.decode(enc)
return retval
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -16,13 +16,13 @@ class Module(core.module.Module):
self.__ip = ""
def public_ip(self, widget):
return self.__ip
return self.__ip or "n/a"
def update(self):
try:
self.__ip = util.location.public_ip()
except Exception:
self.__ip = "n/a"
self.__ip = None
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

View file

@ -55,7 +55,7 @@ class Module(core.module.Module):
self._state = []
self._newspaper_filename = tempfile.mktemp(".html")
self._newspaper_file = tempfile.NamedTemporaryFile(mode="w", suffix=".html")
self._last_refresh = 0
self._last_update = 0
@ -308,10 +308,11 @@ class Module(core.module.Module):
while newspaper_items:
content += self._create_news_section(newspaper_items)
open(self._newspaper_filename, "w").write(
self._newspaper_file.write(
HTML_TEMPLATE.replace("[[CONTENT]]", content)
)
webbrowser.open("file://" + self._newspaper_filename)
self._newspaper_file.flush()
webbrowser.open("file://" + self._newspaper_file.name)
self._update_history("newspaper")
self._save_history()

View file

@ -39,7 +39,11 @@ class Module(core.module.Module):
self.__sun = None
if not lat or not lon:
lat, lon = util.location.coordinates()
try:
lat, lon = util.location.coordinates()
except Exception:
pass
if lat and lon:
self.__sun = Sun(float(lat), float(lon))
@ -55,6 +59,10 @@ class Module(core.module.Module):
return "n/a"
def __calculate_times(self):
if not self.__sun:
self.__sunset = self.__sunrise = None
return
self.__isup = False
order_matters = True