mirror of
https://github.com/gryf/pywmtemp.git
synced 2026-02-02 22:25:45 +01:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7295d8123d | |||
| 6f805d8bdc | |||
| 1f51add078 | |||
| 6f9b91d525 | |||
| 9f18dfdf26 | |||
| 56f85d4887 | |||
| bfb37a5b63 | |||
| 580dc45c2a | |||
| d02ecefdf3 | |||
| d4bd3b19d3 | |||
| ac56074faf |
@@ -5,7 +5,7 @@ PyWMTemp
|
||||
WindowMaker dockapp for monitoring resources like CPU/GPU temperatures. It
|
||||
supports up to 2 different readings.
|
||||
|
||||
.. image:: /images/pywmtemp.png?raw=true
|
||||
.. image:: /images/pywmtemp.gif?raw=true
|
||||
:alt: wmamixer overview
|
||||
|
||||
|
||||
|
||||
BIN
images/pywmtemp.gif
Normal file
BIN
images/pywmtemp.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.7 KiB |
@@ -170,18 +170,15 @@ class SensorDockApp(wmdocklib.DockApp):
|
||||
readings using information found on /sys file system.
|
||||
"""
|
||||
background_color = '#202020'
|
||||
x_offset = 3
|
||||
y_offset = 3
|
||||
font_dimentions = (6, 8)
|
||||
graph_width = 58
|
||||
graph_max_height = 36
|
||||
graph_coords = (3, 25)
|
||||
|
||||
def __init__(self, args=None):
|
||||
super().__init__(args)
|
||||
self.font = FONT
|
||||
self._debug = args.debug
|
||||
self.fonts = [wmdocklib.BitmapFonts(FONT, (6, 8))]
|
||||
self.background = BACKGROUND
|
||||
self.max_chars_in_line = None
|
||||
self.conf = {}
|
||||
self.critical = 0
|
||||
self.warning = 0
|
||||
@@ -196,12 +193,7 @@ class SensorDockApp(wmdocklib.DockApp):
|
||||
|
||||
def run(self):
|
||||
self.prepare_pixmaps()
|
||||
self.max_chars_in_line = int((self.width - 2 * self.x_offset) /
|
||||
self.char_width)
|
||||
self.max_rows = int((self.height - 2 * self.x_offset) /
|
||||
self.char_height)
|
||||
self.open_xwindow()
|
||||
|
||||
try:
|
||||
self.main_loop()
|
||||
except KeyboardInterrupt:
|
||||
@@ -220,11 +212,9 @@ class SensorDockApp(wmdocklib.DockApp):
|
||||
# ignored.
|
||||
for item in self.conf.get('readings', [])[:2]:
|
||||
self._put_string(item, position)
|
||||
position += self.char_height
|
||||
position += self.fonts[0].height
|
||||
self._draw_graph()
|
||||
name = self._current_graph.upper()
|
||||
name = name[:4]
|
||||
self.add_string(name, 1, 50)
|
||||
self._draw_graph_label()
|
||||
|
||||
count += 1
|
||||
if count >= 10:
|
||||
@@ -240,33 +230,51 @@ class SensorDockApp(wmdocklib.DockApp):
|
||||
temp = None
|
||||
temps = psutil.sensors_temperatures()
|
||||
for shw in temps.get(item.get('sensor'), []):
|
||||
# if there is no label configured, take the first sensor
|
||||
# temperature.
|
||||
if not item.get('label'):
|
||||
temp = shw
|
||||
break
|
||||
|
||||
if shw.label == item.get('label'):
|
||||
temp = shw
|
||||
break
|
||||
else:
|
||||
# in case there is no items matched.
|
||||
return ' ', 0
|
||||
|
||||
value = int(temp.current)
|
||||
name = item.get('name')
|
||||
self._history[name] = self._history[name][1:]
|
||||
self._history[name].append(value)
|
||||
charset_width = self.fonts[0].charset_width
|
||||
char_width = self.fonts[0].width
|
||||
|
||||
# shift charset depending on the threshold defined in config, assuming
|
||||
# charset is the same row(s) copied with different color for warning
|
||||
# and critival.
|
||||
# and critical.
|
||||
# FIXME: remove hardcoded multiplies in favor of automatically
|
||||
# computed factors.
|
||||
displacement = 0
|
||||
if item.get('override_warning') and value >= item['override_warning']:
|
||||
displacement = int(self.charset_width / self.char_width) * 2
|
||||
displacement = int(charset_width / char_width) * 2
|
||||
elif temp.high and value >= temp.high:
|
||||
displacement = int(self.charset_width / self.char_width) * 2
|
||||
displacement = int(charset_width / char_width) * 2
|
||||
|
||||
if (item.get('override_critical') and
|
||||
value >= item['override_critical']):
|
||||
displacement = int(self.charset_width / self.char_width) * 4
|
||||
displacement = int(charset_width / char_width) * 4
|
||||
elif temp.critical and value >= temp.critical:
|
||||
displacement = int(self.charset_width / self.char_width) * 4
|
||||
displacement = int(charset_width / char_width) * 4
|
||||
|
||||
if (len(str(value)) - len(item.get('unit', ''))) <= 5:
|
||||
value = (f'{value:{5 - len(item.get("unit", ""))}}'
|
||||
f'{item.get("unit", "")}')
|
||||
else:
|
||||
value = f'{value:5}'
|
||||
|
||||
string = f"{value}".replace('°', '\\').upper()
|
||||
|
||||
string = f"{value}{item['unit']}".replace('°', '\\').upper()
|
||||
if displacement:
|
||||
string = ''.join([chr(ord(i) + displacement) for i in string])
|
||||
|
||||
@@ -323,18 +331,32 @@ class SensorDockApp(wmdocklib.DockApp):
|
||||
def _put_string(self, item, position):
|
||||
temp, displacement = self.get_reading(item)
|
||||
name = item.get('name', '').upper()
|
||||
name = name[:4]
|
||||
name = f'{name[:4]:4}'
|
||||
if displacement:
|
||||
name = ''.join([chr(ord(i) + displacement)
|
||||
for i in name])
|
||||
|
||||
self.add_string(name, 1, position)
|
||||
self.add_string(temp, 34, position)
|
||||
self.fonts[0].add_string(name, 1, position)
|
||||
self.fonts[0].add_string(temp[:5], 28, position)
|
||||
|
||||
def _draw_graph_label(self):
|
||||
name = self._current_graph.upper()
|
||||
name = name[:4]
|
||||
# ugly as hell 1 pixel border for the upper and left side of the label
|
||||
helpers.copy_xpm_area(1, 65,
|
||||
len(name) * self.fonts[0].width + 1, 1,
|
||||
4, 51)
|
||||
helpers.copy_xpm_area(1, 65,
|
||||
1, self.fonts[0].height + 1,
|
||||
4, 51)
|
||||
self.fonts[0].add_string(name, 2, 49)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-c', '--config', help='Alternate config file')
|
||||
parser.add_argument('-d', '--debug', action="store_true",
|
||||
help='Turn on debug information')
|
||||
args = parser.parse_args()
|
||||
|
||||
dockapp = SensorDockApp(args)
|
||||
|
||||
Reference in New Issue
Block a user