2017-06-15 07:48:25 +02:00
|
|
|
# -*- coding: UTF-8 -*-
|
2017-06-05 04:54:23 +02:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
2017-04-19 13:36:35 +02:00
|
|
|
"""Displays sensor temperature
|
|
|
|
|
|
|
|
Parameters:
|
2017-07-19 13:40:57 +02:00
|
|
|
* sensors.path: path to temperature file (default /sys/class/thermal/thermal_zone0/temp).
|
2017-04-19 13:36:35 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
import bumblebee.input
|
|
|
|
import bumblebee.output
|
|
|
|
import bumblebee.engine
|
|
|
|
|
|
|
|
class Module(bumblebee.engine.Module):
|
|
|
|
def __init__(self, engine, config):
|
|
|
|
super(Module, self).__init__(engine, config,
|
2017-06-05 04:54:23 +02:00
|
|
|
bumblebee.output.Widget(full_text=self.temperature))
|
2017-04-19 18:53:45 +02:00
|
|
|
self._temperature = "unknown"
|
2017-06-15 07:48:25 +02:00
|
|
|
self._mhz = "n/a"
|
2017-04-19 13:36:35 +02:00
|
|
|
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, cmd="xsensors")
|
|
|
|
|
|
|
|
def get_temp(self):
|
2017-07-19 13:40:57 +02:00
|
|
|
try:
|
|
|
|
temperature = open(self.parameter("path", "/sys/class/thermal/thermal_zone0/temp")).read()[:2]
|
|
|
|
except IOError:
|
|
|
|
temperature = "unknown"
|
2017-04-19 13:36:35 +02:00
|
|
|
return temperature
|
|
|
|
|
2017-06-13 04:19:30 +02:00
|
|
|
def get_mhz( self ):
|
2017-06-15 07:48:25 +02:00
|
|
|
output = open("/proc/cpuinfo").read()
|
|
|
|
m = re.search(r"cpu MHz\s+:\s+(\d+)", output)
|
|
|
|
mhz = int(m.group(1))
|
2017-06-13 04:19:30 +02:00
|
|
|
|
|
|
|
if mhz < 1000:
|
2017-06-15 07:48:25 +02:00
|
|
|
return "{} MHz".format(mhz)
|
2017-06-13 04:19:30 +02:00
|
|
|
else:
|
2017-06-15 07:48:25 +02:00
|
|
|
return "{:0.01f} GHz".format(float(mhz)/1000.0)
|
2017-06-13 04:19:30 +02:00
|
|
|
|
2017-06-05 04:54:23 +02:00
|
|
|
def temperature(self, _):
|
2017-06-15 07:48:25 +02:00
|
|
|
return u"{}°c @ {}".format(self._temperature, self._mhz)
|
2017-04-19 13:36:35 +02:00
|
|
|
|
|
|
|
def update(self, widgets):
|
|
|
|
self._temperature = self.get_temp()
|
2017-06-13 04:19:30 +02:00
|
|
|
self._mhz = self.get_mhz()
|
2017-04-19 18:53:45 +02:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|