10 changed files with 467 additions and 408 deletions

No files matched your search

@@ -0,0 +1,37 @@
# System Overview — monitor app
A system overview in one 1024x768 window, in the btop style: four
`XSysBox` composite boxes (CPU / MEM / NET / DISK), one `XLoadBadge`
(live load averages + uptime), two `XDonutGauge`s (CPU, Disk) and three
`XUsageBar`s (Memory, Disk, Network). All values are read live from
`/proc` (`stat`, `meminfo`, `net/dev`, `loadavg`, `uptime`) and
`statvfs("/")`, refreshed every 500 ms. No seeded demo data is shown:
the SysBox history graphs are flushed with live ticks before the
screenshot is taken (60 samples at 500 ms ≈ 30 s of run time).
Window title: `System Overview - monitor`.
## Widgets used
- `XSysBox` × 4 — CPU, MEM, NET (KB/s), DISK /
- `XLoadBadge` × 1 — 1 / 5 / 15 min load averages + uptime
- `XDonutGauge` × 2 — CPU, Disk /
- `XUsageBar` × 3 — Memory, Disk /, Network KB/s
## Build and run
```sh
make # builds ./system-overview
./system-overview # needs an X display; Esc / q / window-close quits
```
## Source
- C: `examples/monitor/system-overview/main.cpp` in
https://github.com/cnmcdee/lightgui
- Rust: `crates/xframe-demo/examples/monitor_system_overview.rs` in
https://github.com/cnmcdee/lightgui_rust
- Python: `examples/monitor_system_overview/main.py` in
https://github.com/cnmcdee/lightgui_python
Walkthrough: https://www.lightgui.com/monitor-system-overview/
+256
View File
@@ -0,0 +1,256 @@
#!/usr/bin/env python3
"""System Overview - monitor app (Stage 2, btop-widget project).
One 1024x768 window: four XSysBox composites (CPU / MEM / NET / DISK),
one XLoadBadge (live load averages + uptime), two XDonutGauges (CPU,
Disk) and three XUsageBars (Memory, Disk, Network). All values are read
live from /proc (stat, meminfo, net/dev, loadavg, uptime) and
shutil.disk_usage("/"), refreshed every 500 ms. push() starts a fresh
series, so the SysBox graphs show live ticks only -- no seeded demo
data.
Run with the LightGUI Python package on PYTHONPATH:
PYTHONPATH=/root/monitor-wt/system-overview/lightgui_python \
python3 examples/monitor_system_overview/main.py
Press Esc / q or close the window to quit.
"""
import os
import shutil
import sys
import time
import gi
gi.require_version("Gtk", "3.0")
gi.require_version("Gdk", "3.0")
from gi.repository import Gdk, GLib, Gtk # noqa: E402
from lightgui.xframe.core import create, parse_color # noqa: E402
# ---------------------------------------------------------------------------
# Live data from /proc
# ---------------------------------------------------------------------------
class Sampler:
def __init__(self):
self.prev_idle = 0
self.prev_total = 0
self.prev_rx = 0
self.prev_t = None
def cpu(self):
try:
with open("/proc/stat") as f:
fields = f.readline().split()[1:9]
nums = [int(v) for v in fields]
except (OSError, ValueError):
return None
idle = nums[3] + nums[4]
total = sum(nums)
if self.prev_total == 0:
self.prev_idle, self.prev_total = idle, total
return None
d_total = total - self.prev_total
d_idle = idle - self.prev_idle
self.prev_idle, self.prev_total = idle, total
if d_total == 0:
return None
return 100.0 * (1.0 - d_idle / d_total)
def mem(self):
total = avail = 0
try:
with open("/proc/meminfo") as f:
for line in f:
parts = line.split()
if parts[0] == "MemTotal:":
total = int(parts[1])
elif parts[0] == "MemAvailable:":
avail = int(parts[1])
except (OSError, ValueError):
return None
if total == 0:
return None
return 100.0 * (1.0 - avail / total)
def net_kbps(self):
rx_total = 0
try:
with open("/proc/net/dev") as f:
lines = f.readlines()[2:]
for line in lines:
iface, rest = line.split(":", 1)
if iface.strip() == "lo":
continue
rx_total += int(rest.split()[0])
except (OSError, ValueError):
return None
now = time.time()
if self.prev_t is None:
self.prev_rx, self.prev_t = rx_total, now
return None
dt = now - self.prev_t
delta = rx_total - self.prev_rx
self.prev_rx, self.prev_t = rx_total, now
if dt <= 0:
return None
return delta / dt / 1024.0
@staticmethod
def disk():
try:
du = shutil.disk_usage("/")
except OSError:
return None
if du.total == 0:
return None
return 100.0 * (1.0 - du.free / du.total)
SAMPLER = Sampler()
DATA = {"cpu": 0.0, "mem": 0.0, "net": 0.0, "disk": 0.0}
def sample():
v = SAMPLER.cpu()
if v is not None:
DATA["cpu"] = v
v = SAMPLER.mem()
if v is not None:
DATA["mem"] = v
v = SAMPLER.net_kbps()
if v is not None:
DATA["net"] = v
v = SAMPLER.disk()
if v is not None:
DATA["disk"] = v
# ---------------------------------------------------------------------------
# App shell (same pattern as the generated widget examples: GTK window +
# DrawingArea, widgets drawn via widget.draw(cr))
# ---------------------------------------------------------------------------
_DESIGN_SIZE = (1024, 768)
_BACKGROUND = ""
_WIDGETS = []
_AREA = []
def _build_widgets():
widgets = []
badge = create("XLoadBadge", "badge", 16, 12, 992, 84)
widgets.append(badge)
cpu = create("XSysBox", "cpu", 16, 108, 488, 200)
cpu.set_prop("label", "CPU")
cpu.set_prop("unit", "%")
cpu.set_prop("maximum", "100")
widgets.append(cpu)
mem = create("XSysBox", "mem", 520, 108, 488, 200)
mem.set_prop("label", "MEM")
mem.set_prop("unit", "%")
mem.set_prop("maximum", "100")
widgets.append(mem)
net = create("XSysBox", "net", 16, 320, 488, 200)
net.set_prop("label", "NET")
net.set_prop("unit", " KB/s")
net.set_prop("maximum", "1000")
widgets.append(net)
disk = create("XSysBox", "disk", 520, 320, 488, 200)
disk.set_prop("label", "DISK /")
disk.set_prop("unit", "%")
disk.set_prop("maximum", "100")
widgets.append(disk)
donut_cpu = create("XDonutGauge", "donut_cpu", 16, 532, 180, 180)
donut_cpu.set_prop("label", "CPU")
donut_cpu.set_prop("unit", "CPU")
widgets.append(donut_cpu)
donut_disk = create("XDonutGauge", "donut_disk", 212, 532, 180, 180)
donut_disk.set_prop("label", "Disk /")
donut_disk.set_prop("unit", "Disk /")
widgets.append(donut_disk)
bar_mem = create("XUsageBar", "bar_mem", 408, 532, 600, 44)
bar_mem.set_prop("label", "Memory")
bar_mem.set_prop("maximum", "100")
widgets.append(bar_mem)
bar_disk = create("XUsageBar", "bar_disk", 408, 596, 600, 44)
bar_disk.set_prop("label", "Disk /")
bar_disk.set_prop("maximum", "100")
widgets.append(bar_disk)
# UsageBar prints its raw value with a "%" sign, so feed it the
# percent-of-1000-KB/s-max, with maximum 100, to keep text + fill true.
bar_net = create("XUsageBar", "bar_net", 408, 660, 600, 44)
bar_net.set_prop("label", "Network KB/s")
bar_net.set_prop("maximum", "100")
widgets.append(bar_net)
return widgets
def _push(widgets):
by_name = {w.name: w for w in widgets}
by_name["badge"].refresh_load()
for name, key in (("cpu", "cpu"), ("mem", "mem"),
("net", "net"), ("disk", "disk")):
w = by_name[name]
w.push(DATA[key])
w.set_value(DATA[key])
by_name["donut_cpu"].set_value(DATA["cpu"])
by_name["donut_disk"].set_value(DATA["disk"])
by_name["bar_mem"].set_value(DATA["mem"])
by_name["bar_disk"].set_value(DATA["disk"])
by_name["bar_net"].set_value(DATA["net"] / 10.0)
def _tick():
sample()
_push(_WIDGETS)
if _AREA:
_AREA[0].queue_draw()
return True
def _on_draw(area, cr):
bg = parse_color(_BACKGROUND, None)
if bg is None:
bg = (1.0, 1.0, 1.0)
cr.set_source_rgb(*bg)
cr.paint()
for widget in _WIDGETS:
widget.draw(cr)
return False
def _on_key_press(window, event):
key = Gdk.keyval_name(event.keyval)
if key in ("Escape", "q", "Q"):
Gtk.main_quit()
return True
return False
def main():
window = Gtk.Window(title="System Overview - monitor")
window.set_default_size(1024, 768)
window.connect("destroy", Gtk.main_quit)
window.connect("key-press-event", _on_key_press)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0)
window.add(vbox)
area = Gtk.DrawingArea()
area.set_hexpand(True)
area.set_vexpand(True)
area.connect("draw", _on_draw)
vbox.pack_start(area, True, True, 0)
_WIDGETS.extend(_build_widgets())
_AREA.append(area)
sample()
_push(_WIDGETS)
GLib.timeout_add(500, _tick)
window.show_all()
Gtk.main()
return 0
if __name__ == "__main__":
sys.exit(main())
Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

+1 -1
View File
@@ -62,7 +62,7 @@ def _build_widgets():
"""Create every placed widget with its props."""
widgets = []
widget = create('XMonitorButton', 'XMonitorButton_001', 16, 16, 200, 48)
widget.set_prop("label", "sshd :22")
widget.set_prop("label", "SSH :22")
widget.set_prop("check-type", "Port")
widget.set_prop("target", "22")
# Live data: poll the check now; the timer re-polls.
+1 -1
View File
@@ -67,7 +67,7 @@ def _build_widgets():
# closed port (shows the red/down state).
widget.add_monitor("process", "python3", "Python")
widget.add_monitor("unit", "sshd", "sshd unit")
widget.add_monitor("port", "22", "sshd :22")
widget.add_monitor("port", "22", "SSH :22")
widget.add_monitor("port", "9999", "Port 9999")
widget.poll_all()
widgets.append(widget)
+5 -6
View File
@@ -30,7 +30,7 @@ _HANDLERS = {
# Design-time geometry + effective anchors per widget:
# name -> (top, left, right, bottom, x, y, width, height)
_ANCHORS = {
'XStackBar_001': (True, True, False, False, 16, 16, 320, 120),
'XStackBar_001': (True, True, False, False, 16, 16, 320, 48),
}
@@ -60,15 +60,14 @@ def _apply_anchors(widgets, width, height):
def _build_widgets():
"""Create every placed widget with its props."""
widgets = []
widget = create('XStackBar', 'XStackBar_001', 16, 16, 320, 120)
widget = create('XStackBar', 'XStackBar_001', 16, 16, 320, 48)
widget.set_prop("label", "Memory")
widget.set_prop("segments", "used=11.7|cached=15.5|buffers=1.2|free=1.9")
widget.set_prop("unit", "GiB")
widget.set_prop("segments", "used=45|cached=25|buffers=10|free=20")
widgets.append(widget)
return widgets
_DESIGN_SIZE = (352, 152)
_DESIGN_SIZE = (352, 80)
_BACKGROUND = ''
_WIDGETS = []
_LAST_SIZE = [None]
@@ -145,7 +144,7 @@ def _on_area_resize(area, allocation):
def main():
window = Gtk.Window(title='XStackBar example')
window.set_default_size(352, 152)
window.set_default_size(352, 80)
window.connect("destroy", Gtk.main_quit)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
spacing=0)
+1 -1
View File
@@ -62,7 +62,7 @@ def _build_widgets():
"""Create every placed widget with its props."""
widgets = []
widget = create('XTachometer', 'XTachometer_001', 16, 16, 220, 180)
widget.set_prop("label", "RPM")
widget.set_prop("label", "Engine")
widget.set_prop("value", "3200")
widget.set_prop("maximum", "8000")
widget.set_prop("redline", "6500")
+4 -4
View File
@@ -31,7 +31,7 @@ _HANDLERS = {
# Design-time geometry + effective anchors per widget:
# name -> (top, left, right, bottom, x, y, width, height)
_ANCHORS = {
'XVerticalBar_001': (True, True, False, False, 16, 16, 160, 200),
'XVerticalBar_001': (True, True, False, False, 16, 16, 60, 200),
}
@@ -61,7 +61,7 @@ def _apply_anchors(widgets, width, height):
def _build_widgets():
"""Create every placed widget with its props."""
widgets = []
widget = create('XVerticalBar', 'XVerticalBar_001', 16, 16, 160, 200)
widget = create('XVerticalBar', 'XVerticalBar_001', 16, 16, 60, 200)
widget.set_prop("label", "CPU")
# Seed the peak-hold marker: 82, then back to 65.
widget.set_value(65)
@@ -71,7 +71,7 @@ def _build_widgets():
return widgets
_DESIGN_SIZE = (192, 232)
_DESIGN_SIZE = (92, 232)
_BACKGROUND = ''
_WIDGETS = []
_LAST_SIZE = [None]
@@ -166,7 +166,7 @@ def _tick():
def main():
window = Gtk.Window(title='XVerticalBar example')
window.set_default_size(192, 232)
window.set_default_size(92, 232)
window.connect("destroy", Gtk.main_quit)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
spacing=0)
-2
View File
@@ -83,8 +83,6 @@ MONITOR_TABLES = {
_label(),
PropDef("segments", "Str", "", 0, 0, (), (),
"Segments", False),
# Unit for the "total <sum> <unit>" header (e.g. GiB).
_unit(),
),
"XVerticalBar": (
_label(),
+162 -393
View File
@@ -39,7 +39,6 @@ from lightgui.xframe.core import (
_rounded_box,
_rounded_path,
_text_width,
_wrap_lines,
_wtext,
parse_color,
)
@@ -106,23 +105,6 @@ def _fmt_bytes(nbytes):
return "%.1f TiB" % value
def _fpx(value, lo, hi):
"""Font size derived from a widget dimension, clamped to [lo, hi]
(sane minimum 11px so text never shrinks to unreadable)."""
return max(lo, min(hi, value))
def _peak_fit(cr, widget, peak, bar_x, bar_w):
"""Peak-label size: 14px bold, shrinking to 11px when the bar is
too narrow for the label to fit inside the frame."""
text = "peak %.0f" % peak
avail = bar_x + bar_w - 2 - 8
for size in (14, 13, 12, 11):
if _text_width(cr, widget, text, size=size, bold=True) <= avail:
return size
return 11
def _fmt_uptime(seconds):
"""'up 2d 14:21' from a seconds count."""
seconds = max(0, int(seconds))
@@ -310,18 +292,16 @@ def _panel(cr, widget, title=None):
_rounded_box(cr, 0, 0, widget.width, widget.height, _PANEL,
_PANEL_EDGE, line_width=1.0, radius=4)
if title:
_wtext(cr, widget, title, 8, 17, size=16, rgb=_TITLE, bold=True,
_wtext(cr, widget, title, 8, 15, size=12, rgb=_TITLE, bold=True,
max_width=widget.width - 16)
return 24
return 22
return 6
def _plot_frame(cr, x, y, w, h, lo, hi, labels=True, label_size=14,
fmt=None):
def _plot_frame(cr, x, y, w, h, lo, hi, labels=True):
"""Plot area: dark inner fill, horizontal grid lines + y labels
at 0/25/50/75/100% of the range. *labels* is False when the plot
starts too close to the left edge for labels to fit. *fmt* formats
the tick values (humanised rates for the net graph)."""
starts too close to the left edge for labels to fit."""
if w <= 0 or h <= 0:
return
_box(cr, x, y, w, h, _PANEL_INNER, _GRID)
@@ -336,28 +316,16 @@ def _plot_frame(cr, x, y, w, h, lo, hi, labels=True, label_size=14,
cr.restore()
if not labels:
return
for i in range(5):
frac = i / 4.0
value = lo + frac * (hi - lo)
label = fmt(value) if fmt is not None else "%.0f" % value
gy = y + h - frac * h
# Top label hangs below its gridline (clear of the title),
# bottom label sits above its gridline (clear of the strip
# below the plot); middle labels are centred on the line.
if i == 4:
ybase = gy + label_size * 0.75
elif i == 0:
ybase = gy - 2
else:
ybase = gy + label_size * 0.35
_ylabel(cr, label, x - 4, ybase, size=label_size)
for frac, label in ((0.0, "%.0f" % lo), (0.5, "%.0f" % ((lo + hi) / 2)),
(1.0, "%.0f" % hi)):
_ylabel(cr, label, x - 2, y + h - frac * h + 3)
def _ylabel(cr, text, x, y, size=8):
"""Small dim right-aligned y-axis label (baseline *y*)."""
def _ylabel(cr, text, x, y):
"""Small dim right-aligned y-axis label."""
cr.save()
cr.select_font_face("Sans", 0, 0)
cr.set_font_size(size)
cr.set_font_size(8)
_rgb(cr, _DIM)
w = cr.text_extents(text)[2]
cr.move_to(x - w, y)
@@ -365,16 +333,6 @@ def _ylabel(cr, text, x, y, size=8):
cr.restore()
def _y_axis_width(cr, widget, lo, hi, size, fmt=None):
"""Left margin for a plot: widest of the 5 Y labels + 10px."""
widest = 0.0
for i in range(5):
value = lo + (i / 4.0) * (hi - lo)
label = fmt(value) if fmt is not None else "%.0f" % value
widest = max(widest, _text_width(cr, widget, label, size=size))
return widest + 10
def _series_line(cr, values, x, y, w, h, lo, hi, color, width=1.5,
fill=False):
"""Polyline for *values* (oldest left, newest right) in the
@@ -894,8 +852,8 @@ class MonitorWidget(Widget):
def _cell_layout(self):
"""(x, y, w, h) per grid cell inside the widget."""
cols = 2 if self.width < 300 else 3
count = max(1, len(self._monitors))
cols = max(1, math.ceil(math.sqrt(count)))
rows = (count + cols - 1) // cols
pad, gap = 8, 6
top = 26
@@ -935,15 +893,15 @@ class MonitorWidget(Widget):
for i, values in enumerate(series):
cur, mn, mx, avg = _stats(values)
color = _SERIES_COLORS[i % len(_SERIES_COLORS)]
_box(cr, 8, y - 10, 10, 10, color, color)
_box(cr, 8, y - 8, 8, 8, color, color)
if cur is None:
line = "%s --" % names[i]
else:
line = "%s %.1f%s min %.1f max %.1f avg %.1f" % (
names[i], cur, unit, mn, mx, avg)
_wtext(cr, self, line, 24, y, size=14, rgb=_TEXT,
max_width=self.width - 30)
y += 18
_wtext(cr, self, line, 22, y, size=10, rgb=_TEXT,
max_width=self.width - 28)
y += 14
return y
def _draw_history_graph(self, cr):
@@ -955,26 +913,16 @@ class MonitorWidget(Widget):
series = self._plot_series()
names = self._series_names()
show_legend = _prop_bool(self, "show-legend", True)
body_px = _fpx(0.032 * self.height, 11, 16)
legend_h = 18 * len(series) if show_legend else 0
legend_y = top + 13
if show_legend:
self._legend(cr, legend_y, series, names)
plot_x = _y_axis_width(cr, self, lo, hi, body_px)
plot_y = top + legend_h + 4
plot_w = max(1, self.width - plot_x - 8)
plot_h = max(1, self.height - plot_y - 22)
_plot_frame(cr, plot_x, plot_y, plot_w, plot_h, lo, hi,
label_size=body_px)
legend_h = 14 * len(series) if show_legend else 0
plot_x, plot_y = 34, top + 2
plot_w = max(1, self.width - 40)
plot_h = max(1, self.height - plot_y - legend_h - 6)
_plot_frame(cr, plot_x, plot_y, plot_w, plot_h, lo, hi)
for i, values in enumerate(series):
_series_line(cr, values, plot_x, plot_y, plot_w, plot_h,
lo, hi, _SERIES_COLORS[i % len(_SERIES_COLORS)])
# Time axis: "-60s" left, "now" right.
time_px = _fpx(0.028 * self.height, 11, 14)
_wtext(cr, self, "-60s", plot_x, self.height - 5, size=time_px,
rgb=_DIM)
_wtext(cr, self, "now", plot_x + plot_w, self.height - 5,
size=time_px, rgb=_DIM, align="right")
if show_legend:
self._legend(cr, plot_y + plot_h + 12, series, names)
def _draw_core_grid(self, cr):
top = _panel(cr, self, self._title())
@@ -985,7 +933,6 @@ class MonitorWidget(Widget):
pad, gap = 6, 4
cw = (self.width - 2 * pad - (cols - 1) * gap) / cols
ch = (self.height - top - pad - (rows - 1) * gap) / rows
cell_px = _fpx(0.10 * ch, 11, 16)
for i, values in enumerate(series):
r, c = divmod(i, cols)
x = pad + c * (cw + gap)
@@ -994,15 +941,14 @@ class MonitorWidget(Widget):
radius=3)
color = _SERIES_COLORS[i % len(_SERIES_COLORS)]
cur = values[-1] if values else 0.0
_wtext(cr, self, "C%d" % i, x + 6, y + cell_px + 2,
size=cell_px, rgb=_DIM, bold=True)
_wtext(cr, self, "%.0f%%" % cur, x + cw - 6,
y + cell_px + 2, size=cell_px, rgb=color,
align="right", bold=True)
_wtext(cr, self, "C%d" % i, x + 6, y + 13, size=10,
rgb=_DIM, bold=True)
_wtext(cr, self, "%.0f%%" % cur, x + cw - 6, y + 13,
size=10, rgb=color, align="right", bold=True)
if ch > 26:
_series_line(cr, values, x + 3, y + cell_px + 7, cw - 6,
ch - cell_px - 10, 0.0, 100.0, color,
width=1.0, fill=True)
_series_line(cr, values, x + 3, y + 17, cw - 6,
ch - 20, 0.0, 100.0, color, width=1.0,
fill=True)
def _draw_net_graph(self, cr):
top = _panel(cr, self, self._title())
@@ -1010,42 +956,27 @@ class MonitorWidget(Widget):
peak = max(max(down) if down else 0.0,
max(up) if up else 0.0)
hi = max(1.0, peak * 1.15)
body_px = _fpx(0.032 * self.height, 11, 16)
# Legend on top: one line per direction, split into rate /
# total lines when the full line would clip at the right edge.
legend = []
for color, name, series, total in (
(_GREEN, "Down", down, self._total_down),
(_CYAN, "Up", up, self._total_up)):
full = "%s %s Total %s" % (
name, _fmt_rate(series[-1] if series else 0.0),
_fmt_bytes(total))
if _text_width(cr, self, full, size=body_px) \
<= self.width - 30:
legend.append((color, [full]))
else:
legend.append((color, [
"%s %s" % (name, _fmt_rate(
series[-1] if series else 0.0)),
"Total %s" % _fmt_bytes(total)]))
legend_h = 18 * sum(len(lines) for _c, lines in legend)
legend_y = top + 13
for color, lines in legend:
for line in lines:
_box(cr, 8, legend_y - 10, 10, 10, color, color)
_wtext(cr, self, line, 24, legend_y, size=body_px,
rgb=_TEXT, max_width=self.width - 30)
legend_y += 18
plot_x = _y_axis_width(cr, self, 0.0, hi, body_px, fmt=_fmt_rate)
plot_y = top + legend_h + 4
plot_w = max(1, self.width - plot_x - 8)
plot_h = max(1, self.height - plot_y - 6)
_plot_frame(cr, plot_x, plot_y, plot_w, plot_h, 0.0, hi,
label_size=body_px, fmt=_fmt_rate)
plot_x, plot_y = 34, top + 2
plot_w = max(1, self.width - 40)
plot_h = max(1, self.height - plot_y - 34)
_plot_frame(cr, plot_x, plot_y, plot_w, plot_h, 0.0, hi)
_series_line(cr, down, plot_x, plot_y, plot_w, plot_h, 0.0, hi,
_GREEN)
_series_line(cr, up, plot_x, plot_y, plot_w, plot_h, 0.0, hi,
_CYAN)
legend_y = plot_y + plot_h + 12
_box(cr, 8, legend_y - 8, 8, 8, _GREEN, _GREEN)
_wtext(cr, self, "Down %s Total %s"
% (_fmt_rate(down[-1] if down else 0.0),
_fmt_bytes(self._total_down)),
22, legend_y, size=10, rgb=_TEXT,
max_width=self.width - 28)
_box(cr, 8, legend_y + 6, 8, 8, _CYAN, _CYAN)
_wtext(cr, self, "Up %s Total %s"
% (_fmt_rate(up[-1] if up else 0.0),
_fmt_bytes(self._total_up)),
22, legend_y + 14, size=10, rgb=_TEXT,
max_width=self.width - 28)
def _draw_temp_history(self, cr):
top = _panel(cr, self, self._title())
@@ -1054,18 +985,13 @@ class MonitorWidget(Widget):
lo, hi = 0.0, max(100.0, threshold + 20.0)
cur = values[-1] if values else 0.0
cur_rgb = _RED if cur > threshold else _TEXT
body_px = _fpx(0.032 * self.height, 11, 16)
_wtext(cr, self, "%.1f C" % cur, self.width - 8, 17,
size=_fpx(0.032 * self.height, 11, 16), rgb=cur_rgb,
align="right", bold=True)
plot_x = _y_axis_width(cr, self, lo, hi, body_px,
fmt=lambda v: "%.0f C" % v)
plot_y = top + 2
plot_w = max(1, self.width - plot_x - 8)
_wtext(cr, self, "%.1f C" % cur, self.width - 8, 15, size=14,
rgb=cur_rgb, align="right", bold=True)
plot_x, plot_y = 34, top + 2
plot_w = max(1, self.width - 40)
plot_h = max(1, self.height - plot_y - 20)
_plot_frame(cr, plot_x, plot_y, plot_w, plot_h, lo, hi,
label_size=body_px, fmt=lambda v: "%.0f C" % v)
# Threshold line (dashed red) + label above the line.
_plot_frame(cr, plot_x, plot_y, plot_w, plot_h, lo, hi)
# Threshold line (dashed red) + label.
thr_y = plot_y + plot_h - (threshold - lo) / (hi - lo) * plot_h
cr.save()
_rgb(cr, _RED)
@@ -1075,9 +1001,8 @@ class MonitorWidget(Widget):
cr.line_to(plot_x + plot_w, thr_y)
cr.stroke()
cr.restore()
_wtext(cr, self, "%.0f C limit" % threshold,
plot_x + plot_w - 2, thr_y - 6, size=14, rgb=_RED,
align="right")
_wtext(cr, self, "%.0f C" % threshold, plot_x + plot_w - 2,
thr_y - 3, size=9, rgb=_RED, align="right")
_series_line(cr, values, plot_x, plot_y, plot_w, plot_h, lo, hi,
_CYAN)
# Red overlay where the line runs over the threshold.
@@ -1108,7 +1033,7 @@ class MonitorWidget(Widget):
_wtext(cr, self, "min %.1f max %.1f avg %.1f"
% (min(values), max(values),
sum(values) / len(values)),
8, plot_y + plot_h + 14, size=13, rgb=_DIM)
8, plot_y + plot_h + 13, size=10, rgb=_DIM)
def _gradient_bar(self, cr, x, y, w, h, frac, horizontal=True):
"""Trough + green->yellow->red gradient fill to *frac*."""
@@ -1142,66 +1067,19 @@ class MonitorWidget(Widget):
def _draw_usage_bar(self, cr):
frac = _range_frac(self)
self._gradient_bar(cr, 0, 0, self.width, self.height, frac)
label = self.get_prop("label", "") or self.kind
value = _prop_float(self, "value", 0.0)
# Dark panel first: the labels sit outside the bar, and
# without it they are white text on the window background.
_panel(cr, self)
# The 0.45x rule is capped at 40px: the literal rule gives a
# 209px label in the 464px-tall demo bar.
bar_h = self.height - 16
label_px = _fpx(0.45 * bar_h, 11, 40)
label_w = _text_width(cr, self, label, size=label_px, bold=True)
value_text = "%.0f%%" % value
value_w = _text_width(cr, self, value_text, size=label_px,
bold=True)
bar_x = 8 + label_w + 12
bar_w = max(1, self.width - bar_x - value_w - 20)
self._gradient_bar(cr, bar_x, 8, bar_w, bar_h, frac)
mid = self.height / 2 + label_px * 0.35
_wtext(cr, self, label, 8, mid, size=label_px, rgb=_WHITE,
bold=True, max_width=bar_x - 12)
_wtext(cr, self, value_text, self.width - 8, mid,
size=label_px, rgb=_WHITE, align="right", bold=True)
_wtext(cr, self, label, 8, self.height / 2 + 5, size=12,
rgb=_WHITE, bold=True, max_width=self.width / 2)
_wtext(cr, self, "%.0f%%" % value, self.width - 8,
self.height / 2 + 5, size=12, rgb=_WHITE, align="right",
bold=True)
def _draw_stack_bar(self, cr):
segments = self.get_segments()
total = sum(v for _label, v, _c in segments) or 1.0
legend_px = _fpx(0.032 * self.height, 11, 16)
head_px = _fpx(0.033 * self.height, 11, 16)
row_h = 1.6 * legend_px
# Legend rows (flow left to right, wrap when the width runs out).
rows = []
lx = 6
row = []
for label, value, color in segments:
text = "%s %.0f%%" % (label, 100.0 * value / total)
tw = _text_width(cr, self, text, size=legend_px) + 16
if lx + tw > self.width - 4 and row:
rows.append(row)
lx, row = 6, []
row.append((label, value, color, text, tw))
lx += tw
if row:
rows.append(row)
bar_h = _fpx(1.5 * legend_px, 8, 0.30 * self.height)
block_h = bar_h + 8 + row_h * len(rows)
# Title + total header (C style) when the widget is tall
# enough to hold it; at palette-default height (48px) the
# header would push the legend out of the widget, so the
# bar+legend block takes the space instead.
show_title = (self.height - 24) >= block_h
top = _panel(cr, self, self._title() if show_title else None)
if show_title:
# Total header (C style): the raw segment sum, with the
# unit prop appended when the host sets one (demo: GiB).
unit = self.get_prop("unit", "")
total_text = ("total %.1f %s" % (total, unit)) if unit \
else "total %.1f" % total
_wtext(cr, self, total_text, self.width - 8, 17,
size=head_px, rgb=_TEXT, align="right")
avail = self.height - top
bar_y = top + max(0, (avail - block_h) / 2)
bar_y, bar_h = 4, 16
x = 0.0
for label, value, color in segments:
seg_w = self.width * value / total
@@ -1209,16 +1087,18 @@ class MonitorWidget(Widget):
continue
_box(cr, x, bar_y, max(0, seg_w - 1), bar_h, color, color)
x += seg_w
ly = bar_y + bar_h + 8 + legend_px
for row in rows:
lx = 6
for label, value, color, text, tw in row:
_box(cr, lx, ly - legend_px * 0.7, legend_px * 0.7,
legend_px * 0.7, color, color)
_wtext(cr, self, text, lx + legend_px, ly,
size=legend_px, rgb=_TEXT)
lx += tw
ly += row_h
# Legend: color chip + "label 45%" flowing left to right,
# wrapping to a second row when the width runs out.
lx, ly = 6, bar_y + bar_h + 15
for label, value, color in segments:
text = "%s %.0f%%" % (label, 100.0 * value / total)
tw = _text_width(cr, self, text, size=10) + 16
if lx + tw > self.width - 4 and lx > 6:
lx = 6
ly += 14
_box(cr, lx, ly - 8, 8, 8, color, color)
_wtext(cr, self, text, lx + 12, ly, size=10, rgb=_TEXT)
lx += tw
def _draw_vertical_bar(self, cr):
frac = _range_frac(self)
@@ -1231,30 +1111,15 @@ class MonitorWidget(Widget):
self._peak = peak
lo = _prop_float(self, "minimum", 0.0)
hi = _prop_float(self, "maximum", 100.0)
top = _panel(cr, self, self._title())
body_px = _fpx(0.03 * self.height, 11, 16)
# Dynamic scale width from the widest Y label.
scale_w = 0.0
for f in (0.0, 0.25, 0.5, 0.75, 1.0):
label = "%.0f" % (lo + f * (hi - lo))
scale_w = max(scale_w, _text_width(cr, self, label,
size=body_px))
bar_x = int(scale_w) + 10
bar_w = self.width - bar_x - 8
bar_y, bar_h = top + 2, self.height - top - 10
_panel(cr, self)
bar_x, bar_w = 26, self.width - 34
bar_y, bar_h = 10, self.height - 34
self._gradient_bar(cr, bar_x, bar_y, bar_w, bar_h, frac,
horizontal=False)
# Scale labels + ticks on the left.
for f in (0.0, 0.25, 0.5, 0.75, 1.0):
gy = bar_y + bar_h - f * bar_h
if f == 1.0:
ybase = gy + body_px * 0.75
elif f == 0.0:
ybase = gy - 2
else:
ybase = gy + body_px * 0.35
_ylabel(cr, "%.0f" % (lo + f * (hi - lo)), bar_x - 4,
ybase, size=body_px)
_ylabel(cr, "%.0f" % (lo + f * (hi - lo)), bar_x - 4, gy + 3)
cr.save()
_rgb(cr, _GRID)
cr.set_line_width(1)
@@ -1262,8 +1127,7 @@ class MonitorWidget(Widget):
cr.line_to(bar_x, gy)
cr.stroke()
cr.restore()
# Peak-hold marker + label (bold, above the line, inset from
# the frame edge).
# Peak-hold marker.
if peak > lo:
py = bar_y + bar_h - (peak - lo) / (hi - lo) * bar_h \
if hi > lo else bar_y
@@ -1274,20 +1138,12 @@ class MonitorWidget(Widget):
cr.line_to(bar_x + bar_w + 2, py)
cr.stroke()
cr.restore()
_wtext(cr, self, "peak %.0f" % peak, bar_x + bar_w - 2,
py - 6, size=_peak_fit(cr, self, peak, bar_x, bar_w),
rgb=_RED, align="right", bold=True)
# Value INSIDE the bar at the bottom (PY style), white on the
# fill, dark when the fill is too short to hold it.
fill_h = bar_h * frac
value_px = _fpx(0.033 * self.height, 11, 16)
value_rgb = _WHITE if fill_h >= value_px + 8 else _TEXT
_wtext(cr, self, "%.0f%%" % value, bar_x + bar_w / 2,
bar_y + bar_h - 8, size=value_px, rgb=value_rgb,
align="center", bold=True)
_wtext(cr, self, "%.0f%%" % value, self.width / 2,
self.height - 8, size=11, rgb=_TEXT, align="center",
bold=True)
def _draw_tachometer(self, cr):
top = _panel(cr, self)
top = _panel(cr, self, self._title())
lo = _prop_float(self, "minimum", 0.0)
hi = _prop_float(self, "maximum", 8000.0)
if hi <= lo:
@@ -1316,9 +1172,7 @@ class MonitorWidget(Widget):
_RED, 10, cap=1)
_arc_stroke(cr, cx, cy, r, start, _angle(frac), _CYAN, 10,
cap=1)
# Ticks + numbers: numerals ~7.5% of the dial diameter, bold,
# just inside the major tick ring; redline numerals in red.
numeral_px = _fpx(0.075 * 2 * r, 13, 28)
# Ticks + numbers.
cr.save()
for i in range(11):
f = i / 10.0
@@ -1336,11 +1190,9 @@ class MonitorWidget(Widget):
if major:
label = "%.0f" % (lo + f * (hi - lo))
lx = cx + (r - 26) * math.cos(ang)
ly = cy + (r - 26) * math.sin(ang) \
+ numeral_px * 0.35
rgb = _RED if f >= red_frac else _TEXT
_wtext(cr, self, label, lx, ly, size=numeral_px,
rgb=rgb, align="center", bold=True)
ly = cy + (r - 26) * math.sin(ang) + 3
_wtext(cr, self, label, lx, ly, size=9, rgb=_TEXT,
align="center")
# Peak-hold tick.
cr.save()
_rgb(cr, _WHITE)
@@ -1366,21 +1218,13 @@ class MonitorWidget(Widget):
cr.arc(cx, cy, 6, 0, 2 * math.pi)
cr.fill()
cr.restore()
# Title bold and centred inside the dial, below the top
# numerals: its baseline hangs below the top numeral's bottom
# edge, so it cannot collide with the 3200/4800 numerals on
# small dials (a fixed cy - r*0.55 put it on top of them).
title_px = _fpx(numeral_px - 4, 13, 24)
title_base = cy - (r - 26) + numeral_px * 0.75 + title_px + 4
_wtext(cr, self, self._title(), cx, title_base,
size=title_px, rgb=_WHITE, align="center", bold=True)
readout_px = _fpx(0.05 * 2 * r, 13, 20)
_wtext(cr, self, "%.0f (peak %.0f)" % (value, peak),
cx, cy + r * 0.80, size=readout_px, rgb=_WHITE,
align="center", bold=True)
# Digital readout: below the hub, clear of the 0/max tick
# labels at the bottom of the dial.
unit = self.get_prop("unit", "")
_wtext(cr, self, "%.0f" % value, cx, cy + r * 0.80, size=20,
rgb=_WHITE, align="center", bold=True)
if unit:
_wtext(cr, self, unit, cx, cy + r * 0.80 + 16, size=12,
_wtext(cr, self, unit, cx, cy + r * 0.80 + 14, size=10,
rgb=_DIM, align="center")
def _draw_arc_gauge(self, cr):
@@ -1388,8 +1232,8 @@ class MonitorWidget(Widget):
frac = _range_frac(self)
value = _prop_float(self, "value", 0.0)
cx = self.width / 2
cy = self.height - 32
r = min(self.width / 2 - 12, self.height - top - 40)
cy = self.height - 14
r = min(self.width / 2 - 12, self.height - top - 22)
if r <= 0:
return
zones = ((0.0, 0.6, _GREEN), (0.6, 0.8, _YELLOW),
@@ -1401,72 +1245,48 @@ class MonitorWidget(Widget):
math.pi + f1 * math.pi, color, 12)
_arc_stroke(cr, cx, cy, r, math.pi, math.pi + frac * math.pi,
_WHITE, 12)
centre_px = _fpx(0.10 * 2 * r, 16, 48)
_wtext(cr, self, "%.0f%%" % value, cx, cy - r * 0.45,
size=centre_px, rgb=_WHITE, align="center", bold=True)
_wtext(cr, self, "%.0f%%" % value, cx, cy - r * 0.45, size=22,
rgb=_WHITE, align="center", bold=True)
label = self.get_prop("unit", "") or "usage"
_wtext(cr, self, label, cx, cy - r * 0.45 + centre_px * 0.75,
size=_fpx(0.04 * 2 * r, 11, 16), rgb=_DIM,
align="center")
# Endpoints under the arc ends.
end_px = _fpx(0.04 * 2 * r, 11, 18)
_wtext(cr, self, "0", cx - r, cy + end_px + 4, size=end_px,
rgb=_DIM, align="center")
_wtext(cr, self, "100", cx + r, cy + end_px + 4, size=end_px,
_wtext(cr, self, label, cx, cy - r * 0.45 + 16, size=10,
rgb=_DIM, align="center")
def _draw_donut_gauge(self, cr):
# No top-left title: the centre label carries the value name
# (the title would duplicate it).
top = _panel(cr, self)
top = _panel(cr, self, self._title())
frac = _range_frac(self)
value = _prop_float(self, "value", 0.0)
cx = self.width / 2
cy = top + (self.height - top) / 2
r0 = min(self.width, self.height - top) / 2 - 12
if r0 <= 0:
r = min(self.width, self.height - top) / 2 - 12
if r <= 0:
return
thick = _fpx(0.09 * 2 * r0, 8, 48)
# The ring stroke extends thick/2 past r: shrink r so the
# outer edge stays inside the frame.
r = r0 - thick / 2
_arc_stroke(cr, cx, cy, r, 0, 2 * math.pi,
(0.25, 0.25, 0.28), thick, cap=1)
(0.25, 0.25, 0.28), 14, cap=1)
_arc_stroke(cr, cx, cy, r, -math.pi / 2,
-math.pi / 2 + frac * 2 * math.pi, _GREEN, thick,
-math.pi / 2 + frac * 2 * math.pi, _GREEN, 14,
cap=1)
centre_px = _fpx(0.10 * 2 * r, 16, 44)
_wtext(cr, self, "%.0f%%" % value, cx, cy + centre_px * 0.35,
size=centre_px, rgb=_WHITE, align="center", bold=True)
label = self.get_prop("label", "") or self.kind
_wtext(cr, self, label, cx, cy + centre_px * 0.35 + 22,
size=_fpx(0.04 * 2 * r, 11, 18), rgb=_DIM,
_wtext(cr, self, "%.0f%%" % value, cx, cy + 7, size=20,
rgb=_WHITE, align="center", bold=True)
label = self.get_prop("unit", "") or self.kind
_wtext(cr, self, label, cx, cy + 24, size=10, rgb=_DIM,
align="center", max_width=self.width - 16)
def _draw_process_list(self, cr):
top = _panel(cr, self, self._title())
rows = self._sorted_rows()
_wtext(cr, self, "%d procs" % len(rows), self.width - 8, 17,
size=13, rgb=_DIM, align="right")
cols = ((6, 52, "PID", "left"), (62, 130, "Program", "left"),
(196, 44, "User", "left"), (248, 52, "Mem", "right"),
(308, 48, "CPU%", "right"))
sort_col = _prop_int(self, "sort-by", 0)
sort_key = {0: "CPU%", 1: "Mem", 2: "PID", 3: "Program"}.get(
sort_col, "CPU%")
sort_desc = _prop_bool(self, "sort-desc", True)
header_y = top + 15
(196, 44, "User", "left"), (244, 48, "Mem", "right"),
(296, 56, "CPU%", "right"))
header_y = top + 13
for x, _w, name, align in cols:
if name == sort_key:
name = name + (" \u25bc" if sort_desc else " \u25b2")
if align == "right":
_wtext(cr, self, name, x + _w, header_y, size=13,
_wtext(cr, self, name, x + _w, header_y, size=10,
rgb=_DIM, align="right", bold=True)
else:
_wtext(cr, self, name, x, header_y, size=13,
_wtext(cr, self, name, x, header_y, size=10,
rgb=_DIM, bold=True)
row_h = 23
y0 = top + 24
row_h = 18
y0 = top + 18
visible = max(0, (self.height - y0) // row_h)
for i, row in enumerate(rows[:visible]):
y = y0 + i * row_h
@@ -1479,52 +1299,42 @@ class MonitorWidget(Widget):
_rgb(cr, _AMBER, 0.12)
cr.rectangle(0, y, self.width, row_h)
cr.fill()
_wtext(cr, self, str(row["pid"]), 6, y + 16, size=13,
_wtext(cr, self, str(row["pid"]), 6, y + 13, size=10,
rgb=_TEXT)
_wtext(cr, self, row["name"], 62, y + 16, size=13,
_wtext(cr, self, row["name"], 62, y + 13, size=10,
rgb=_TEXT,
max_width=128)
_wtext(cr, self, row["user"], 196, y + 16, size=13,
_wtext(cr, self, row["user"], 196, y + 13, size=10,
rgb=_TEXT, max_width=44)
_wtext(cr, self, _fmt_bytes(row["mem_kb"] * 1024), 300,
y + 16, size=13, rgb=_TEXT, align="right")
# In-cell CPU% bar behind the number (colour-coded).
bar_x, bar_w = 308, 48
_box(cr, bar_x, y + 5, bar_w, 12, (0.20, 0.20, 0.23),
_wtext(cr, self, _fmt_bytes(row["mem_kb"] * 1024), 292,
y + 13, size=10, rgb=_TEXT, align="right")
# In-cell CPU% bar behind the number.
bar_x, bar_w = 300, 52
_box(cr, bar_x, y + 3, bar_w, 12, (0.20, 0.20, 0.23),
(0.20, 0.20, 0.23))
fill = max(0, bar_w * min(1.0, cpu / 100.0))
if fill > 0:
color = _GREEN if cpu < 50 else \
_AMBER if cpu < 80 else _RED
_box(cr, bar_x, y + 5, fill, 12, color, color)
_wtext(cr, self, "%.1f" % cpu, bar_x + bar_w - 3, y + 16,
size=13, rgb=_WHITE, align="right", bold=True)
_box(cr, bar_x, y + 3, fill, 12, color, color)
_wtext(cr, self, "%.1f" % cpu, bar_x + bar_w - 3, y + 13,
size=10, rgb=_WHITE, align="right", bold=True)
def _draw_load_badge(self, cr):
_panel(cr, self)
load1, load5, load15, uptime = self._load_values()
ncores = os.cpu_count() or 1
# Two-line layout, value block vertically centred. (No 1/5/15
# sub-labels: the audit calls the PY layout correct as-is;
# the sub-labels were directed at the Rust port.)
val_px = _fpx(0.055 * self.height, 13, 28)
title_px = _fpx(0.033 * self.height, 11, 16)
val_base = self.height / 2 - 6
_wtext(cr, self, "Load", 8, val_base, size=title_px, rgb=_DIM,
bold=True)
x = 8 + _text_width(cr, self, "Load", size=title_px,
bold=True) + 16
_wtext(cr, self, "Load", 8, 24, size=13, rgb=_DIM, bold=True)
x = 52
for load in (load1, load5, load15):
per_core = load / ncores
color = _GREEN if per_core < 0.7 else \
_AMBER if per_core < 1.0 else _RED
text = "%.2f" % load
_wtext(cr, self, text, x, val_base, size=val_px,
rgb=color, bold=True)
x += _text_width(cr, self, text, size=val_px,
bold=True) + 12
_wtext(cr, self, text, x, 24, size=13, rgb=color, bold=True)
x += _text_width(cr, self, text, size=13, bold=True) + 12
_wtext(cr, self, "%s %d cores" % (_fmt_uptime(uptime), ncores),
8, val_base + 28, size=14, rgb=_TEXT)
8, 46, size=11, rgb=_TEXT)
def _draw_monitor_button(self, cr):
status = self._status
@@ -1541,40 +1351,31 @@ class MonitorWidget(Widget):
cr.restore()
_rounded_box(cr, 0, 0, self.width, self.height, _PANEL_INNER,
color, line_width=1.5, radius=6)
dot_d = _fpx(0.10 * self.height, 12, 30)
dot_r = dot_d / 2
dot_cx = 10 + dot_r
mid_y = self.height / 2
_rgb(cr, color)
cr.arc(dot_cx, mid_y, dot_r, 0, 2 * math.pi)
cr.arc(18, self.height / 2, 7, 0, 2 * math.pi)
cr.fill()
if status == "up":
_rgb(cr, _WHITE)
cr.arc(dot_cx, mid_y, dot_r * 0.35, 0, 2 * math.pi)
cr.arc(18, self.height / 2, 2.5, 0, 2 * math.pi)
cr.fill()
label = self.get_prop("label", "") or self.get_prop("target", "") \
or self.kind
status_text = _STATUS_LABELS[status]
label_px = _fpx(0.10 * self.height, 13, 24)
status_px = _fpx(0.09 * self.height, 12, 20)
detail_px = _fpx(0.06 * self.height, 11, 14)
sw = _text_width(cr, self, status_text, size=status_px,
bold=True)
label_x = dot_cx + dot_r + 10
max_w = self.width - label_x - sw - 16
sw = _text_width(cr, self, status_text, size=12, bold=True)
mid_y = self.height / 2
if self._detail:
_wtext(cr, self, label, label_x, mid_y - 2, size=label_px,
rgb=_WHITE, bold=True, max_width=max_w)
_wtext(cr, self, self._detail, label_x,
mid_y + detail_px + 2, size=detail_px, rgb=_DIM,
max_width=max_w)
_wtext(cr, self, label, 32, mid_y - 1, size=13, rgb=_WHITE,
bold=True,
max_width=self.width - 40 - sw - 8)
_wtext(cr, self, self._detail, 32, mid_y + 14, size=10,
rgb=_DIM,
max_width=self.width - 40 - sw - 8)
else:
_wtext(cr, self, label, label_x, mid_y + label_px * 0.35,
size=label_px, rgb=_WHITE, bold=True,
max_width=max_w)
_wtext(cr, self, status_text, self.width - 8,
mid_y + status_px * 0.35, size=status_px, rgb=color,
align="right", bold=True)
_wtext(cr, self, label, 32, mid_y + 5, size=13, rgb=_WHITE,
bold=True,
max_width=self.width - 40 - sw - 8)
_wtext(cr, self, status_text, self.width - 8, mid_y + 5,
size=12, rgb=color, align="right", bold=True)
def _draw_monitor_grid(self, cr):
top = _panel(cr, self, self._title())
@@ -1583,13 +1384,6 @@ class MonitorWidget(Widget):
self.width / 2, self.height / 2 + 5, size=11,
rgb=_DIM, align="center")
return
# Summary, bold, top-right (e.g. "3/4 up").
n_up = sum(1 for m in self._monitors
if m["status"] == "up")
summary = "%d/%d up" % (n_up, len(self._monitors))
_wtext(cr, self, summary, self.width - 8, 17,
size=_fpx(0.033 * self.height, 11, 16), rgb=_TITLE,
align="right", bold=True)
for i, (x, y, w, h) in enumerate(self._cell_layout()):
if i >= len(self._monitors):
break
@@ -1597,36 +1391,16 @@ class MonitorWidget(Widget):
color = _STATUS_COLORS[monitor["status"]]
_rounded_box(cr, x, y, w, h, _PANEL_INNER, color,
line_width=1.0, radius=4)
dot_d = _fpx(0.11 * h, 10, 24)
dot_r = dot_d / 2
dot_cx = x + 10 + dot_r
mid_y = y + h / 2
_rgb(cr, color)
cr.arc(dot_cx, mid_y, dot_r, 0, 2 * math.pi)
cr.arc(x + 12, y + h / 2, 5, 0, 2 * math.pi)
cr.fill()
label_px = _fpx(0.10 * h, 13, 20)
status_px = _fpx(0.09 * h, 12, 18)
detail_px = _fpx(0.06 * h, 11, 14)
label_x = dot_cx + dot_r + 10
status_text = _STATUS_LABELS[monitor["status"]]
sw = _text_width(cr, self, status_text, size=status_px,
bold=True)
_wtext(cr, self, monitor["label"], label_x, mid_y - 2,
size=label_px, rgb=_WHITE, bold=True,
max_width=w - (label_x - x) - sw - 12)
_wtext(cr, self, status_text, x + w - 8,
mid_y + status_px * 0.35, size=status_px, rgb=color,
align="right", bold=True)
# Detail on its own line, wrapped to two lines rather
# than truncated ("DOWN - clos..." bug).
detail = monitor["detail"]
lines = _wrap_lines(cr, self, detail,
w - (label_x - x) - 8, size=detail_px)
dy = mid_y + detail_px + 4
for line in lines[:2]:
_wtext(cr, self, line, label_x, dy, size=detail_px,
rgb=_DIM)
dy += detail_px + 4
label = monitor["label"]
_wtext(cr, self, label, x + 24, y + h / 2 - 1, size=11,
rgb=_WHITE, bold=True, max_width=w - 30)
status_text = "%s - %s" % (
_STATUS_LABELS[monitor["status"]], monitor["detail"])
_wtext(cr, self, status_text, x + 24, y + h / 2 + 13,
size=9, rgb=_DIM, max_width=w - 30)
def _draw_sys_box(self, cr):
top = _panel(cr, self, self._title())
@@ -1636,29 +1410,24 @@ class MonitorWidget(Widget):
hi = _prop_float(self, "maximum", 100.0)
if hi <= lo:
hi = lo + 100.0
hero_px = _fpx(0.10 * self.height, 20, 32)
_wtext(cr, self, "%.0f" % value, 8, top + hero_px,
size=hero_px, rgb=_WHITE, bold=True)
_wtext(cr, self, "%.0f" % value, 8, top + 26, size=26,
rgb=_WHITE, bold=True)
_wtext(cr, self, unit, 8 + _text_width(cr, self, "%.0f" % value,
size=hero_px,
bold=True) + 6,
top + hero_px, size=14, rgb=_DIM)
_wtext(cr, self, "max %.0f%s" % (hi, unit), self.width - 8,
top + hero_px, size=13, rgb=_DIM, align="right")
size=26, bold=True) + 6,
top + 26, size=12, rgb=_DIM)
values = self._single_series(55.0, 28.0, lo, hi)
graph_y = top + hero_px + 10
bar_h = _fpx(0.055 * self.height, 20, 28)
graph_h = max(1, self.height - graph_y - bar_h - 16)
graph_y = top + 34
graph_h = max(1, self.height - graph_y - 26)
_plot_frame(cr, 8, graph_y, self.width - 16, graph_h, lo, hi,
labels=False)
_series_line(cr, values, 8, graph_y, self.width - 16, graph_h,
lo, hi, _GREEN)
frac = max(0.0, min(1.0, (value - lo) / (hi - lo)))
bar_y = self.height - 8 - bar_h
self._gradient_bar(cr, 8, bar_y, self.width - 16, bar_h, frac)
self._gradient_bar(cr, 8, self.height - 20, self.width - 16,
12, frac)
_wtext(cr, self, "%.0f%%" % (frac * 100.0), self.width - 12,
bar_y + bar_h / 2 + 5, size=14, rgb=_WHITE,
align="right", bold=True)
self.height - 10, size=9, rgb=_WHITE, align="right",
bold=True)
_MONITOR_DRAW = {