1
0
mirror of https://github.com/gryf/pywmtemp.git synced 2026-02-02 14:15:53 +01:00

11 Commits
1.0 ... master

Author SHA1 Message Date
7295d8123d Added guard for unlabeled sensors 2025-07-31 16:42:53 +02:00
6f805d8bdc Fix for phony multiple packages 2023-06-03 11:50:33 +02:00
1f51add078 Add guard for nonexistent pattern to match with. 2022-09-16 17:08:59 +02:00
6f9b91d525 Added package information to setup.cfg. 2022-06-03 12:37:13 +02:00
9f18dfdf26 Added debug switch.
For now it only saves merged xpm image.
2022-05-21 10:43:15 +02:00
56f85d4887 Image update 2022-05-06 17:37:58 +02:00
bfb37a5b63 Added some visual adjustment for the label on the graph.
Font set used in this app have additional 1 pixel gap right after the
character and 1 pixel below it, just to not deal with different
character width. In this patch there was added some space above the
label and on the left side for the completeness.
2022-05-05 18:46:09 +02:00
580dc45c2a If value for the reading is too long, trim it.
I know, that this is kind of naive implementation, but in case of
temperatures there is a more serious issue than trimming, if any of the
HW component exceeds 1000 Celsius degrees ;)
2022-05-05 18:43:23 +02:00
d02ecefdf3 Readme update 2022-05-05 16:38:09 +02:00
d4bd3b19d3 Apply color for not used 'lcd' cells 2022-05-05 16:37:04 +02:00
ac56074faf Adapt to newest wmdocklib changes. 2022-05-03 18:53:50 +02:00
5 changed files with 47 additions and 27 deletions

View File

@@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -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)

View File

@@ -19,14 +19,12 @@ classifier =
Programming Language :: Python :: 3.10
Topic :: System :: Networking
[install]
record = install.log
[options.entry_points]
console_scripts =
pywmtemp = pywmtemp.pywmtemp:main
[options]
packages = pywmtemp
install_requires =
wmdocklib
pyyaml