diff --git a/lightgui/xframe/instruments.py b/lightgui/xframe/instruments.py index a113f63..dc87dae 100644 --- a/lightgui/xframe/instruments.py +++ b/lightgui/xframe/instruments.py @@ -85,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): @@ -1731,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): @@ -1785,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) @@ -1799,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) @@ -1890,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() @@ -1918,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): @@ -1929,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() @@ -1949,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): @@ -1967,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) @@ -1986,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): @@ -2019,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 ----------------------------------------------------------- @@ -2040,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): @@ -2050,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) @@ -2084,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)