diff --git a/examples/xmonitorbutton.py b/examples/xmonitorbutton.py index 936be40..838556d 100644 --- a/examples/xmonitorbutton.py +++ b/examples/xmonitorbutton.py @@ -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", "SSH :22") + widget.set_prop("label", "sshd :22") widget.set_prop("check-type", "Port") widget.set_prop("target", "22") # Live data: poll the check now; the timer re-polls. diff --git a/examples/xmonitorgrid.py b/examples/xmonitorgrid.py index fb332f6..c2ddc2f 100644 --- a/examples/xmonitorgrid.py +++ b/examples/xmonitorgrid.py @@ -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", "SSH :22") + widget.add_monitor("port", "22", "sshd :22") widget.add_monitor("port", "9999", "Port 9999") widget.poll_all() widgets.append(widget) diff --git a/examples/xstackbar.py b/examples/xstackbar.py index 66563f8..e4fe65d 100644 --- a/examples/xstackbar.py +++ b/examples/xstackbar.py @@ -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, 48), + 'XStackBar_001': (True, True, False, False, 16, 16, 320, 120), } @@ -60,14 +60,15 @@ 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, 48) + widget = create('XStackBar', 'XStackBar_001', 16, 16, 320, 120) widget.set_prop("label", "Memory") - widget.set_prop("segments", "used=45|cached=25|buffers=10|free=20") + widget.set_prop("segments", "used=11.7|cached=15.5|buffers=1.2|free=1.9") + widget.set_prop("unit", "GiB") widgets.append(widget) return widgets -_DESIGN_SIZE = (352, 80) +_DESIGN_SIZE = (352, 152) _BACKGROUND = '' _WIDGETS = [] _LAST_SIZE = [None] @@ -144,7 +145,7 @@ def _on_area_resize(area, allocation): def main(): window = Gtk.Window(title='XStackBar example') - window.set_default_size(352, 80) + window.set_default_size(352, 152) window.connect("destroy", Gtk.main_quit) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) diff --git a/examples/xtachometer.py b/examples/xtachometer.py index 475f738..e496015 100644 --- a/examples/xtachometer.py +++ b/examples/xtachometer.py @@ -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", "Engine") + widget.set_prop("label", "RPM") widget.set_prop("value", "3200") widget.set_prop("maximum", "8000") widget.set_prop("redline", "6500") diff --git a/examples/xverticalbar.py b/examples/xverticalbar.py index cd414f9..36bdb9d 100644 --- a/examples/xverticalbar.py +++ b/examples/xverticalbar.py @@ -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, 60, 200), + 'XVerticalBar_001': (True, True, False, False, 16, 16, 160, 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, 60, 200) + widget = create('XVerticalBar', 'XVerticalBar_001', 16, 16, 160, 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 = (92, 232) +_DESIGN_SIZE = (192, 232) _BACKGROUND = '' _WIDGETS = [] _LAST_SIZE = [None] @@ -166,7 +166,7 @@ def _tick(): def main(): window = Gtk.Window(title='XVerticalBar example') - window.set_default_size(92, 232) + window.set_default_size(192, 232) window.connect("destroy", Gtk.main_quit) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) diff --git a/lightgui/props_monitor.py b/lightgui/props_monitor.py index 6b679bc..bc166a1 100644 --- a/lightgui/props_monitor.py +++ b/lightgui/props_monitor.py @@ -83,6 +83,8 @@ MONITOR_TABLES = { _label(), PropDef("segments", "Str", "", 0, 0, (), (), "Segments", False), + # Unit for the "total " header (e.g. GiB). + _unit(), ), "XVerticalBar": ( _label(), diff --git a/lightgui/xframe/instruments.py b/lightgui/xframe/instruments.py index 9748f63..dc87dae 100644 --- a/lightgui/xframe/instruments.py +++ b/lightgui/xframe/instruments.py @@ -20,6 +20,7 @@ import math from lightgui.xframe.core import ( Widget, + _apply_font, parse_color, _bg, _box, @@ -84,7 +85,17 @@ _LEVEL_DEFAULT = { def _color(widget, name, default): - return parse_color(widget.get_prop(name, ""), default) + """Colour prop with the per-kind PropDef default first (e.g. the + LedBlue lens is blue, not the shared red fallback): a freshly + created widget carries no set props, so get_prop alone would + always return the hardcoded default.""" + raw = widget.get_prop(name, "") + if raw: + return parse_color(raw, default) + prop = widget.prop_def(name) + if prop is not None and prop.default: + return parse_color(prop.default, default) + return default def _value(widget): @@ -131,6 +142,59 @@ def _brightness(widget): return max(0, min(100, _prop_int(widget, "brightness", 100))) +# --- proportions fix (Dec 2026 audit, G1-G7) --------------------------------- +# Text scales from the widget's drawn size, mirroring the C +# inst_cap_font helpers (cap-height convention: a Cairo Sans bold +# cap is ~0.72 of the em size). Audit sizes are cap heights at the +# C demo scale (600 px tall window): dial numerals 7-8% of dial +# diameter, scale labels 16 px, titles 16-20 px, state labels +# 14-16 px, values 18 px. Fractions below are those sizes / 600. + +def _cap_size(cap): + """Cairo font size (em) for a target cap height in px.""" + return max(4.0, cap / 0.72) + + +def _fs(frac, dim): + """Font size for text whose cap height is frac of dim.""" + return _cap_size(frac * dim) + + +def _fit_size(cr, widget, text, target_w, size, bold=True): + """Shrink *size* so *text* fits *target_w* (nameplate rule: + engraving fills 40-50% of the plate width).""" + cr.save() + _apply_font(cr, widget, size=size, bold=bold) + w = cr.text_extents(text)[2] + cr.restore() + if w > 0: + size = size * target_w / w + return max(4.0, size) + + +# C constructor default labels (text_) that are real words, not the +# class name (audit G2 blanks only the class-name defaults). A +# designer-set text wins; otherwise the word below is drawn. +_INST_LABEL = { + "AnalogGauge": "Analog", "BarMeter": "Level", "Beacon": "BEACON", + "DigitalReadout": "Readout", "FlowMeter": "Flow", + "LedBlue": "BLUE", "LedGreen": "GREEN", "LedRed": "RED", + "Manometer": "Manometer", "PanelLampAmber": "AMBER", + "PanelLampBlue": "BLUE", "PanelLampGreen": "GREEN", + "PanelLampRed": "RED", "PanelLampWhite": "WHITE", + "PressureGauge": "Pressure", "RgbStatusLed": "RGB", + "StackLight": "STACK", "TemperatureGauge": "Temperature", + "VuMeter": "VU", +} + + +def _label(widget): + """Display label: designer text, else the C default word.""" + if widget.text != widget.name: + return widget.text + return _INST_LABEL.get(widget.pkind, "") + + def _screw(cr, x, y, r=4): """One panel screw: grey disc + dark slot.""" cr.save() @@ -188,7 +252,13 @@ def _draw_dial(cr, widget, red_from=None, unit="", fmt="%.0f"): cr.arc(cx, cy, r - 6, _dial_angle(red_from), _dial_angle(1.0)) cr.stroke() - # Ticks + numbers. + # Ticks + numbers (audit G1: numerals 7-8% of dial diameter, + # bold, just inside the tick ring). + num_cap = 0.075 * 2 * r + num_size = _cap_size(num_cap) + # Numeral centre radius mirrors C (R - numCap - 12): the glyph + # tops clear the tick ring instead of touching the rim. + num_r = r - num_cap - 12 for i in range(11): f = i / 10.0 angle = _dial_angle(f) @@ -205,10 +275,11 @@ def _draw_dial(cr, widget, red_from=None, unit="", fmt="%.0f"): if major: value = lo + f * (hi - lo) label = fmt % value - tx = cx + (r - 24) * math.cos(angle) - ty = cy + (r - 24) * math.sin(angle) - _wtext(cr, widget, label, tx, ty + 4, size=11, - rgb=ink, align="center", max_width=44) + tx = cx + num_r * math.cos(angle) + ty = cy + num_r * math.sin(angle) + _wtext(cr, widget, label, tx, ty + num_cap * 0.35, + size=num_size, bold=True, + rgb=ink, align="center", max_width=2 * num_r) # Needle. angle = _dial_angle(frac) width = _prop_int(widget, "needle-line-width", 3) @@ -225,11 +296,14 @@ def _draw_dial(cr, widget, red_from=None, unit="", fmt="%.0f"): cr.fill() cr.restore() label = (fmt % _value(widget)) + (" " + unit if unit else "") - _wtext(cr, widget, label, cx, cy + r * 0.55 + 6, size=12, + _wtext(cr, widget, label, cx, cy + r * 0.55 + 6, + size=_fs(0.030, h), rgb=ink, align="center", bold=True, max_width=w - 16) if widget.text != widget.name: - _wtext(cr, widget, widget.text, cx, cy - r * 0.55, size=11, - rgb=ink, align="center", max_width=w - 16) + # Title inside the dial, below the top numerals (audit G3). + _wtext(cr, widget, widget.text, cx, cy - r * 0.55, + size=_fs(0.028, h), + rgb=ink, align="center", bold=True, max_width=w - 16) cr.restore() @@ -295,16 +369,25 @@ def _draw_bar_meter(cr, widget): cr.stroke() cr.restore() lo, hi = _range(widget) + scale_cap = 0.027 * h + scale_size = _cap_size(scale_cap) for i in range(6): f = i / 5.0 label = "%.0f" % (lo + f * (hi - lo)) if horizontal: _wtext(cr, widget, label, x0 + f * bw, y0 + bh + 14, - size=10, rgb=ink, align="center", max_width=36) + size=scale_size, bold=True, rgb=ink, align="center", + max_width=36) else: - _wtext(cr, widget, label, x0 - 4, y0 + bh - f * bh + 4, - size=10, rgb=ink, align="right", max_width=26) - _wtext(cr, widget, "%.1f" % _value(widget), w / 2, h - 4, size=12, + # Top label inset clear of the border (audit G7). + ly = y0 + bh - f * bh + scale_cap * 0.35 + if i == 5: + ly = y0 + scale_cap + 2 + _wtext(cr, widget, label, x0 - 4, ly, + size=scale_size, bold=True, rgb=ink, align="right", + max_width=40) + _wtext(cr, widget, "%.1f" % _value(widget), w / 2, h - 4, + size=_fs(0.030, h), rgb=ink, align="center", bold=True, max_width=w - 8) @@ -345,14 +428,15 @@ def _draw_flow_meter(cr, widget): cr.stroke() cr.restore() lo, hi = _range(widget) + scale_size = _fs(0.027, h) for i in range(6): f = i / 5.0 y = bot_y - f * (bot_y - top_y) _wtext(cr, widget, "%.0f" % (lo + f * (hi - lo)), - cx - bot_w / 2 - 4, y + 4, size=10, rgb=ink, - align="right", max_width=30) + cx - bot_w / 2 - 4, y + 4, size=scale_size, bold=True, + rgb=ink, align="right", max_width=44) _wtext(cr, widget, "%.0f L/min" % _value(widget), cx, h - 8, - size=12, rgb=ink, align="center", bold=True, + size=_fs(0.030, h), rgb=ink, align="center", bold=True, max_width=w - 8) @@ -402,9 +486,10 @@ def _draw_manometer(cr, widget): f = i / 4.0 y = top + f * (bot - top) _wtext(cr, widget, "%+.0f" % (lo + f * (hi - lo)), - left_x - tube_w / 2 - 4, y + 4, size=10, rgb=ink, - align="right", max_width=34) - _wtext(cr, widget, "%.1f mm" % value, w / 2, h - 8, size=12, + left_x - tube_w / 2 - 4, y + 4, size=_fs(0.027, h), + bold=True, rgb=ink, align="right", max_width=48) + _wtext(cr, widget, "%.1f mm" % value, w / 2, h - 8, + size=_fs(0.030, h), rgb=ink, align="center", bold=True, max_width=w - 8) @@ -449,7 +534,22 @@ def _draw_needle_tapered(cr, widget): cr.arc(cx, cy, 4, 0, 2 * math.pi) cr.fill() cr.restore() - _wtext(cr, widget, "%.1f" % _value(widget), cx, h - 8, size=12, + # Audit G1: numerals 7-8% of dial diameter, bold, just inside + # the tick ring (mirrors the C dial numerals). + lo, hi = _range(widget) + num_cap = 0.075 * 2 * r + num_r = r - num_cap - 12 + for i in range(0, 11, 5): + f = i / 10.0 + a = _dial_angle(f) + tx = cx + num_r * math.cos(a) + ty = cy + num_r * math.sin(a) + _wtext(cr, widget, "%.0f" % (lo + f * (hi - lo)), tx, + ty + num_cap * 0.35, size=_cap_size(num_cap), + bold=True, rgb=ink, align="center", + max_width=2 * num_r) + _wtext(cr, widget, "%.1f" % _value(widget), cx, h - 8, + size=_fs(0.030, h), rgb=ink, align="center", bold=True, max_width=w - 8) @@ -493,12 +593,16 @@ def _draw_needle_knife(cr, widget): cr.fill() cr.restore() lo, hi = _range(widget) + num_cap = 0.030 * bw + num_size = _cap_size(num_cap) for i in range(6): f = i / 5.0 x = x0 + 8 + f * (bw - 16) _wtext(cr, widget, "%.0f" % (lo + f * (hi - lo)), x, - y0 + 14, size=10, rgb=ink, align="center", max_width=36) - _wtext(cr, widget, "%.1f" % _value(widget), w / 2, h - 8, size=12, + y0 + 14 + num_cap * 0.35, size=num_size, bold=True, + rgb=ink, align="center", max_width=48) + _wtext(cr, widget, "%.1f" % _value(widget), w / 2, h - 8, + size=_fs(0.030, h), rgb=ink, align="center", bold=True, max_width=w - 8) @@ -516,7 +620,8 @@ def _draw_needle_edgewise(cr, widget): return _box(cr, x0, y0, bw, bh, face, ink) frac = _frac(widget) - pivot_x, pivot_y = x0 + bw / 2, y0 + bh + 6 + # Audit: pivot attached to the scale (was 6 px below the box). + pivot_x, pivot_y = x0 + bw / 2, y0 + bh # Edgewise: the needle sweeps a shallow arc; the scale is a # horizontal band with a red zone at the right end. cr.save() @@ -528,6 +633,8 @@ def _draw_needle_edgewise(cr, widget): _rgb(cr, tick) cr.set_line_width(1) lo, hi = _range(widget) + num_cap = 0.030 * bw + num_size = _cap_size(num_cap) for i in range(11): f = i / 10.0 x = x0 + 6 + f * (bw - 12) @@ -535,8 +642,8 @@ def _draw_needle_edgewise(cr, widget): cr.line_to(x, y0 + 14 if i % 5 == 0 else y0 + 10) if i % 5 == 0: _wtext(cr, widget, "%.0f" % (lo + f * (hi - lo)), x, - y0 + 28, size=10, rgb=ink, align="center", - max_width=36) + y0 + 28 + num_cap * 0.35, size=num_size, bold=True, + rgb=ink, align="center", max_width=56) cr.stroke() _rgb(cr, needle) cr.set_line_width(2) @@ -548,7 +655,8 @@ def _draw_needle_edgewise(cr, widget): cr.arc(pivot_x, pivot_y, 4, 0, 2 * math.pi) cr.fill() cr.restore() - _wtext(cr, widget, "%.1f" % _value(widget), w / 2, h - 8, size=12, + _wtext(cr, widget, "%.1f" % _value(widget), w / 2, h - 8, + size=_fs(0.030, h), rgb=ink, align="center", bold=True, max_width=w - 8) @@ -574,6 +682,9 @@ def _draw_needle_vu(cr, widget): _rgb(cr, ink) cr.set_line_width(1) lo, hi = _range(widget) + # Audit G1: numerals 4% of width, bold, red in the red zone. + num_cap = 0.040 * w + num_size = _cap_size(num_cap) for i in range(11): f = i / 10.0 angle = math.pi * (1.25 + 0.5 * f) @@ -587,9 +698,11 @@ def _draw_needle_vu(cr, widget): if i % 5 == 0: tx = pivot_x + (r0 + 16) * math.cos(angle) ty = pivot_y + (r0 + 16) * math.sin(angle) - _wtext(cr, widget, "%+.0f" % (lo + f * (hi - lo)), tx, - ty + 4, size=10, rgb=ink, align="center", - max_width=36) + lab = "%+.0f" % (lo + f * (hi - lo)) + _wtext(cr, widget, lab, tx, ty + num_cap * 0.35, + size=num_size, bold=True, + rgb=red if (lo + f * (hi - lo)) >= 0 else ink, + align="center", max_width=64) cr.stroke() angle = math.pi * (1.25 + 0.5 * frac) _rgb(cr, needle) @@ -602,8 +715,14 @@ def _draw_needle_vu(cr, widget): cr.arc(pivot_x, pivot_y, 4, 0, 2 * math.pi) cr.fill() cr.restore() - _wtext(cr, widget, "VU %.1f" % _value(widget), w / 2, h - 8, - size=12, rgb=ink, align="center", bold=True, + # "VU" below the arc centre, clear of the numerals (audit G2: + # no class-name caption on the scale). + _wtext(cr, widget, "VU", w / 2, y0 + bh * 0.68, + size=_fs(0.033, h), rgb=ink, align="center", bold=True, + max_width=w - 8) + _wtext(cr, widget, "%.1f" % _value(widget), w / 2, h - 8, + size=_fs(0.030, h), + rgb=ink, align="center", bold=True, max_width=w - 8) @@ -626,12 +745,21 @@ def _tank_colours(widget): } -def _alarm_lines(cr, widget, x, top, bottom, vertical=False): - """Alarm markers: hi-hi/hi/lo/lo-lo (red/amber/amber/red).""" +def _alarm_lines(cr, widget, x, top, bottom, vertical=False, + labels=True): + """Alarm markers: hi-hi/hi/lo/lo-lo (red/amber/amber/red). + With labels, the word labels sit right of each line (audit: + alarm labels 14 px bold) -- callers must leave room on the + right; pass labels=False where a legend already names them.""" cols = _tank_colours(widget) hi_hi, hi, lo, lo_lo = _alarms(widget) - for level, colour in ((hi_hi, cols["red"]), (hi, cols["amber"]), - (lo, cols["amber"]), (lo_lo, cols["red"])): + h = widget.height + lab_cap = 0.023 * h + lab_size = _cap_size(lab_cap) + for level, colour, lab in ((hi_hi, cols["red"], "HI-HI"), + (hi, cols["amber"], "HI"), + (lo, cols["amber"], "LO"), + (lo_lo, cols["red"], "LO-LO")): y = bottom - level / 100.0 * (bottom - top) cr.save() _rgb(cr, colour) @@ -644,10 +772,15 @@ def _alarm_lines(cr, widget, x, top, bottom, vertical=False): cr.line_to(x + 14, y) cr.stroke() cr.restore() + if labels and not vertical: + _wtext(cr, widget, lab, x + 20, y + lab_cap * 0.35, + size=lab_size, bold=True, rgb=cols["ink"], + max_width=64) def _tank_readout(cr, widget, level, x, y, align="left"): - _wtext(cr, widget, "%.1f%%" % level, x, y, size=13, bold=True, + _wtext(cr, widget, "%.1f%%" % level, x, y, size=_fs(0.030, widget.height), + bold=True, rgb=(0.12, 0.12, 0.12), align=align, max_width=widget.width - 16) @@ -658,7 +791,9 @@ def _draw_vertical_tank(cr, widget): level = _level(widget) w, h = widget.width, widget.height x0, y0 = 24, 16 - bw, bh = w - 62, h - 36 + # Narrowed to leave room for the alarm word labels right of + # the alarm lines (audit: alarms 14 px bold). + bw, bh = w - 116, h - 36 if bw <= 0 or bh <= 0: return _box(cr, x0, y0, bw, bh, cols["pale"], cols["ink"]) @@ -707,6 +842,17 @@ def _draw_horizontal_tank(cr, widget): cr.line_to(x, y0 + bh) cr.stroke() cr.restore() + # Alarm word labels above the tank, clear of the capsule ends + # (audit: alarms 14 px bold; % clear of the curve, G7). + lab_cap = 0.023 * h + lab_size = _cap_size(lab_cap) + for mark, colour, lab in ((hi_hi, cols["red"], "HI-HI"), + (hi, cols["amber"], "HI"), + (lo, cols["amber"], "LO"), + (lo_lo, cols["red"], "LO-LO")): + x = x0 + bw * mark / 100.0 + _wtext(cr, widget, lab, x, y0 - 4, size=lab_size, bold=True, + rgb=cols["ink"], align="center", max_width=44) _tank_readout(cr, widget, level, x0 + bw / 2, h - 6, align="center") @@ -757,7 +903,8 @@ def _draw_sight_glass(cr, widget): level = _level(widget) w, h = widget.width, widget.height cx = w / 2 - tube_w = 26 + # Audit: widen the tube so the fill is visible. + tube_w = max(26, int(0.06 * w)) x0 = cx - tube_w / 2 top, bot = 20, h - 24 if bot - top < 10: @@ -772,6 +919,8 @@ def _draw_sight_glass(cr, widget): cr.rectangle(x0 + 2, bot - fill_h, tube_w - 4, fill_h) cr.fill() cr.restore() + scale_cap = 0.027 * h + scale_size = _cap_size(scale_cap) for i in range(11): y = bot - (bot - top) * i / 10.0 cr.save() @@ -781,10 +930,11 @@ def _draw_sight_glass(cr, widget): cr.line_to(x0, y) cr.stroke() cr.restore() - if i % 5 == 0 and i: - _wtext(cr, widget, "%d" % (i * 10), x0 - 14, y + 4, - size=10, rgb=cols["ink"], align="right", - max_width=26) + if i % 5 == 0: + _wtext(cr, widget, "%d" % (i * 10), x0 - 14, + y + scale_cap * 0.35, + size=scale_size, bold=True, rgb=cols["ink"], + align="right", max_width=40) _alarm_lines(cr, widget, x0 + tube_w + 2, top, bot) _tank_readout(cr, widget, level, cx, h - 6, align="center") @@ -814,10 +964,13 @@ def _draw_level_column(cr, widget): cr.rectangle(x0 - 6, float_y - 3, col_w + 12, 6) cr.fill() cr.restore() + scale_cap = 0.027 * h + scale_size = _cap_size(scale_cap) for i in range(11): y = bot - (bot - top) * i / 10.0 - _wtext(cr, widget, "%d" % (i * 10), x0 - 8, y + 4, size=10, - rgb=cols["ink"], align="right", max_width=26) + _wtext(cr, widget, "%d" % (i * 10), x0 - 8, + y + scale_cap * 0.35, size=scale_size, bold=True, + rgb=cols["ink"], align="right", max_width=40) _alarm_lines(cr, widget, x0 + col_w + 2, top, bot) _tank_readout(cr, widget, level, cx + 44, top + 12, align="center") @@ -840,16 +993,30 @@ def _draw_level_transmitter(cr, widget): cr.fill() cr.restore() _alarm_lines(cr, widget, x0 + bw + 2, y0, y0 + bh) - _wtext(cr, widget, "%.1f%%" % level, x0 + bw + 22, y0 + 14, - size=13, bold=True, rgb=(0.12, 0.12, 0.12), - max_width=w - x0 - bw - 26) - _wtext(cr, widget, "%.2f mA" % ma, x0 + bw + 22, y0 + 32, size=12, - rgb=cols["ink"], max_width=w - x0 - bw - 26) - # Loop terminals. - _box(cr, x0 + bw + 22, y0 + 48, 14, 10, cols["white"], cols["ink"]) - _box(cr, x0 + bw + 42, y0 + 48, 14, 10, cols["white"], cols["ink"]) - _wtext(cr, widget, "+ -", x0 + bw + 22, y0 + 72, size=11, - rgb=cols["ink"], max_width=40) + # Data block right of the alarm labels (audit: 16 px data). + data_cap = 0.027 * h + data_size = _cap_size(data_cap) + dx = x0 + bw + 66 + _wtext(cr, widget, "%.1f%%" % level, dx, y0 + 14, + size=data_size, bold=True, rgb=(0.12, 0.12, 0.12), + max_width=w - dx - 4) + _wtext(cr, widget, "%.2f mA" % ma, dx, y0 + 32, + size=_fs(0.020, h), + rgb=cols["ink"], max_width=w - dx - 4) + # Loop terminals: (+)(-) buttons, 24 px at demo scale, with + # legible signs (audit). + btn = max(14.0, 0.040 * h) + _box(cr, dx, y0 + 48, btn, btn, cols["white"], cols["ink"]) + _box(cr, dx + btn + 6, y0 + 48, btn, btn, cols["white"], + cols["ink"]) + btn_cap = 0.023 * h + _wtext(cr, widget, "+", dx + btn / 2, y0 + 48 + btn / 2 + + btn_cap * 0.35, size=_cap_size(btn_cap), bold=True, + rgb=cols["ink"], align="center", max_width=btn) + _wtext(cr, widget, "-", dx + btn * 1.5 + 6, + y0 + 48 + btn / 2 + btn_cap * 0.35, + size=_cap_size(btn_cap), bold=True, rgb=cols["ink"], + align="center", max_width=btn) def _draw_open_channel(cr, widget): @@ -859,8 +1026,10 @@ def _draw_open_channel(cr, widget): (20 / 255, 80 / 255, 160 / 255)) level = _level(widget) w, h = widget.width, widget.height - x0, y0 = 16, 16 - bw, bh = w - 48, h - 40 + # Left margin widened so the alarm word labels fit left of the + # channel (audit: alarms 14 px bold). + x0, y0 = 64, 16 + bw, bh = w - 112, h - 40 if bw <= 0 or bh <= 0: return fill_h = bh * level / 100.0 @@ -881,10 +1050,24 @@ def _draw_open_channel(cr, widget): cr.line_to(x0 + bw, y0) cr.stroke() cr.restore() + # Alarm word labels, right-aligned left of the channel. + lab_cap = 0.023 * h + lab_size = _cap_size(lab_cap) + hi_hi, hi, lo, lo_lo = _alarms(widget) + for mark, colour, lab in ((hi_hi, cols["red"], "HI-HI"), + (hi, cols["amber"], "HI"), + (lo, cols["amber"], "LO"), + (lo_lo, cols["red"], "LO-LO")): + y = y0 + bh - bh * mark / 100.0 + _wtext(cr, widget, lab, x0 - 6, y + lab_cap * 0.35, + size=lab_size, bold=True, rgb=colour, + align="right", max_width=52) + scale_size = _fs(0.027, h) for i in range(6): y = y0 + bh - bh * i / 5.0 _wtext(cr, widget, "%d" % (i * 20), x0 + bw + 4, y + 4, - size=10, rgb=cols["ink"], max_width=26) + size=scale_size, bold=True, rgb=cols["ink"], + max_width=40) _tank_readout(cr, widget, level, x0 + bw / 2, h - 6, align="center") @@ -905,25 +1088,30 @@ def _draw_tank_alarms(cr, widget): cr.rectangle(x0 + 1, y0 + bh - fill_h, bw - 2, fill_h) cr.fill() cr.restore() - _alarm_lines(cr, widget, x0 + bw + 2, y0, y0 + bh) + _alarm_lines(cr, widget, x0 + bw + 2, y0, y0 + bh, labels=False) lamps = (("HI-HI", cols["red"], level >= hi_hi), ("HI", cols["amber"], level >= hi), ("LO", cols["amber"], level <= lo), ("LO-LO", cols["red"], level <= lo_lo)) lx = x0 + bw + 20 ly = y0 + 8 + # Audit: legend 14 px bold with 16 px swatches. + sw = max(6.0, 0.027 * h) + leg_cap = 0.023 * h + leg_size = _cap_size(leg_cap) for label, colour, lit in lamps: cr.save() _rgb(cr, colour if lit else (60 / 255, 60 / 255, 60 / 255)) - cr.arc(lx + 6, ly + 6, 6, 0, 2 * math.pi) + cr.arc(lx + sw / 2, ly + sw / 2, sw / 2, 0, 2 * math.pi) cr.fill_preserve() _rgb(cr, cols["ink"]) cr.set_line_width(1) cr.stroke() cr.restore() - _wtext(cr, widget, label, lx + 16, ly + 10, size=10, - rgb=cols["ink"], max_width=40) - ly += 20 + _wtext(cr, widget, label, lx + sw + 4, ly + sw / 2 + + leg_cap * 0.35, size=leg_size, bold=True, + rgb=cols["ink"], max_width=48) + ly += max(20.0, sw + 6) _tank_readout(cr, widget, level, x0 + bw / 2, h - 6, align="center") @@ -947,8 +1135,9 @@ def _draw_panel_lamp(cr, widget): on = _on(widget) brightness = _brightness(widget) w, h = widget.width, widget.height - cx, cy = w / 2, h / 2 - (6 if widget.text != widget.name else 0) - r = min(w, h) / 2 - 10 + # Audit: disc shrunk so the label clears below it (C: R - 30). + cx, cy = w / 2, h / 2 - 12 + r = min(w, h) / 2 - max(10.0, 0.0625 * h) if r < 4: return cr.save() @@ -970,9 +1159,11 @@ def _draw_panel_lamp(cr, widget): cr.arc(cx - r * 0.3, cy - r * 0.35, r * 0.18, 0, 2 * math.pi) cr.fill() cr.restore() - if widget.text != widget.name: - _wtext(cr, widget, widget.text, cx, h - 6, size=11, - align="center", rgb=(0.25, 0.25, 0.25), + # Audit: label 16-18 px bold with a clear gap below the disc. + lab = _label(widget) + if lab: + _wtext(cr, widget, lab, cx, h - 10, size=_fs(0.028, h), + bold=True, align="center", rgb=(0.25, 0.25, 0.25), max_width=w - 8) @@ -985,7 +1176,10 @@ def _draw_led(cr, widget): brightness = _brightness(widget) w, h = widget.width, widget.height cx = w / 2 - block_w, block_h = min(w - 16, 64), min(h - 30, 54) + # Audit: LED block scales with the widget (was capped at 64x54, + # so the label rule 12-15% of LED diameter had nothing to scale + # from); label 28 px bold at demo scale, leads end above it. + block_w, block_h = min(w - 16, 0.32 * w), min(h - 30, 0.45 * h) bx, by = cx - block_w / 2, 10 _rounded_box(cr, bx, by, block_w, block_h, dark, dark, radius=6) r = min(block_w, block_h) / 2 - 6 @@ -998,18 +1192,22 @@ def _draw_led(cr, widget): 0, 2 * math.pi) cr.fill() cr.restore() + lead_end = max(by + block_h + 4, h - 0.092 * h) cr.save() _rgb(cr, lead) cr.set_line_width(3) cr.move_to(cx - 10, by + block_h) - cr.line_to(cx - 10, h - 6) + cr.line_to(cx - 10, lead_end) cr.move_to(cx + 10, by + block_h) - cr.line_to(cx + 10, h - 6) + cr.line_to(cx + 10, lead_end) cr.stroke() cr.restore() - if widget.text != widget.name: - _wtext(cr, widget, widget.text, cx, h - 4, size=11, - align="center", rgb=(0.25, 0.25, 0.25), + lab = _label(widget) + if lab: + # Label 12-15% of the LED diameter, bold, above the leads. + _wtext(cr, widget, lab, cx, h - 8, + size=_cap_size(0.135 * 2 * r), + bold=True, align="center", rgb=(0.25, 0.25, 0.25), max_width=w - 8) @@ -1031,7 +1229,7 @@ def _draw_rgb_led(cr, widget): blue_on = all_on or _prop_bool(widget, "blue-on", False) w, h = widget.width, widget.height cx = w / 2 - block_w, block_h = min(w - 16, 64), min(h - 34, 50) + block_w, block_h = min(w - 16, 0.30 * w), min(h - 34, 0.40 * h) bx, by = cx - block_w / 2, 8 _rounded_box(cr, bx, by, block_w, block_h, dark, dark, radius=6) combined = ( @@ -1046,13 +1244,20 @@ def _draw_rgb_led(cr, widget): cr.arc(cx, by + block_h / 2, max(r, 3), 0, 2 * math.pi) cr.fill() cr.restore() - sw = 14 + # Audit: swatches 24 px with 14 px labels. + sw = max(8.0, 0.040 * h) + sw_cap = 0.023 * h sx = cx - (3 * sw + 2 * 6) / 2 sy = by + block_h + 6 - for on, colour in ((red_on, red_c), (green_on, green_c), - (blue_on, blue_c)): + for on, colour, ch in ((red_on, red_c, "R"), + (green_on, green_c, "G"), + (blue_on, blue_c, "B")): _box(cr, sx, sy, sw, sw, colour if on else (30 / 255, 30 / 255, 30 / 255), outline) + _wtext(cr, widget, ch, sx + sw / 2, sy + sw + 4 + + sw_cap * 0.35, size=_cap_size(sw_cap), bold=True, + rgb=(0.25, 0.25, 0.25), align="center", + max_width=sw + 8) sx += sw + 6 @@ -1065,23 +1270,37 @@ def _draw_stack_light(cr, widget): outline = _color(widget, "tier-outline-color", (60 / 255, 60 / 255, 60 / 255)) all_on = _prop_bool(widget, "all-on", False) - tiers = ( - ("red-on", "red-brightness", red), - ("amber-on", "amber-brightness", amber), - ("green-on", "green-brightness", green), - ) w, h = widget.width, widget.height cx = w / 2 pole_h = 18 - tier_h = max(14, (h - pole_h - 26) / 3) + # Audit: title 16 px bold on top; segment letters 24 px bold + # with contrast (white on lit, light grey on unlit -- the "A" + # on dark amber was nearly invisible, G6). + title_cap = 0.027 * h + title_h = title_cap + 8 + tier_h = max(14, (h - pole_h - 26 - title_h) / 3) tier_w = min(54, w - 20) x0 = cx - tier_w / 2 - y = 8 - for prop, bright_prop, colour in tiers: + lab = _label(widget) + if lab: + _wtext(cr, widget, lab, cx, 8 + title_cap, + size=_cap_size(title_cap), bold=True, align="center", + rgb=(0.25, 0.25, 0.25), max_width=w - 8) + y = 8 + title_h + letter_cap = 0.040 * h + for prop, bright_prop, colour, ch in ( + ("red-on", "red-brightness", red, "R"), + ("amber-on", "amber-brightness", amber, "A"), + ("green-on", "green-brightness", green, "G")): on = all_on or _prop_bool(widget, prop, False) bright = _prop_int(widget, bright_prop, 100) _rounded_box(cr, x0, y, tier_w, tier_h - 3, _lens_rgb(colour, on, bright), outline, radius=6) + _wtext(cr, widget, ch, cx, y + (tier_h - 3) / 2 + + letter_cap * 0.35, size=_cap_size(letter_cap), + bold=True, align="center", + rgb=(1.0, 1.0, 1.0) if on else (0.75, 0.75, 0.75), + max_width=tier_w - 4) y += tier_h # Pole + base. _box(cr, cx - 3, y, 6, pole_h, dark, dark) @@ -1100,11 +1319,16 @@ def _draw_beacon(cr, widget): lit = on and phase w, h = widget.width, widget.height cx = w / 2 - base_y = h - 18 - dome_r = min(w / 2 - 12, (h - 30) / 2) + # Audit: bar lowered so the dome clears it, captions inset 16 px + # bold (C: base_y y2-72, bar 28, dome 6 px above the bar); the + # bar sits above two text lines, so base_y reserves that room. + rate_cap = 0.027 * h + bar_h = max(10.0, 0.058 * h) + base_y = h - bar_h - 2 * rate_cap - 14 + dome_r = min(w / 2 - 12, (base_y - 12) / 2) if dome_r < 4: return - cy = base_y - dome_r + cy = base_y - dome_r - 6 if lit: cr.save() _rgb(cr, beacon, 0.25) @@ -1128,10 +1352,19 @@ def _draw_beacon(cr, widget): cr.set_line_width(2) cr.stroke() cr.restore() - _box(cr, cx - dome_r - 4, base_y, 2 * dome_r + 8, 10, dark, dark) - _wtext(cr, widget, "%.1f Hz" % _prop_float(widget, "flash-rate", 2.0), - cx, h - 4, size=11, align="center", rgb=(0.25, 0.25, 0.25), - max_width=w - 8) + # Rate in white on the dark bar, BEACON below it (audit G6/G7). + _box(cr, cx - dome_r - 4, base_y, 2 * dome_r + 8, bar_h, dark, + dark) + rate = "FLASH %g Hz" % _prop_float(widget, "flash-rate", 2.0) + _wtext(cr, widget, rate, cx, base_y + bar_h / 2 + + rate_cap * 0.35, size=_cap_size(rate_cap), bold=True, + align="center", rgb=(1.0, 1.0, 1.0), + max_width=2 * dome_r) + lab = _label(widget) + if lab: + _wtext(cr, widget, lab, cx, h - 8, size=_cap_size(rate_cap), + bold=True, align="center", rgb=(0.25, 0.25, 0.25), + max_width=w - 8) def _draw_lamp_test_button(cr, widget): @@ -1140,7 +1373,9 @@ def _draw_lamp_test_button(cr, widget): w, h = widget.width, widget.height _rounded_box(cr, 0, 0, w, h, bezel, bezel, radius=6) _rounded_box(cr, 4, 4, w - 8, h - 8, face, bezel, radius=5) - _wtext(cr, widget, "TEST", w / 2, h / 2 + 5, size=12, bold=True, + # Audit: button text 16 px bold, centred. + _wtext(cr, widget, "TEST", w / 2, h / 2 + 0.027 * h * 0.35, + size=_fs(0.027, h), bold=True, align="center", rgb=(0.15, 0.15, 0.15), max_width=w - 16) @@ -1340,7 +1575,9 @@ def _draw_seg_digit(cr, x, y, w, h, ch, on_rgb, off_rgb, cr.fill() else: x0, y0, x1, y1 = lines[seg] - _draw_diag(cr, x0, y0, x1, y1, t) + # Audit G5: diagonals thinned (2/3) so they read as + # strokes, not a dark X blob over the glyph. + _draw_diag(cr, x0, y0, x1, y1, t * 2 / 3) cr.restore() def _led_digits_text(value, digits, dp): """Zero-padded digit string + decimal-point index (C shown_digits @@ -1364,10 +1601,13 @@ def _draw_led_digits(cr, widget): digits = int(kind.replace("LedDigits", "")) dp = _prop_int(widget, "decimal-places", 0 if digits == 1 else 1) bezel = _color(widget, "bezel-color", (58 / 255, 58 / 255, 62 / 255)) - dim = _color(widget, "dim-color", (52 / 255, 14 / 255, 11 / 255)) + # Audit G5: unlit segments barely visible, never a ghost "8". + dim = _color(widget, "dim-color", (24 / 255, 15 / 255, 13 / 255)) lit = _color(widget, "lit-color", (255 / 255, 60 / 255, 35 / 255)) - _rounded_box(cr, 0, 0, widget.width, widget.height, bezel, bezel, - radius=6) + # Dark face (C bg) so the dim colour reads faintly lighter than + # the background, not as black shapes on a grey panel. + _rounded_box(cr, 0, 0, widget.width, widget.height, + (12 / 255, 12 / 255, 14 / 255), bezel, radius=6) text, point_after = _led_digits_text(_value(widget), digits, dp) pad = 10 gap = 6 @@ -1390,8 +1630,9 @@ def _draw_led_digits(cr, widget): def _draw_digital_readout(cr, widget): dark = _color(widget, "dark-color", (30 / 255, 30 / 255, 30 / 255)) + # Audit G5: unlit segments slightly more visible, uniform dim. off = _color(widget, "segment-off-color", - (50 / 255, 45 / 255, 20 / 255)) + (70 / 255, 62 / 255, 30 / 255)) on = _color(widget, "segment-on-color", (255 / 255, 176 / 255, 0.0)) _rounded_box(cr, 0, 0, widget.width, widget.height, dark, dark, @@ -1423,10 +1664,13 @@ def _draw_seg_display(cr, widget): digits = int(kind.replace("Seg14Display", "") .replace("Seg16Display", "")) bezel = _color(widget, "bezel-color", (58 / 255, 58 / 255, 62 / 255)) - dim = _color(widget, "dim-color", (60 / 255, 42 / 255, 8 / 255)) + # Audit G5: unlit segments uniform very dim, never brown blocks. + dim = _color(widget, "dim-color", (26 / 255, 20 / 255, 10 / 255)) lit = _color(widget, "lit-color", (255 / 255, 176 / 255, 0.0)) - _rounded_box(cr, 0, 0, widget.width, widget.height, bezel, bezel, - radius=6) + # Dark face (C bg) so the dim colour reads faintly lighter than + # the background, not as black shapes on a grey panel. + _rounded_box(cr, 0, 0, widget.width, widget.height, + (12 / 255, 12 / 255, 14 / 255), bezel, radius=6) raw = widget.get_prop( "value", widget.prop_def("value").default @@ -1497,15 +1741,28 @@ def _draw_rocker(cr, widget, illuminated=False, double=False): cr.set_line_width(1.5) cr.stroke() cr.restore() - _wtext(cr, widget, "I", w / 2, y0 + 12, size=11, align="center", - rgb=(0.15, 0.15, 0.15), max_width=20) - _wtext(cr, widget, "O", w / 2, y0 + rh - 4, size=11, - align="center", rgb=(0.15, 0.15, 0.15), max_width=20) + # Audit: state labels 16 px bold. + lab_cap = 0.027 * h + lab_size = _cap_size(lab_cap) + _wtext(cr, widget, "I ON" if not double else "UP", w / 2, + y0 + 12 + lab_cap * 0.35, size=lab_size, bold=True, + align="center", rgb=(0.15, 0.15, 0.15), max_width=w - 16) + _wtext(cr, widget, "O OFF" if not double else "DOWN", w / 2, + y0 + rh - 4, size=lab_size, bold=True, + align="center", rgb=(0.15, 0.15, 0.15), max_width=w - 16) if illuminated: on = _on(widget) - _rounded_box(cr, w / 2 - 12, y0 + rh / 2 - 5, 24, 10, + # Lamp window scales with the widget; state text inside it. + lamp_w = max(24.0, 0.18 * w) + lamp_h = max(10.0, 0.05 * h) + _rounded_box(cr, w / 2 - lamp_w / 2, y0 + rh / 2 - lamp_h / 2, + lamp_w, lamp_h, greenlit if on else dimred, green if on else dimred, radius=4) + _wtext(cr, widget, "ON" if on else "OFF", w / 2, + y0 + rh / 2 + lab_cap * 0.35, size=lab_size, bold=True, + align="center", rgb=(0.1, 0.1, 0.1), + max_width=lamp_w - 4) def _draw_toggle_switch(cr, widget, illuminated=False): @@ -1551,7 +1808,8 @@ def _draw_toggle_switch(cr, widget, illuminated=False): _rgb(cr, greenlit if on else redlit) cr.arc(cx + 22, 18, 4, 0, 2 * math.pi) cr.fill() - _wtext(cr, widget, "ON" if on else "OFF", cx, h - 8, size=10, + _wtext(cr, widget, "ON" if on else "OFF", cx, h - 8, + size=_fs(0.027, h), bold=True, align="center", rgb=(0.9, 0.9, 0.9), max_width=40) @@ -1565,15 +1823,26 @@ def _draw_slide_switch(cr, widget): on = _on(widget) w, h = widget.width, widget.height _rounded_box(cr, 6, 6, w - 12, h - 12, panel, bezel, radius=8) - track_h = 16 + # Audit: bigger knob with a clear grip; labels 16 px bold. + track_h = max(12.0, 0.04 * h) ty = h / 2 - track_h / 2 _rounded_box(cr, 14, ty, w - 28, track_h, bezel, bezel, radius=track_h / 2) - knob_w = 30 + knob_w = max(30.0, 0.12 * w) kx = (w - 14 - knob_w) if on else 14 _rounded_box(cr, kx, ty - 5, knob_w, track_h + 10, rocker, bezel, radius=6) - _wtext(cr, widget, "ON" if on else "OFF", w / 2, h - 8, size=10, + cr.save() + _rgb(cr, bezel) + cr.set_line_width(2) + for gx in (-1, 0, 1): + gx0 = kx + knob_w / 2 + gx * 8 + cr.move_to(gx0, ty - 2) + cr.line_to(gx0, ty + track_h + 2) + cr.stroke() + cr.restore() + _wtext(cr, widget, "ON" if on else "OFF", w / 2, h - 8, + size=_fs(0.027, h), bold=True, align="center", rgb=(0.9, 0.9, 0.9), max_width=40) @@ -1584,9 +1853,12 @@ def _draw_key_switch(cr, widget): plate = _color(widget, "plate-color", (210 / 255, 210 / 255, 210 / 255)) amber = _color(widget, "amber-color", (255 / 255, 176 / 255, 0.0)) key_in = _prop_bool(widget, "key-in", False) + position = max(0, min(2, _prop_int(widget, "position", 0))) w, h = widget.width, widget.height cx, cy = w / 2, h / 2 - r = min(w, h) / 2 - 10 + # Plate leaves a band at the bottom for the state text (audit + # G7: "NO KEY" was clipped by the plate edge). + r = min(w, h) / 2 - 34 if r < 4: return _rounded_box(cr, 6, 6, w - 12, h - 12, panel, bezel, radius=8) @@ -1597,28 +1869,46 @@ def _draw_key_switch(cr, widget): _rgb(cr, bezel) cr.set_line_width(2) cr.stroke() - # Key slot pointing up; positions around it. + # Key slot points at the current position (C: -120 deg + pos). + pa = -2.094 + position * (4.188 / 2) _rgb(cr, bezel) cr.set_line_width(max(2, _prop_int(widget, "pointer-line-width", 10) // 2)) cr.move_to(cx, cy) - cr.line_to(cx, cy - r + 8) + cr.line_to(cx + (r - 8) * math.cos(pa), + cy + (r - 8) * math.sin(pa)) cr.stroke() if key_in: _rgb(cr, amber) cr.set_line_width(4) - cr.move_to(cx, cy - r + 8) - cr.line_to(cx, cy - r - 6) + cr.move_to(cx + (r - 8) * math.cos(pa), + cy + (r - 8) * math.sin(pa)) + cr.line_to(cx + (r + 6) * math.cos(pa), + cy + (r + 6) * math.sin(pa)) cr.stroke() _rgb(cr, amber) - cr.arc(cx, cy - r - 6, 5, 0, 2 * math.pi) + cr.arc(cx + (r + 6) * math.cos(pa), + cy + (r + 6) * math.sin(pa), 5, 0, 2 * math.pi) cr.fill() _rgb(cr, bezel) cr.arc(cx, cy, 5, 0, 2 * math.pi) cr.fill() cr.restore() - _wtext(cr, widget, "KEY", cx, h - 8, size=10, align="center", - rgb=(0.9, 0.9, 0.9), max_width=40) + # Audit: position numerals 16 px bold; state light-on-dark + # ("NO KEY" was dark-on-dark, nearly invisible, G6). + num_cap = 0.027 * h + num_size = _cap_size(num_cap) + for i in range(3): + # C: -120 deg + i * 120 deg (positions around the dial). + angle = -2.094 + i * (4.188 / 2) + tx = cx + (r + 8) * math.cos(angle) + ty = cy + (r + 8) * math.sin(angle) + _wtext(cr, widget, str(i), tx, ty + num_cap * 0.35, + size=num_size, bold=True, align="center", + rgb=(0.9, 0.9, 0.9), max_width=16) + _wtext(cr, widget, "KEY IN" if key_in else "NO KEY", cx, h - 8, + size=_fs(0.023, h), bold=True, align="center", + rgb=(0.9, 0.9, 0.9), max_width=80) def _draw_rotary(cr, widget): @@ -1635,14 +1925,22 @@ def _draw_rotary(cr, widget): if r < 4: return _rounded_box(cr, 6, 6, w - 12, h - 12, panel, bezel, radius=8) + # Audit: numerals 16 px bold. + num_cap = 0.027 * h + num_size = _cap_size(num_cap) for i in range(positions): angle = -math.pi * 0.75 + i * (math.pi * 1.5 / (positions - 1)) tx = cx + (r + 8) * math.cos(angle) ty = cy + (r + 8) * math.sin(angle) - _wtext(cr, widget, str(i), tx, ty + 4, size=10, + _wtext(cr, widget, str(i), tx, ty + num_cap * 0.35, + size=num_size, bold=True, align="center", rgb=(0.9, 0.9, 0.9), max_width=16) cr.save() + # new_path: the numeral _wtext calls above leave a current point + # at the last numeral; without this, arc() joins it to the arc + # start with a stray chord across the plate. + cr.new_path() _rgb(cr, plate) cr.arc(cx, cy, r, 0, 2 * math.pi) cr.fill_preserve() @@ -1663,6 +1961,11 @@ def _draw_rotary(cr, widget): cr.arc(cx, cy, 5, 0, 2 * math.pi) cr.fill() cr.restore() + # Audit: readout 16 px bold inside the plate, below the hub. + _wtext(cr, widget, "POS %d / %d" % (position, positions), + cx, cy + r * 0.6, size=_fs(0.027, h), bold=True, + align="center", rgb=(0.25, 0.25, 0.25), + max_width=2 * r) def _draw_push_button(cr, widget, latching=False): @@ -1674,16 +1977,19 @@ def _draw_push_button(cr, widget, latching=False): (255 / 255, 70 / 255, 60 / 255)) on = _on(widget) w, h = widget.width, widget.height - cx, cy = w / 2, h / 2 + 4 - r = min(w, h) / 2 - 12 + # Button leaves a foot band for the title (C: title at the foot). + cx, cy = w / 2, (h - 0.05 * h) / 2 + r = min(w, h * 0.95) / 2 - 12 if r < 4: return cr.save() _rgb(cr, bezel) cr.arc(cx, cy, r + 5, 0, 2 * math.pi) cr.fill() - face = (0.75, 0.75, 0.78) if (on and latching) else \ - (0.9, 0.9, 0.92) + # Audit G6: face label white on the coloured face, 18 px bold. + # The face itself shows the state (green on, red off), so the + # old indicator dot above the button is gone. + face = (0.1, 0.6, 0.2) if on else (0.78, 0.12, 0.12) _rgb(cr, face) cr.arc(cx, cy, r, 0, 2 * math.pi) cr.fill_preserve() @@ -1694,13 +2000,17 @@ def _draw_push_button(cr, widget, latching=False): cr.arc(cx - r * 0.3, cy - r * 0.35, r * 0.2, 0, 2 * math.pi) cr.fill() cr.restore() - _rgb(cr, greenlit if on else redlit) - cr.arc(cx, cy - r - 8, 5, 0, 2 * math.pi) - cr.fill() - _wtext(cr, widget, widget.text if widget.text != widget.name - else ("PUSH" if not latching else "LATCH"), cx, h - 6, - size=11, align="center", rgb=(0.25, 0.25, 0.25), - max_width=w - 8) + face_cap = 0.030 * h + _wtext(cr, widget, "ON" if on else + ("LATCH" if latching else "PUSH"), cx, + cy + face_cap * 0.35, size=_cap_size(face_cap), bold=True, + align="center", rgb=(1.0, 1.0, 1.0), max_width=2 * r) + # Title at the foot, only when the designer set a text. + title = _label(widget) + if title: + _wtext(cr, widget, title, cx, h - 6, size=_fs(0.027, h), + bold=True, align="center", rgb=(0.25, 0.25, 0.25), + max_width=w - 8) def _draw_emergency_stop(cr, widget): @@ -1712,11 +2022,12 @@ def _draw_emergency_stop(cr, widget): (255 / 255, 70 / 255, 60 / 255)) on = _on(widget) w, h = widget.width, widget.height - cx, cy = w / 2, h / 2 - r = min(w, h) / 2 - 10 + cx, cy = w / 2, (h - 0.05 * h) / 2 + r = min(w, h * 0.95) / 2 - 10 if r < 4: return - _rounded_box(cr, 8, 8, w - 16, h - 16, surround, surround, radius=8) + _rounded_box(cr, 8, 8, w - 16, h - 16 - 0.05 * h, surround, + surround, radius=8) cr.save() _rgb(cr, (40 / 255, 40 / 255, 40 / 255)) cr.rectangle(cx - 8, cy - 4, 16, r) @@ -1731,8 +2042,17 @@ def _draw_emergency_stop(cr, widget): cr.arc(cx - r * 0.25, cy - r * 0.35, r * 0.18, 0, 2 * math.pi) cr.fill() cr.restore() - _wtext(cr, widget, "STOP", cx, h - 6, size=11, bold=True, - align="center", rgb=(0.6, 0.1, 0.1), max_width=w - 8) + # Audit G6: "E-STOP" white on red, 18 px bold, on the button. + face_cap = 0.030 * h + _wtext(cr, widget, "STOPPED" if on else "E-STOP", cx, + cy + face_cap * 0.35, size=_cap_size(face_cap), bold=True, + align="center", rgb=(1.0, 1.0, 1.0), max_width=2 * r) + # Title at the foot, only when the designer set a text. + title = _label(widget) + if title: + _wtext(cr, widget, title, cx, h - 6, size=_fs(0.027, h), + bold=True, align="center", rgb=(0.25, 0.25, 0.25), + max_width=w - 8) def _draw_circuit_breaker(cr, widget): @@ -1764,8 +2084,16 @@ def _draw_circuit_breaker(cr, widget): _rgb(cr, red) cr.arc(bx + bw - 10, by + bh - 12, 5, 0, 2 * math.pi) cr.fill() - _wtext(cr, widget, "ON", bx + bw / 2, by + bh - 4, size=10, + # Audit: state label 16 px bold; title 16 px at the foot. + # The lever is drawn up (ON), so the label reads ON. + _wtext(cr, widget, "ON", bx + bw / 2, + by + bh - 4, size=_fs(0.027, h), bold=True, align="center", rgb=(0.25, 0.25, 0.25), max_width=bw) + title = _label(widget) + if title: + _wtext(cr, widget, title, w / 2, h - 6, size=_fs(0.027, h), + bold=True, align="center", rgb=(0.25, 0.25, 0.25), + max_width=w - 8) # --- panel furniture ----------------------------------------------------------- @@ -1785,9 +2113,12 @@ def _draw_bezel(cr, widget): cr.stroke() cr.restore() _panel_screws(cr, widget) - if widget.text != widget.name: - _wtext(cr, widget, widget.text, widget.width / 2, 12, size=11, - align="center", rgb=ink, max_width=widget.width - 40) + # Audit: label 14-16 px, inside the frame below the top edge. + lab = _label(widget) or "GAUGE" + lab_cap = 0.025 * widget.height + _wtext(cr, widget, lab, widget.width / 2, + margin + lab_cap + 2, size=_cap_size(lab_cap), bold=True, + align="center", rgb=ink, max_width=widget.width - 40) def _draw_panel_plate(cr, widget): @@ -1795,10 +2126,14 @@ def _draw_panel_plate(cr, widget): ink = _color(widget, "ink-color", (40 / 255, 40 / 255, 40 / 255)) amber = _color(widget, "amber-color", (255 / 255, 176 / 255, 0.0)) _bg(cr, widget, panel, stroke=ink) - _box(cr, 8, 8, widget.width - 16, 22, amber, amber) + # Audit: header bar taller for the 18-20 px bold title. + bar_h = max(22.0, 0.079 * widget.height) + title_cap = 0.032 * widget.height + _box(cr, 8, 8, widget.width - 16, bar_h, amber, amber) _wtext(cr, widget, widget.text if widget.text != widget.name - else "PANEL", widget.width / 2, 24, size=12, bold=True, - align="center", rgb=(0.15, 0.15, 0.15), + else "PANEL", widget.width / 2, + 8 + bar_h / 2 + title_cap * 0.35, size=_cap_size(title_cap), + bold=True, align="center", rgb=(0.15, 0.15, 0.15), max_width=widget.width - 32) _panel_screws(cr, widget) @@ -1809,9 +2144,13 @@ def _draw_nameplate(cr, widget): (240 / 255, 220 / 255, 160 / 255)) _rounded_box(cr, 0, 0, widget.width, widget.height, dark, dark, radius=6) - _wtext(cr, widget, widget.text if widget.text != widget.name - else "NAMEPLATE", widget.width / 2, widget.height / 2 + 5, - size=13, bold=True, align="center", rgb=engraved, + # Audit: engraving fills 40-50% of the plate width, bold. + label = widget.text if widget.text != widget.name else "NAMEPLATE" + size = _fit_size(cr, widget, label, 0.45 * widget.width, + _cap_size(0.45 * widget.height), bold=True) + _wtext(cr, widget, label, widget.width / 2, + widget.height / 2 + size * 0.72 * 0.35, + size=size, bold=True, align="center", rgb=engraved, max_width=widget.width - 40) _screw(cr, 12, widget.height / 2) _screw(cr, widget.width - 12, widget.height / 2) @@ -1825,25 +2164,31 @@ def _draw_control_panel(cr, widget): rows = max(1, _prop_int(widget, "grid-rows", 3)) cols = max(1, _prop_int(widget, "grid-cols", 2)) _bg(cr, widget, panel, stroke=ink) - _box(cr, 8, 8, widget.width - 16, 22, amber, amber) + # Audit: header title 18-20 px bold, grid labels 14 px bold. + bar_h = max(22.0, 0.079 * widget.height) + title_cap = 0.032 * widget.height + _box(cr, 8, 8, widget.width - 16, bar_h, amber, amber) _wtext(cr, widget, widget.text if widget.text != widget.name - else "CONTROL", widget.width / 2, 24, size=12, bold=True, - align="center", rgb=(0.15, 0.15, 0.15), + else "CONTROL", widget.width / 2, + 8 + bar_h / 2 + title_cap * 0.35, size=_cap_size(title_cap), + bold=True, align="center", rgb=(0.15, 0.15, 0.15), max_width=widget.width - 32) _panel_screws(cr, widget) - grid_x, grid_y = 14, 38 - grid_w, grid_h = widget.width - 28, widget.height - 52 + grid_x, grid_y = 14, 8 + bar_h + 8 + grid_w, grid_h = widget.width - 28, widget.height - grid_y - 14 if grid_w <= 0 or grid_h <= 0: return cell_w, cell_h = grid_w / cols, grid_h / rows labels = ("PUMP", "VALVE", "MOTOR", "FAN", "LIGHT", "HEATER") + lab_cap = 0.023 * widget.height for r in range(rows): for c in range(cols): x, y = grid_x + c * cell_w, grid_y + r * cell_h _box(cr, x + 2, y + 2, cell_w - 4, cell_h - 4, face, ink) label = labels[(r * cols + c) % len(labels)] _wtext(cr, widget, label, x + cell_w / 2, - y + cell_h / 2 + 4, size=11, align="center", + y + cell_h / 2 + lab_cap * 0.35, + size=_cap_size(lab_cap), bold=True, align="center", rgb=ink, max_width=cell_w - 8) diff --git a/lightgui/xframe/monitor.py b/lightgui/xframe/monitor.py index 4f9e9e1..f88c464 100644 --- a/lightgui/xframe/monitor.py +++ b/lightgui/xframe/monitor.py @@ -39,6 +39,7 @@ from lightgui.xframe.core import ( _rounded_box, _rounded_path, _text_width, + _wrap_lines, _wtext, parse_color, ) @@ -105,6 +106,23 @@ 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)) @@ -292,16 +310,18 @@ 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, 15, size=12, rgb=_TITLE, bold=True, + _wtext(cr, widget, title, 8, 17, size=16, rgb=_TITLE, bold=True, max_width=widget.width - 16) - return 22 + return 24 return 6 -def _plot_frame(cr, x, y, w, h, lo, hi, labels=True): +def _plot_frame(cr, x, y, w, h, lo, hi, labels=True, label_size=14, + fmt=None): """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.""" + starts too close to the left edge for labels to fit. *fmt* formats + the tick values (humanised rates for the net graph).""" if w <= 0 or h <= 0: return _box(cr, x, y, w, h, _PANEL_INNER, _GRID) @@ -316,16 +336,28 @@ def _plot_frame(cr, x, y, w, h, lo, hi, labels=True): cr.restore() if not labels: return - 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) + 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) -def _ylabel(cr, text, x, y): - """Small dim right-aligned y-axis label.""" +def _ylabel(cr, text, x, y, size=8): + """Small dim right-aligned y-axis label (baseline *y*).""" cr.save() cr.select_font_face("Sans", 0, 0) - cr.set_font_size(8) + cr.set_font_size(size) _rgb(cr, _DIM) w = cr.text_extents(text)[2] cr.move_to(x - w, y) @@ -333,6 +365,16 @@ def _ylabel(cr, text, x, y): 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 @@ -865,8 +907,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 @@ -906,15 +948,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 - 8, 8, 8, color, color) + _box(cr, 8, y - 10, 10, 10, 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, 22, y, size=10, rgb=_TEXT, - max_width=self.width - 28) - y += 14 + _wtext(cr, self, line, 24, y, size=14, rgb=_TEXT, + max_width=self.width - 30) + y += 18 return y def _draw_history_graph(self, cr): @@ -926,16 +968,26 @@ class MonitorWidget(Widget): series = self._plot_series() names = self._series_names() show_legend = _prop_bool(self, "show-legend", True) - 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) + 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) 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)]) - if show_legend: - self._legend(cr, plot_y + plot_h + 12, series, names) + # 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") def _draw_core_grid(self, cr): top = _panel(cr, self, self._title()) @@ -946,6 +998,7 @@ 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) @@ -954,14 +1007,15 @@ 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 + 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) + _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) if ch > 26: - _series_line(cr, values, x + 3, y + 17, cw - 6, - ch - 20, 0.0, 100.0, color, width=1.0, - fill=True) + _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) def _draw_net_graph(self, cr): top = _panel(cr, self, self._title()) @@ -969,47 +1023,67 @@ 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) - 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) + 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) _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()) threshold = _prop_float(self, "threshold", 80.0) values = self._single_series(58.0, 24.0, 0.0, 120.0) lo, hi = 0.0, max(100.0, threshold + 20.0) + body_px = _fpx(0.032 * self.height, 11, 16) if values: cur = values[-1] cur_rgb = _RED if cur > threshold else _TEXT - _wtext(cr, self, "%.1f C" % cur, self.width - 8, 15, size=14, - rgb=cur_rgb, align="right", bold=True) + _wtext(cr, self, "%.1f C" % cur, self.width - 8, 17, + size=body_px, rgb=cur_rgb, + align="right", bold=True) else: # Honest empty state: no samples, no reading to show. - _wtext(cr, self, "no data", self.width - 8, 15, size=14, + _wtext(cr, self, "no data", self.width - 8, 17, size=body_px, rgb=_DIM, align="right", bold=True) - plot_x, plot_y = 34, top + 2 - plot_w = max(1, self.width - 40) + 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) plot_h = max(1, self.height - plot_y - 20) - _plot_frame(cr, plot_x, plot_y, plot_w, plot_h, lo, hi) - # Threshold line (dashed red) + label. + _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. thr_y = plot_y + plot_h - (threshold - lo) / (hi - lo) * plot_h cr.save() _rgb(cr, _RED) @@ -1019,8 +1093,9 @@ class MonitorWidget(Widget): cr.line_to(plot_x + plot_w, thr_y) cr.stroke() cr.restore() - _wtext(cr, self, "%.0f C" % threshold, plot_x + plot_w - 2, - thr_y - 3, size=9, rgb=_RED, align="right") + _wtext(cr, self, "%.0f C limit" % threshold, + plot_x + plot_w - 2, thr_y - 6, size=14, 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. @@ -1051,7 +1126,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 + 13, size=10, rgb=_DIM) + 8, plot_y + plot_h + 14, size=13, rgb=_DIM) def _gradient_bar(self, cr, x, y, w, h, frac, horizontal=True): """Trough + green->yellow->red gradient fill to *frac*.""" @@ -1085,19 +1160,66 @@ 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) - _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) + # 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) def _draw_stack_bar(self, cr): segments = self.get_segments() total = sum(v for _label, v, _c in segments) or 1.0 - bar_y, bar_h = 4, 16 + 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) x = 0.0 for label, value, color in segments: seg_w = self.width * value / total @@ -1105,18 +1227,16 @@ class MonitorWidget(Widget): continue _box(cr, x, bar_y, max(0, seg_w - 1), bar_h, color, color) x += seg_w - # 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 + 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 def _draw_vertical_bar(self, cr): frac = _range_frac(self) @@ -1129,15 +1249,30 @@ class MonitorWidget(Widget): self._peak = peak lo = _prop_float(self, "minimum", 0.0) hi = _prop_float(self, "maximum", 100.0) - _panel(cr, self) - bar_x, bar_w = 26, self.width - 34 - bar_y, bar_h = 10, self.height - 34 + 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 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 - _ylabel(cr, "%.0f" % (lo + f * (hi - lo)), bar_x - 4, gy + 3) + 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) cr.save() _rgb(cr, _GRID) cr.set_line_width(1) @@ -1145,7 +1280,8 @@ class MonitorWidget(Widget): cr.line_to(bar_x, gy) cr.stroke() cr.restore() - # Peak-hold marker. + # Peak-hold marker + label (bold, above the line, inset from + # the frame edge). if peak > lo: py = bar_y + bar_h - (peak - lo) / (hi - lo) * bar_h \ if hi > lo else bar_y @@ -1156,12 +1292,20 @@ class MonitorWidget(Widget): cr.line_to(bar_x + bar_w + 2, py) cr.stroke() cr.restore() - _wtext(cr, self, "%.0f%%" % value, self.width / 2, - self.height - 8, size=11, rgb=_TEXT, align="center", - bold=True) + _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) def _draw_tachometer(self, cr): - top = _panel(cr, self, self._title()) + top = _panel(cr, self) lo = _prop_float(self, "minimum", 0.0) hi = _prop_float(self, "maximum", 8000.0) if hi <= lo: @@ -1190,7 +1334,9 @@ class MonitorWidget(Widget): _RED, 10, cap=1) _arc_stroke(cr, cx, cy, r, start, _angle(frac), _CYAN, 10, cap=1) - # Ticks + numbers. + # 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) cr.save() for i in range(11): f = i / 10.0 @@ -1207,10 +1353,20 @@ class MonitorWidget(Widget): cr.restore() if major: label = "%.0f" % (lo + f * (hi - lo)) - lx = cx + (r - 26) * math.cos(ang) - ly = cy + (r - 26) * math.sin(ang) + 3 - _wtext(cr, self, label, lx, ly, size=9, rgb=_TEXT, - align="center") + # Numeral centre radius: the glyph box's farthest + # corner in the radial direction must stay inside the + # tick ring (inner end r-16) with 4 px clearance, so a + # wide 4-digit label never crosses the dial rim. + lw = _text_width(cr, self, label, size=numeral_px, bold=True) + extent = (lw / 2) * abs(math.cos(ang)) \ + + (numeral_px / 2) * abs(math.sin(ang)) + lr = max(8.0, r - 16 - extent - 4) + lx = cx + lr * math.cos(ang) + ly = cy + lr * 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) # Peak-hold tick. cr.save() _rgb(cr, _WHITE) @@ -1236,13 +1392,21 @@ class MonitorWidget(Widget): cr.arc(cx, cy, 6, 0, 2 * math.pi) cr.fill() cr.restore() - # Digital readout: below the hub, clear of the 0/max tick - # labels at the bottom of the dial. + # 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) 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 + 14, size=10, + _wtext(cr, self, unit, cx, cy + r * 0.80 + 16, size=12, rgb=_DIM, align="center") def _draw_arc_gauge(self, cr): @@ -1250,8 +1414,8 @@ class MonitorWidget(Widget): frac = _range_frac(self) value = _prop_float(self, "value", 0.0) cx = self.width / 2 - cy = self.height - 14 - r = min(self.width / 2 - 12, self.height - top - 22) + cy = self.height - 32 + r = min(self.width / 2 - 12, self.height - top - 40) if r <= 0: return zones = ((0.0, 0.6, _GREEN), (0.6, 0.8, _YELLOW), @@ -1263,48 +1427,72 @@ 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) - _wtext(cr, self, "%.0f%%" % value, cx, cy - r * 0.45, size=22, - rgb=_WHITE, align="center", bold=True) + 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) label = self.get_prop("unit", "") or "usage" - _wtext(cr, self, label, cx, cy - r * 0.45 + 16, size=10, + _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, rgb=_DIM, align="center") def _draw_donut_gauge(self, cr): - top = _panel(cr, self, self._title()) + # No top-left title: the centre label carries the value name + # (the title would duplicate it). + top = _panel(cr, self) frac = _range_frac(self) value = _prop_float(self, "value", 0.0) cx = self.width / 2 cy = top + (self.height - top) / 2 - r = min(self.width, self.height - top) / 2 - 12 - if r <= 0: + r0 = min(self.width, self.height - top) / 2 - 12 + if r0 <= 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), 14, cap=1) + (0.25, 0.25, 0.28), thick, cap=1) _arc_stroke(cr, cx, cy, r, -math.pi / 2, - -math.pi / 2 + frac * 2 * math.pi, _GREEN, 14, + -math.pi / 2 + frac * 2 * math.pi, _GREEN, thick, cap=1) - _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, + 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, 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"), (244, 48, "Mem", "right"), - (296, 56, "CPU%", "right")) - header_y = top + 13 + (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 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=10, + _wtext(cr, self, name, x + _w, header_y, size=13, rgb=_DIM, align="right", bold=True) else: - _wtext(cr, self, name, x, header_y, size=10, + _wtext(cr, self, name, x, header_y, size=13, rgb=_DIM, bold=True) - row_h = 18 - y0 = top + 18 + row_h = 23 + y0 = top + 24 visible = max(0, (self.height - y0) // row_h) for i, row in enumerate(rows[:visible]): y = y0 + i * row_h @@ -1317,42 +1505,52 @@ 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 + 13, size=10, + _wtext(cr, self, str(row["pid"]), 6, y + 16, size=13, rgb=_TEXT) - _wtext(cr, self, row["name"], 62, y + 13, size=10, + _wtext(cr, self, row["name"], 62, y + 16, size=13, rgb=_TEXT, max_width=128) - _wtext(cr, self, row["user"], 196, y + 13, size=10, + _wtext(cr, self, row["user"], 196, y + 16, size=13, rgb=_TEXT, max_width=44) - _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), + _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), (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 + 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) + _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) def _draw_load_badge(self, cr): _panel(cr, self) load1, load5, load15, uptime = self._load_values() ncores = os.cpu_count() or 1 - _wtext(cr, self, "Load", 8, 24, size=13, rgb=_DIM, bold=True) - x = 52 + # 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 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, 24, size=13, rgb=color, bold=True) - x += _text_width(cr, self, text, size=13, bold=True) + 12 + _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, "%s %d cores" % (_fmt_uptime(uptime), ncores), - 8, 46, size=11, rgb=_TEXT) + 8, val_base + 28, size=14, rgb=_TEXT) def _draw_monitor_button(self, cr): status = self._status @@ -1369,31 +1567,40 @@ 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(18, self.height / 2, 7, 0, 2 * math.pi) + cr.arc(dot_cx, mid_y, dot_r, 0, 2 * math.pi) cr.fill() if status == "up": _rgb(cr, _WHITE) - cr.arc(18, self.height / 2, 2.5, 0, 2 * math.pi) + cr.arc(dot_cx, mid_y, dot_r * 0.35, 0, 2 * math.pi) cr.fill() label = self.get_prop("label", "") or self.get_prop("target", "") \ or self.kind status_text = _STATUS_LABELS[status] - sw = _text_width(cr, self, status_text, size=12, bold=True) - mid_y = self.height / 2 + 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 if self._detail: - _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) + _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) else: - _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) + _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) def _draw_monitor_grid(self, cr): top = _panel(cr, self, self._title()) @@ -1402,6 +1609,13 @@ 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 @@ -1409,16 +1623,36 @@ 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(x + 12, y + h / 2, 5, 0, 2 * math.pi) + cr.arc(dot_cx, mid_y, dot_r, 0, 2 * math.pi) cr.fill() - 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) + 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 def _draw_sys_box(self, cr): top = _panel(cr, self, self._title()) @@ -1428,24 +1662,29 @@ class MonitorWidget(Widget): hi = _prop_float(self, "maximum", 100.0) if hi <= lo: hi = lo + 100.0 - _wtext(cr, self, "%.0f" % value, 8, top + 26, size=26, - rgb=_WHITE, bold=True) + 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, unit, 8 + _text_width(cr, self, "%.0f" % value, - size=26, bold=True) + 6, - top + 26, size=12, rgb=_DIM) + 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") values = self._single_series(55.0, 28.0, lo, hi) - graph_y = top + 34 - graph_h = max(1, self.height - graph_y - 26) + 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) _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))) - self._gradient_bar(cr, 8, self.height - 20, self.width - 16, - 12, frac) + bar_y = self.height - 8 - bar_h + self._gradient_bar(cr, 8, bar_y, self.width - 16, bar_h, frac) _wtext(cr, self, "%.0f%%" % (frac * 100.0), self.width - 12, - self.height - 10, size=9, rgb=_WHITE, align="right", - bold=True) + bar_y + bar_h / 2 + 5, size=14, rgb=_WHITE, + align="right", bold=True) _MONITOR_DRAW = {