[modules/redshift] Single quotes
This commit is contained in:
parent
967521593c
commit
2592069fb9
2 changed files with 48 additions and 47 deletions
|
@ -11,6 +11,7 @@
|
||||||
- use __ for private?
|
- use __ for private?
|
||||||
|
|
||||||
# Features
|
# Features
|
||||||
|
- new themeing? (and add a "version" for backwards compat)
|
||||||
|
|
||||||
## Backwards-compatibility
|
## Backwards-compatibility
|
||||||
- aliases
|
- aliases
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
# pylint: disable=C0111,R0903
|
# pylint: disable=C0111,R0903
|
||||||
|
|
||||||
"""Displays the current color temperature of redshift
|
'''Displays the current color temperature of redshift
|
||||||
|
|
||||||
Requires the following executable:
|
Requires the following executable:
|
||||||
* redshift
|
* redshift
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
* redshift.location : location provider, either of "geoclue2" (default), \
|
* redshift.location : location provider, either of 'geoclue2' (default), \
|
||||||
"ipinfo" (requires the requests package), or "manual"
|
'ipinfo' (requires the requests package), or 'manual'
|
||||||
* redshift.lat : latitude if location is set to "manual"
|
* redshift.lat : latitude if location is set to 'manual'
|
||||||
* redshift.lon : longitude if location is set to "manual"
|
* redshift.lon : longitude if location is set to 'manual'
|
||||||
"""
|
'''
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
try:
|
try:
|
||||||
|
@ -25,7 +25,7 @@ import bumblebee.engine
|
||||||
|
|
||||||
def is_terminated():
|
def is_terminated():
|
||||||
for thread in threading.enumerate():
|
for thread in threading.enumerate():
|
||||||
if thread.name == "MainThread" and not thread.is_alive():
|
if thread.name == 'MainThread' and not thread.is_alive():
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -34,41 +34,41 @@ def get_redshift_value(widget, location, lat, lon):
|
||||||
while True:
|
while True:
|
||||||
if is_terminated():
|
if is_terminated():
|
||||||
return
|
return
|
||||||
widget.get("condition").acquire()
|
widget.get('condition').acquire()
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
widget.get("condition").wait(1)
|
widget.get('condition').wait(1)
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
continue
|
continue
|
||||||
break
|
break
|
||||||
widget.get("condition").release()
|
widget.get('condition').release()
|
||||||
|
|
||||||
command = ["redshift", "-p", "-l"]
|
command = ['redshift', '-p', '-l']
|
||||||
if location == "manual":
|
if location == 'manual':
|
||||||
command.append(lat + ":" + lon)
|
command.append(lat + ':' + lon)
|
||||||
else:
|
else:
|
||||||
command.append("geoclue2")
|
command.append('geoclue2')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = bumblebee.util.execute(" ".join(command))
|
res = bumblebee.util.execute(' '.join(command))
|
||||||
except Exception:
|
except Exception:
|
||||||
res = ""
|
res = ''
|
||||||
widget.set("temp", "n/a")
|
widget.set('temp', 'n/a')
|
||||||
widget.set("transition", None)
|
widget.set('transition', None)
|
||||||
widget.set("state", "day")
|
widget.set('state', 'day')
|
||||||
for line in res.split("\n"):
|
for line in res.split('\n'):
|
||||||
line = line.lower()
|
line = line.lower()
|
||||||
if "temperature" in line:
|
if 'temperature' in line:
|
||||||
widget.set("temp", line.split(" ")[2])
|
widget.set('temp', line.split(' ')[2])
|
||||||
if "period" in line:
|
if 'period' in line:
|
||||||
state = line.split(" ")[1]
|
state = line.split(' ')[1]
|
||||||
if "day" in state:
|
if 'day' in state:
|
||||||
widget.set("state", "day")
|
widget.set('state', 'day')
|
||||||
elif "night" in state:
|
elif 'night' in state:
|
||||||
widget.set("state", "night")
|
widget.set('state', 'night')
|
||||||
else:
|
else:
|
||||||
widget.set("state", "transition")
|
widget.set('state', 'transition')
|
||||||
widget.set("transition", " ".join(line.split(" ")[2:]))
|
widget.set('transition', ' '.join(line.split(' ')[2:]))
|
||||||
|
|
||||||
|
|
||||||
class Module(bumblebee.engine.Module):
|
class Module(bumblebee.engine.Module):
|
||||||
|
@ -76,31 +76,31 @@ class Module(bumblebee.engine.Module):
|
||||||
widget = bumblebee.output.Widget(full_text=self.text)
|
widget = bumblebee.output.Widget(full_text=self.text)
|
||||||
super(Module, self).__init__(engine, config, widget)
|
super(Module, self).__init__(engine, config, widget)
|
||||||
|
|
||||||
self._location = self.parameter("location", "geoclue2")
|
self._location = self.parameter('location', 'geoclue2')
|
||||||
self._lat = self.parameter("lat", None)
|
self._lat = self.parameter('lat', None)
|
||||||
self._lon = self.parameter("lon", None)
|
self._lon = self.parameter('lon', None)
|
||||||
|
|
||||||
# Even if location method is set to manual, if we have no lat or lon,
|
# Even if location method is set to manual, if we have no lat or lon,
|
||||||
# fall back to the geoclue2 method.
|
# fall back to the geoclue2 method.
|
||||||
if self._location == "manual" and (self._lat is None
|
if self._location == 'manual' and (self._lat is None
|
||||||
or self._lon is None):
|
or self._lon is None):
|
||||||
self._location == "geoclue2"
|
self._location == 'geoclue2'
|
||||||
|
|
||||||
if self._location == "ipinfo":
|
if self._location == 'ipinfo':
|
||||||
try:
|
try:
|
||||||
location_url = "http://ipinfo.io/json"
|
location_url = 'http://ipinfo.io/json'
|
||||||
location = requests.get(location_url).json()
|
location = requests.get(location_url).json()
|
||||||
self._lat, self._lon = location["loc"].split(",")
|
self._lat, self._lon = location['loc'].split(',')
|
||||||
self._lat = str(float(self._lat))
|
self._lat = str(float(self._lat))
|
||||||
self._lon = str(float(self._lon))
|
self._lon = str(float(self._lon))
|
||||||
self._location = "manual"
|
self._location = 'manual'
|
||||||
except Exception:
|
except Exception:
|
||||||
# Fall back to geoclue2.
|
# Fall back to geoclue2.
|
||||||
self._location = "geoclue2"
|
self._location = 'geoclue2'
|
||||||
|
|
||||||
self._text = ""
|
self._text = ''
|
||||||
self._condition = threading.Condition()
|
self._condition = threading.Condition()
|
||||||
widget.set("condition", self._condition)
|
widget.set('condition', self._condition)
|
||||||
self._thread = threading.Thread(target=get_redshift_value,
|
self._thread = threading.Thread(target=get_redshift_value,
|
||||||
args=(widget, self._location,
|
args=(widget, self._location,
|
||||||
self._lat, self._lon))
|
self._lat, self._lon))
|
||||||
|
@ -110,20 +110,20 @@ class Module(bumblebee.engine.Module):
|
||||||
self._condition.release()
|
self._condition.release()
|
||||||
|
|
||||||
def text(self, widget):
|
def text(self, widget):
|
||||||
return "{}".format(self._text)
|
return '{}'.format(self._text)
|
||||||
|
|
||||||
def update(self, widgets):
|
def update(self, widgets):
|
||||||
widget = widgets[0]
|
widget = widgets[0]
|
||||||
self._condition.acquire()
|
self._condition.acquire()
|
||||||
self._condition.notify()
|
self._condition.notify()
|
||||||
self._condition.release()
|
self._condition.release()
|
||||||
temp = widget.get("temp", "n/a")
|
temp = widget.get('temp', 'n/a')
|
||||||
self._text = temp
|
self._text = temp
|
||||||
transition = widget.get("transition", None)
|
transition = widget.get('transition', None)
|
||||||
if transition:
|
if transition:
|
||||||
self._text = "{} {}".format(temp, transition)
|
self._text = '{} {}'.format(temp, transition)
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
return widget.get("state", None)
|
return widget.get('state', None)
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
|
|
Loading…
Add table
Reference in a new issue