mirror of
https://github.com/gryf/pywmtemp.git
synced 2026-02-02 14:15:53 +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
|
WindowMaker dockapp for monitoring resources like CPU/GPU temperatures. It
|
||||||
supports up to 2 different readings.
|
supports up to 2 different readings.
|
||||||
|
|
||||||
.. image:: /images/pywmtemp.png?raw=true
|
.. image:: /images/pywmtemp.gif?raw=true
|
||||||
:alt: wmamixer overview
|
: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.
|
readings using information found on /sys file system.
|
||||||
"""
|
"""
|
||||||
background_color = '#202020'
|
background_color = '#202020'
|
||||||
x_offset = 3
|
|
||||||
y_offset = 3
|
|
||||||
font_dimentions = (6, 8)
|
|
||||||
graph_width = 58
|
graph_width = 58
|
||||||
graph_max_height = 36
|
graph_max_height = 36
|
||||||
graph_coords = (3, 25)
|
graph_coords = (3, 25)
|
||||||
|
|
||||||
def __init__(self, args=None):
|
def __init__(self, args=None):
|
||||||
super().__init__(args)
|
super().__init__(args)
|
||||||
self.font = FONT
|
self._debug = args.debug
|
||||||
|
self.fonts = [wmdocklib.BitmapFonts(FONT, (6, 8))]
|
||||||
self.background = BACKGROUND
|
self.background = BACKGROUND
|
||||||
self.max_chars_in_line = None
|
|
||||||
self.conf = {}
|
self.conf = {}
|
||||||
self.critical = 0
|
self.critical = 0
|
||||||
self.warning = 0
|
self.warning = 0
|
||||||
@@ -196,12 +193,7 @@ class SensorDockApp(wmdocklib.DockApp):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.prepare_pixmaps()
|
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()
|
self.open_xwindow()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.main_loop()
|
self.main_loop()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
@@ -220,11 +212,9 @@ class SensorDockApp(wmdocklib.DockApp):
|
|||||||
# ignored.
|
# ignored.
|
||||||
for item in self.conf.get('readings', [])[:2]:
|
for item in self.conf.get('readings', [])[:2]:
|
||||||
self._put_string(item, position)
|
self._put_string(item, position)
|
||||||
position += self.char_height
|
position += self.fonts[0].height
|
||||||
self._draw_graph()
|
self._draw_graph()
|
||||||
name = self._current_graph.upper()
|
self._draw_graph_label()
|
||||||
name = name[:4]
|
|
||||||
self.add_string(name, 1, 50)
|
|
||||||
|
|
||||||
count += 1
|
count += 1
|
||||||
if count >= 10:
|
if count >= 10:
|
||||||
@@ -240,33 +230,51 @@ class SensorDockApp(wmdocklib.DockApp):
|
|||||||
temp = None
|
temp = None
|
||||||
temps = psutil.sensors_temperatures()
|
temps = psutil.sensors_temperatures()
|
||||||
for shw in temps.get(item.get('sensor'), []):
|
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'):
|
if shw.label == item.get('label'):
|
||||||
temp = shw
|
temp = shw
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
# in case there is no items matched.
|
||||||
|
return ' ', 0
|
||||||
|
|
||||||
value = int(temp.current)
|
value = int(temp.current)
|
||||||
name = item.get('name')
|
name = item.get('name')
|
||||||
self._history[name] = self._history[name][1:]
|
self._history[name] = self._history[name][1:]
|
||||||
self._history[name].append(value)
|
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
|
# shift charset depending on the threshold defined in config, assuming
|
||||||
# charset is the same row(s) copied with different color for warning
|
# charset is the same row(s) copied with different color for warning
|
||||||
# and critival.
|
# and critical.
|
||||||
# FIXME: remove hardcoded multiplies in favor of automatically
|
# FIXME: remove hardcoded multiplies in favor of automatically
|
||||||
# computed factors.
|
# computed factors.
|
||||||
displacement = 0
|
displacement = 0
|
||||||
if item.get('override_warning') and value >= item['override_warning']:
|
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:
|
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
|
if (item.get('override_critical') and
|
||||||
value >= item['override_critical']):
|
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:
|
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:
|
if displacement:
|
||||||
string = ''.join([chr(ord(i) + displacement) for i in string])
|
string = ''.join([chr(ord(i) + displacement) for i in string])
|
||||||
|
|
||||||
@@ -323,18 +331,32 @@ class SensorDockApp(wmdocklib.DockApp):
|
|||||||
def _put_string(self, item, position):
|
def _put_string(self, item, position):
|
||||||
temp, displacement = self.get_reading(item)
|
temp, displacement = self.get_reading(item)
|
||||||
name = item.get('name', '').upper()
|
name = item.get('name', '').upper()
|
||||||
name = name[:4]
|
name = f'{name[:4]:4}'
|
||||||
if displacement:
|
if displacement:
|
||||||
name = ''.join([chr(ord(i) + displacement)
|
name = ''.join([chr(ord(i) + displacement)
|
||||||
for i in name])
|
for i in name])
|
||||||
|
|
||||||
self.add_string(name, 1, position)
|
self.fonts[0].add_string(name, 1, position)
|
||||||
self.add_string(temp, 34, 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():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('-c', '--config', help='Alternate config file')
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
dockapp = SensorDockApp(args)
|
dockapp = SensorDockApp(args)
|
||||||
|
|||||||
@@ -19,14 +19,12 @@ classifier =
|
|||||||
Programming Language :: Python :: 3.10
|
Programming Language :: Python :: 3.10
|
||||||
Topic :: System :: Networking
|
Topic :: System :: Networking
|
||||||
|
|
||||||
[install]
|
|
||||||
record = install.log
|
|
||||||
|
|
||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
console_scripts =
|
console_scripts =
|
||||||
pywmtemp = pywmtemp.pywmtemp:main
|
pywmtemp = pywmtemp.pywmtemp:main
|
||||||
|
|
||||||
[options]
|
[options]
|
||||||
|
packages = pywmtemp
|
||||||
install_requires =
|
install_requires =
|
||||||
wmdocklib
|
wmdocklib
|
||||||
pyyaml
|
pyyaml
|
||||||
|
|||||||
Reference in New Issue
Block a user