Skip to content

Commit 980577f

Browse files
authored
Merge pull request #542 from mathoudebine/dev/492-systemuptime
2 parents c65f270 + 8cf7150 commit 980577f

File tree

7 files changed

+86
-0
lines changed

7 files changed

+86
-0
lines changed

library/scheduler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ def DateStats():
155155
# logger.debug("Refresh date stats")
156156
stats.Date.stats()
157157

158+
@async_job("SystemUptime_Stats")
159+
@schedule(timedelta(seconds=config.THEME_DATA['STATS']['UPTIME'].get("INTERVAL", 0)).total_seconds())
160+
def SystemUptimeStats():
161+
# logger.debug("Refresh system uptime stats")
162+
stats.SystemUptime.stats()
158163

159164
@async_job("Custom_Stats")
160165
@schedule(timedelta(seconds=config.THEME_DATA['STATS']['CUSTOM'].get("INTERVAL", 0)).total_seconds())

library/stats.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import babel.dates
3232
from psutil._common import bytes2human
33+
from uptime import uptime
3334

3435
import library.config as config
3536
from library.display import display
@@ -88,6 +89,9 @@ def display_themed_value(theme_data, value, min_size=0, unit=''):
8889
if not theme_data.get("SHOW", False):
8990
return
9091

92+
if value is None:
93+
return
94+
9195
# overridable MIN_SIZE from theme with backward compatibility
9296
min_size = theme_data.get("MIN_SIZE", min_size)
9397

@@ -750,6 +754,32 @@ def stats():
750754
)
751755

752756

757+
class SystemUptime:
758+
@staticmethod
759+
def stats():
760+
if HW_SENSORS == "STATIC":
761+
# For static sensors, use predefined uptime
762+
uptimesec = 4294036
763+
else:
764+
uptimesec = int(uptime())
765+
766+
uptimeformatted = str(datetime.timedelta(seconds=uptimesec))
767+
768+
systemuptime_theme_data = config.THEME_DATA['STATS']['UPTIME']
769+
770+
systemuptime_sec_theme_data = systemuptime_theme_data['SECONDS']['TEXT']
771+
display_themed_value(
772+
theme_data=systemuptime_sec_theme_data,
773+
value=uptimesec
774+
)
775+
776+
systemuptime_formatted_theme_data = systemuptime_theme_data['FORMATTED']['TEXT']
777+
display_themed_value(
778+
theme_data=systemuptime_formatted_theme_data,
779+
value=uptimeformatted
780+
)
781+
782+
753783
class Custom:
754784
@staticmethod
755785
def stats():

main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ def on_win32_wm_event(hWnd, msg, wParam, lParam):
208208
scheduler.DiskStats()
209209
scheduler.NetStats()
210210
scheduler.DateStats()
211+
scheduler.SystemUptimeStats()
211212
scheduler.CustomStats()
212213
scheduler.QueueHandler()
213214

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ babel~=2.15.0 # Date/time formatting
88
ruamel.yaml~=0.18.6 # For configuration editor
99
sv-ttk~=2.6.0 # Tk Sun Valley theme for configuration editor
1010
tkinter-tooltip~=3.1.0 # Tooltips for configuration editor
11+
uptime~=3.0.1 # For System Uptime
1112

1213
# Efficient image serialization
1314
numpy~=1.24.4; python_version < "3.9" # For Python 3.8 max.

res/themes/default.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,13 @@ STATS:
209209
HOUR:
210210
TEXT:
211211
SHOW: False
212+
UPTIME:
213+
INTERVAL: 0
214+
SECONDS:
215+
TEXT:
216+
SHOW: False
217+
FORMATTED:
218+
TEXT:
219+
SHOW: False
212220
CUSTOM:
213221
INTERVAL: 0

res/themes/theme_example.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,3 +1427,42 @@ STATS:
14271427
BACKGROUND_IMAGE: background.png
14281428
ALIGN: left # left / center / right
14291429
ANCHOR: lt # Check https://pillow.readthedocs.io/en/stable/handbook/text-anchors.html
1430+
UPTIME:
1431+
# For seconds display, it is recommended not to change the interval: keep to 1
1432+
INTERVAL: 1
1433+
SECONDS: # Uptime as seconds
1434+
TEXT:
1435+
SHOW: FALSE
1436+
X: 192
1437+
Y: 261
1438+
# Text sensors may vary in size and create "ghosting" effects where old value stay displayed under the new one.
1439+
# To avoid this use one of these 2 methods (or both):
1440+
# - either use a monospaced font (fonts with "mono" in name, see res/fonts/ for available fonts)
1441+
# - or force a static width/height for the text field. Be sure to have enough space for the longest value that can be displayed (e.g. "100%" for a percentage)
1442+
# WIDTH: 200 # Uncomment to force a static width
1443+
# HEIGHT: 50 # Uncomment to force static height
1444+
FONT: jetbrains-mono/JetBrainsMono-Bold.ttf
1445+
FONT_SIZE: 23
1446+
FONT_COLOR: 255, 255, 255
1447+
# BACKGROUND_COLOR: 132, 154, 165
1448+
BACKGROUND_IMAGE: background.png
1449+
ALIGN: left # left / center / right
1450+
ANCHOR: lt # Check https://pillow.readthedocs.io/en/stable/handbook/text-anchors.html
1451+
FORMATTED: # Uptime as formatted string with days e.g. "49 days, 16:47:16"
1452+
TEXT:
1453+
SHOW: FALSE
1454+
X: 192
1455+
Y: 261
1456+
# Text sensors may vary in size and create "ghosting" effects where old value stay displayed under the new one.
1457+
# To avoid this use one of these 2 methods (or both):
1458+
# - either use a monospaced font (fonts with "mono" in name, see res/fonts/ for available fonts)
1459+
# - or force a static width/height for the text field. Be sure to have enough space for the longest value that can be displayed (e.g. "100%" for a percentage)
1460+
# WIDTH: 200 # Uncomment to force a static width
1461+
# HEIGHT: 50 # Uncomment to force static height
1462+
FONT: jetbrains-mono/JetBrainsMono-Bold.ttf
1463+
FONT_SIZE: 23
1464+
FONT_COLOR: 255, 255, 255
1465+
# BACKGROUND_COLOR: 132, 154, 165
1466+
BACKGROUND_IMAGE: background.png
1467+
ALIGN: left # left / center / right
1468+
ANCHOR: lt # Check https://pillow.readthedocs.io/en/stable/handbook/text-anchors.html

theme-editor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ def refresh_theme():
121121
stats.Net.stats()
122122
if config.THEME_DATA['STATS']['DATE'].get("INTERVAL", 0) > 0:
123123
stats.Date.stats()
124+
if config.THEME_DATA['STATS']['UPTIME'].get("INTERVAL", 0) > 0:
125+
stats.SystemUptime.stats()
124126
if config.THEME_DATA['STATS']['CUSTOM'].get("INTERVAL", 0) > 0:
125127
stats.Custom.stats()
126128

0 commit comments

Comments
 (0)