[modules/cpu2] quotes
This commit is contained in:
parent
ed9278cd39
commit
b34178ee71
1 changed files with 48 additions and 48 deletions
|
@ -28,7 +28,7 @@ Parameters:
|
||||||
* cpu2.fan_pattern: pattern to look for in the output of 'sensors -u';
|
* cpu2.fan_pattern: pattern to look for in the output of 'sensors -u';
|
||||||
required if cpu2.fanspeed widged is used
|
required if cpu2.fanspeed widged is used
|
||||||
|
|
||||||
Note: if you are getting "n/a" for CPU temperature / fan speed, then you're
|
Note: if you are getting 'n/a' for CPU temperature / fan speed, then you're
|
||||||
lacking the aforementioned pattern settings or they have wrong values.
|
lacking the aforementioned pattern settings or they have wrong values.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -47,85 +47,85 @@ class Module(bumblebee.engine.Module):
|
||||||
|
|
||||||
def __init__(self, engine, config):
|
def __init__(self, engine, config):
|
||||||
super(Module, self).__init__(engine, config, [])
|
super(Module, self).__init__(engine, config, [])
|
||||||
self._layout = self.parameter("layout", "cpu2.maxfreq cpu2.cpuload cpu2.coresload cpu2.temp cpu2.fanspeed")
|
self._layout = self.parameter('layout', 'cpu2.maxfreq cpu2.cpuload cpu2.coresload cpu2.temp cpu2.fanspeed')
|
||||||
self._widget_names = self._layout.split()
|
self._widget_names = self._layout.split()
|
||||||
widget_list = []
|
widget_list = []
|
||||||
for widget_name in self._widget_names:
|
for widget_name in self._widget_names:
|
||||||
if widget_name == "cpu2.maxfreq":
|
if widget_name == 'cpu2.maxfreq':
|
||||||
widget = bumblebee.output.Widget(
|
widget = bumblebee.output.Widget(
|
||||||
name=widget_name, full_text=self.maxfreq)
|
name=widget_name, full_text=self.maxfreq)
|
||||||
widget.set("type", "freq")
|
widget.set('type', 'freq')
|
||||||
elif widget_name == "cpu2.cpuload":
|
elif widget_name == 'cpu2.cpuload':
|
||||||
widget = bumblebee.output.Widget(
|
widget = bumblebee.output.Widget(
|
||||||
name=widget_name, full_text=self.cpuload)
|
name=widget_name, full_text=self.cpuload)
|
||||||
widget.set("type", "load")
|
widget.set('type', 'load')
|
||||||
elif widget_name == "cpu2.coresload":
|
elif widget_name == 'cpu2.coresload':
|
||||||
widget = bumblebee.output.Widget(
|
widget = bumblebee.output.Widget(
|
||||||
name=widget_name, full_text=self.coresload)
|
name=widget_name, full_text=self.coresload)
|
||||||
widget.set("type", "loads")
|
widget.set('type', 'loads')
|
||||||
elif widget_name == "cpu2.temp":
|
elif widget_name == 'cpu2.temp':
|
||||||
widget = bumblebee.output.Widget(
|
widget = bumblebee.output.Widget(
|
||||||
name=widget_name, full_text=self.temp)
|
name=widget_name, full_text=self.temp)
|
||||||
widget.set("type", "temp")
|
widget.set('type', 'temp')
|
||||||
elif widget_name == "cpu2.fanspeed":
|
elif widget_name == 'cpu2.fanspeed':
|
||||||
widget = bumblebee.output.Widget(
|
widget = bumblebee.output.Widget(
|
||||||
name=widget_name, full_text=self.fanspeed)
|
name=widget_name, full_text=self.fanspeed)
|
||||||
widget.set("type", "fan")
|
widget.set('type', 'fan')
|
||||||
widget_list.append(widget)
|
widget_list.append(widget)
|
||||||
self.widgets(widget_list)
|
self.widgets(widget_list)
|
||||||
self._colored = bumblebee.util.asbool(self.parameter("colored", 0))
|
self._colored = bumblebee.util.asbool(self.parameter('colored', 0))
|
||||||
self._temp_pattern = self.parameter("temp_pattern")
|
self._temp_pattern = self.parameter('temp_pattern')
|
||||||
if self._temp_pattern is None:
|
if self._temp_pattern is None:
|
||||||
self._temp = "n/a"
|
self._temp = 'n/a'
|
||||||
self._fan_pattern = self.parameter("fan_pattern")
|
self._fan_pattern = self.parameter('fan_pattern')
|
||||||
if self._fan_pattern is None:
|
if self._fan_pattern is None:
|
||||||
self._fan = "n/a"
|
self._fan = 'n/a'
|
||||||
# maxfreq is loaded only once at startup
|
# maxfreq is loaded only once at startup
|
||||||
if "cpu2.maxfreq" in self._widget_names:
|
if 'cpu2.maxfreq' in self._widget_names:
|
||||||
self._maxfreq = psutil.cpu_freq().max / 1000
|
self._maxfreq = psutil.cpu_freq().max / 1000
|
||||||
self.update(widget_list)
|
self.update(widget_list)
|
||||||
|
|
||||||
def maxfreq(self, _):
|
def maxfreq(self, _):
|
||||||
return "{:.2f}GHz".format(self._maxfreq)
|
return '{:.2f}GHz'.format(self._maxfreq)
|
||||||
|
|
||||||
def cpuload(self, _):
|
def cpuload(self, _):
|
||||||
return "{:>3}%".format(self._cpuload)
|
return '{:>3}%'.format(self._cpuload)
|
||||||
|
|
||||||
def add_color(self, bar):
|
def add_color(self, bar):
|
||||||
"""add color as pango markup to a bar"""
|
"""add color as pango markup to a bar"""
|
||||||
if bar in ["▁", "▂"]:
|
if bar in ['▁', '▂']:
|
||||||
color = self.theme().color("green", "green")
|
color = self.theme().color('green', 'green')
|
||||||
elif bar in ["▃", "▄"]:
|
elif bar in ['▃', '▄']:
|
||||||
color = self.theme().color("yellow", "yellow")
|
color = self.theme().color('yellow', 'yellow')
|
||||||
elif bar in ["▅", "▆"]:
|
elif bar in ['▅', '▆']:
|
||||||
color = self.theme().color("orange", "orange")
|
color = self.theme().color('orange', 'orange')
|
||||||
elif bar in ["▇", "█"]:
|
elif bar in ['▇', '█']:
|
||||||
color = self.theme().color("red", "red")
|
color = self.theme().color('red', 'red')
|
||||||
colored_bar = "<span foreground='{}'>{}</span>".format(color, bar)
|
colored_bar = '<span foreground='{}'>{}</span>'.format(color, bar)
|
||||||
return colored_bar
|
return colored_bar
|
||||||
|
|
||||||
def coresload(self, _):
|
def coresload(self, _):
|
||||||
mono_bars = [bumblebee.output.hbar(x) for x in self._coresload]
|
mono_bars = [bumblebee.output.hbar(x) for x in self._coresload]
|
||||||
if not self._colored:
|
if not self._colored:
|
||||||
return "".join(mono_bars)
|
return ''.join(mono_bars)
|
||||||
colored_bars = [self.add_color(x) for x in mono_bars]
|
colored_bars = [self.add_color(x) for x in mono_bars]
|
||||||
return "".join(colored_bars)
|
return ''.join(colored_bars)
|
||||||
|
|
||||||
def temp(self, _):
|
def temp(self, _):
|
||||||
if self._temp == "n/a" or self._temp == 0:
|
if self._temp == 'n/a' or self._temp == 0:
|
||||||
return "n/a"
|
return 'n/a'
|
||||||
return "{}°C".format(self._temp)
|
return '{}°C'.format(self._temp)
|
||||||
|
|
||||||
def fanspeed(self, _):
|
def fanspeed(self, _):
|
||||||
if self._fanspeed == "n/a":
|
if self._fanspeed == 'n/a':
|
||||||
return "n/a"
|
return 'n/a'
|
||||||
return "{}RPM".format(self._fanspeed)
|
return '{}RPM'.format(self._fanspeed)
|
||||||
|
|
||||||
def _parse_sensors_output(self):
|
def _parse_sensors_output(self):
|
||||||
output = bumblebee.util.execute("sensors -u")
|
output = bumblebee.util.execute('sensors -u')
|
||||||
lines = output.split("\n")
|
lines = output.split('\n')
|
||||||
temp = "n/a"
|
temp = 'n/a'
|
||||||
fan = "n/a"
|
fan = 'n/a'
|
||||||
temp_line = None
|
temp_line = None
|
||||||
fan_line = None
|
fan_line = None
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
@ -136,21 +136,21 @@ class Module(bumblebee.engine.Module):
|
||||||
if temp_line is not None and fan_line is not None:
|
if temp_line is not None and fan_line is not None:
|
||||||
break
|
break
|
||||||
if temp_line is not None:
|
if temp_line is not None:
|
||||||
temp = round(float(temp_line.split(":")[1].strip()))
|
temp = round(float(temp_line.split(':')[1].strip()))
|
||||||
if fan_line is not None:
|
if fan_line is not None:
|
||||||
fan = int(fan_line.split(":")[1].strip()[:-4])
|
fan = int(fan_line.split(':')[1].strip()[:-4])
|
||||||
return temp, fan
|
return temp, fan
|
||||||
|
|
||||||
def update(self, _):
|
def update(self, _):
|
||||||
if "cpu2.maxfreq" in self._widget_names:
|
if 'cpu2.maxfreq' in self._widget_names:
|
||||||
self._maxfreq = psutil.cpu_freq().max / 1000
|
self._maxfreq = psutil.cpu_freq().max / 1000
|
||||||
if "cpu2.cpuload" in self._widget_names:
|
if 'cpu2.cpuload' in self._widget_names:
|
||||||
self._cpuload = round(psutil.cpu_percent(percpu=False))
|
self._cpuload = round(psutil.cpu_percent(percpu=False))
|
||||||
if "cpu2.coresload" in self._widget_names:
|
if 'cpu2.coresload' in self._widget_names:
|
||||||
self._coresload = psutil.cpu_percent(percpu=True)
|
self._coresload = psutil.cpu_percent(percpu=True)
|
||||||
if "cpu2.temp" in self._widget_names or "cpu2.fanspeed" in self._widget_names:
|
if 'cpu2.temp' in self._widget_names or 'cpu2.fanspeed' in self._widget_names:
|
||||||
self._temp, self._fanspeed = self._parse_sensors_output()
|
self._temp, self._fanspeed = self._parse_sensors_output()
|
||||||
|
|
||||||
def state(self, widget):
|
def state(self, widget):
|
||||||
"""for having per-widget icons"""
|
"""for having per-widget icons"""
|
||||||
return [widget.get("type", "")]
|
return [widget.get('type', '')]
|
||||||
|
|
Loading…
Reference in a new issue