Skip to content

Commit 055c33f

Browse files
committed
Merge branch 'main' of https://github.com/amnweb/yasb
2 parents 41b9151 + 9c6738f commit 055c33f

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

docs/widgets/(Widget)-GPU.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ If you see a table with your GPU information, `nvidia-smi` is available. If you
2929
| `label_shadow` | dict | `{"enabled": False, "color": "black", "offset": [1, 1], "radius": 3}` | Label shadow options. |
3030
| `progress_bar` | dict | `{'enabled': false, 'position': 'left', 'size': 14, 'thickness': 2, 'color': '#57948a', 'animation': false}` | Progress bar settings. |
3131
| `hide_decimal` | bool | `false` | Whether to hide decimal places in the GPU widget. |
32+
| `units` | string | `"metric"` | Whether the temperature is converted to Fahrenheit (if set to `"imperial"`) or Celsius (if not set or explicitly set to `"metric"`) |
3233

3334
> **About `index`:** If you have multiple NVIDIA GPUs, you can set the `gpu_index` option to select which GPU to monitor. Create multiple GPU widgets with different `gpu_index` values (e.g., 0, 1, 2, ...) to display stats for each card separately.
3435

src/core/validation/widgets/yasb/gpu.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"callbacks": {"on_left": "toggle_label", "on_middle": "do_nothing", "on_right": "do_nothing"},
1212
"gpu_thresholds": {"low": 30, "medium": 60, "high": 90},
1313
"hide_decimal": False,
14+
"units": "metric",
1415
}
1516

1617
VALIDATION_SCHEMA = {
@@ -124,4 +125,5 @@
124125
"default": DEFAULTS["gpu_thresholds"],
125126
},
126127
"hide_decimal": {"type": "boolean", "default": DEFAULTS["hide_decimal"]},
128+
"units": {"type": "string", "default": DEFAULTS["units"], "allowed": ["metric", "imperial"]},
127129
}

src/core/widgets/yasb/gpu.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def __init__(
3636
container_padding: dict[str, int],
3737
callbacks: dict[str, str],
3838
gpu_thresholds: dict[str, int],
39+
units: str,
3940
label_shadow: dict = None,
4041
container_shadow: dict = None,
4142
progress_bar: dict = None,
@@ -54,6 +55,7 @@ def __init__(
5455
self._label_shadow = label_shadow
5556
self._container_shadow = container_shadow
5657
self._gpu_thresholds = gpu_thresholds
58+
self._units = units
5759
self._progress_bar = progress_bar
5860
self._hide_decimal = hide_decimal
5961

@@ -173,15 +175,16 @@ def _update_label(self, gpu_data):
173175
"""Update the label with GPU data."""
174176
self._gpu_util_history.append(gpu_data.utilization)
175177
self._gpu_mem_history.append(gpu_data.mem_used)
176-
178+
_temp = gpu_data.temp if self._units == "metric" else (gpu_data.temp * (9 / 5) + 32)
179+
_temp = round(_temp) if self._hide_decimal else _temp
177180
_naturalsize = lambda value: naturalsize(value, True, True, "%.0f" if self._hide_decimal else "%.1f")
178181
gpu_info = {
179182
"index": gpu_data.index,
180183
"utilization": gpu_data.utilization,
181184
"mem_total": _naturalsize(gpu_data.mem_total * 1024 * 1024),
182185
"mem_used": _naturalsize(gpu_data.mem_used * 1024 * 1024),
183186
"mem_free": _naturalsize(gpu_data.mem_free * 1024 * 1024),
184-
"temp": gpu_data.temp,
187+
"temp": _temp,
185188
"fan_speed": gpu_data.fan_speed,
186189
"histograms": {
187190
"utilization": "".join([self._get_histogram_bar(val, 0, 100) for val in self._gpu_util_history]),

0 commit comments

Comments
 (0)