Files
lightgui_python/lightgui/xframe/instruments.py
Muse 53429a87e6 Inst*: proportions fix (audit Dec 2026) — buttons, switches, panels
Rocker I ON / O OFF (UP / DOWN double) 16 px bold, illuminated
lamp window scaled with ON/OFF inside; toggle/slide state 16 px
bold, slide knob bigger with grip; rotary numerals 16 px bold +
POS n / N readout inside the plate; push-button face label white
on the coloured face 18 px bold with title at the foot; E-STOP
white on red 18 px bold on the mushroom; breaker ON 16 px bold;
bezel GAUGE 14-16 px; panel/control headers taller with 18-20 px
bold titles, grid labels 14 px bold. Drive-bys found while
shooting: _color now falls back to the per-kind PropDef default
(LedBlue/PanelLampBlue rendered red); Rotary plate arc joined a
stray chord from the last numeral (cr.new_path before arc).
2026-12-05 22:53:17 +00:00

2280 lines
84 KiB
Python

"""Instrumentation widgets (66): Cairo drawings in the archetype structure.
Ports the C designer (widgets/components/Inst*, docs/instrumentation*.md)
to the Python XFrame archetype model: one InstWidget class,
parameterised by ``kind``, with kind-specific branches in _draw --
the same pattern as the other archetypes in lightgui/xframe/core.py.
Families: gauges (round dial + needle, bar meter, rotameter,
manometer), tanks (fill 0-100% + alarm bands hi-hi 95 / hi 80 /
lo 20 / lo-lo 5), lamps/LEDs (on/off + brightness 0-100), 7-segment
LED digits, 14/16-segment alphanumeric displays, switches, needles,
panel furniture. Draw fallbacks are the C member defaults from
tools/gen_phase4_props.py, so a freshly placed widget looks like
its C demo (e.g. VerticalTankLevel level 76.28, AnalogGauge value
62.0). ``set_level``/``set_value`` are live: editing level in the
Inspector repaints the fill immediately.
"""
import math
from lightgui.xframe.core import (
Widget,
_apply_font,
parse_color,
_bg,
_box,
_prop_bool,
_prop_float,
_prop_int,
_rgb,
_rounded_box,
_text_width,
_wtext,
)
# Palette kinds (instruments.py covers the 66 Inst* registry names).
INST_KINDS = frozenset((
"AnalogGauge", "BarMeter", "Beacon", "Bezel", "CircuitBreaker",
"ControlPanel", "DigitalReadout", "EmergencyStop", "FlowMeter",
"HorizontalTankLevel", "KeySwitch", "LampTestButton", "LedBlue",
"LedDigits1", "LedDigits2", "LedDigits3", "LedDigits4",
"LedDigits5", "LedDigits6", "LedGreen", "LedRed",
"LevelColumnGauge", "LevelTransmitter", "Manometer", "Nameplate",
"NeedleEdgewise", "NeedleKnifeEdge", "NeedleTapered", "NeedleVu",
"OpenChannelLevel", "PanelLampAmber", "PanelLampBlue",
"PanelLampGreen", "PanelLampRed", "PanelLampWhite", "PanelPlate",
"PressureGauge", "PushButton", "PushButtonLatching", "RgbStatusLed",
"RockerSwitch", "RockerSwitchDouble", "RockerSwitchIlluminated",
"Rotary", "Seg14Display1", "Seg14Display2", "Seg14Display3",
"Seg14Display4", "Seg14Display5", "Seg14Display6",
"Seg16Display1", "Seg16Display2", "Seg16Display3",
"Seg16Display4", "Seg16Display5", "Seg16Display6",
"SightGlassLevel", "SlideSwitch", "SphericalTankLevel",
"StackLight", "TankLevelAlarms", "TemperatureGauge",
"ToggleSwitch", "ToggleSwitchIlluminated", "VerticalTankLevel",
"VuMeter",
))
# C member defaults (tools/gen_phase4_props.py report) used as draw
# fallbacks, so a fresh widget shows its demo state.
_VALUE_DEFAULT = {
"AnalogGauge": 62.0, "PressureGauge": 180.0,
"TemperatureGauge": 85.0, "VuMeter": -6.0, "BarMeter": 55.0,
"FlowMeter": 40.0, "Manometer": 12.0, "DigitalReadout": 123.4,
"NeedleEdgewise": 76.28, "NeedleKnifeEdge": 76.28,
"NeedleTapered": 76.28, "NeedleVu": -2.4556,
"LedDigits1": 6.8652, "LedDigits2": 7.55172,
"LedDigits3": 76.20372, "LedDigits4": 762.72372,
"LedDigits5": 7627.92372, "LedDigits6": 76279.92372,
}
_RANGE_DEFAULT = {
"AnalogGauge": (0.0, 100.0), "PressureGauge": (0.0, 300.0),
"TemperatureGauge": (-20.0, 200.0), "VuMeter": (-20.0, 3.0),
"BarMeter": (0.0, 100.0), "FlowMeter": (0.0, 100.0),
"Manometer": (-50.0, 50.0), "DigitalReadout": (0.0, 999.9),
"NeedleEdgewise": (0.0, 100.0), "NeedleKnifeEdge": (0.0, 100.0),
"NeedleTapered": (0.0, 100.0), "NeedleVu": (-20.0, 3.0),
}
_LEVEL_DEFAULT = {
"VerticalTankLevel": 76.28, "HorizontalTankLevel": 13.78,
"SphericalTankLevel": 14.63, "SightGlassLevel": 14.58,
"LevelColumnGauge": 58.45, "LevelTransmitter": 30.47,
"OpenChannelLevel": 87.83, "TankLevelAlarms": 56.24,
}
def _color(widget, 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):
"""Gauge/digit value with the C demo default."""
default = _VALUE_DEFAULT.get(widget.pkind, 0.0)
return _prop_float(widget, "value", default)
def _range(widget):
"""(min, max) with the C demo default."""
lo, hi = _RANGE_DEFAULT.get(widget.pkind, (0.0, 100.0))
return (_prop_float(widget, "minimum", lo),
_prop_float(widget, "maximum", hi))
def _frac(widget):
"""Value as a 0..1 fraction of its range."""
lo, hi = _range(widget)
value = _value(widget)
if hi <= lo:
return 0.5
return max(0.0, min(1.0, (value - lo) / (hi - lo)))
def _level(widget):
"""Tank level 0..100 with the C demo default."""
default = _LEVEL_DEFAULT.get(widget.pkind, 50.0)
return max(0.0, min(100.0, _prop_float(widget, "level", default)))
def _alarms(widget):
"""(hi-hi, hi, lo, lo-lo) alarm bands (C defaults 95/80/20/5)."""
return (_prop_float(widget, "alarm-hi-hi", 95.0),
_prop_float(widget, "alarm-hi", 80.0),
_prop_float(widget, "alarm-lo", 20.0),
_prop_float(widget, "alarm-lo-lo", 5.0))
def _on(widget):
return _prop_bool(widget, "on", False)
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()
_rgb(cr, (150 / 255, 150 / 255, 150 / 255))
cr.arc(x, y, r, 0, 2 * math.pi)
cr.fill_preserve()
_rgb(cr, (40 / 255, 40 / 255, 40 / 255))
cr.set_line_width(1)
cr.stroke()
cr.move_to(x - r + 1, y)
cr.line_to(x + r - 1, y)
cr.stroke()
cr.restore()
def _panel_screws(cr, widget, margin=10):
w, h = widget.width, widget.height
for x, y in ((margin, margin), (w - margin, margin),
(margin, h - margin), (w - margin, h - margin)):
_screw(cr, x, y)
# --- gauges ------------------------------------------------------------------
def _dial_angle(frac):
"""Needle angle (radians, Cairo coords): 270-degree sweep from
lower-left (0.75 pi) through top (1.5 pi) to lower-right."""
return (0.75 + 1.5 * frac) * math.pi
def _draw_dial(cr, widget, red_from=None, unit="", fmt="%.0f"):
"""Round dial gauge: face, ticks, numbers, red zone, needle,
hub, value readout. *red_from* is the fraction where the red
zone starts (None = no red zone)."""
w, h = widget.width, widget.height
face = _color(widget, "face-color", (245 / 255, 245 / 255, 240 / 255))
ink = _color(widget, "ink-color", (40 / 255, 40 / 255, 40 / 255))
red = _color(widget, "red-color", (200 / 255, 30 / 255, 30 / 255))
lo, hi = _range(widget)
frac = _frac(widget)
cx, cy = w / 2, h / 2 + 4
r = min(w, h) / 2 - 10
if r < 4:
return
cr.save()
_rgb(cr, face)
cr.arc(cx, cy, r, 0, 2 * math.pi)
cr.fill_preserve()
_rgb(cr, ink)
cr.set_line_width(2)
cr.stroke()
if red_from is not None:
_rgb(cr, red)
cr.set_line_width(4)
cr.arc(cx, cy, r - 6, _dial_angle(red_from),
_dial_angle(1.0))
cr.stroke()
# 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)
major = i % 5 == 0
r0 = r - (12 if major else 7)
cr.save()
_rgb(cr, ink)
cr.set_line_width(2 if major else 1)
cr.move_to(cx + r0 * math.cos(angle), cy + r0 * math.sin(angle))
cr.line_to(cx + (r - 2) * math.cos(angle),
cy + (r - 2) * math.sin(angle))
cr.stroke()
cr.restore()
if major:
value = lo + f * (hi - lo)
label = fmt % value
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)
cr.save()
_rgb(cr, ink)
cr.set_line_width(max(1, width))
cr.set_line_cap(1)
cr.move_to(cx, cy)
cr.line_to(cx + (r - 16) * math.cos(angle),
cy + (r - 16) * math.sin(angle))
cr.stroke()
_rgb(cr, ink)
cr.arc(cx, cy, 5, 0, 2 * math.pi)
cr.fill()
cr.restore()
label = (fmt % _value(widget)) + (" " + unit if unit else "")
_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:
# 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()
def _draw_analog_gauge(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
_draw_dial(cr, widget)
def _draw_pressure_gauge(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
_draw_dial(cr, widget, red_from=0.8, unit="psi")
def _draw_temperature_gauge(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
_draw_dial(cr, widget, red_from=170.0 / 220.0, unit="°C")
def _draw_vu_meter(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
_draw_dial(cr, widget, red_from=20.0 / 23.0, unit="VU", fmt="%.0f")
def _draw_bar_meter(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
face = _color(widget, "face-color", (245 / 255, 245 / 255, 240 / 255))
ink = _color(widget, "ink-color", (40 / 255, 40 / 255, 40 / 255))
green = _color(widget, "green-color", (0.0, 150 / 255, 0.0))
amber = _color(widget, "amber-color", (255 / 255, 176 / 255, 0.0))
red = _color(widget, "red-color", (200 / 255, 30 / 255, 30 / 255))
frac = _frac(widget)
horizontal = _prop_bool(widget, "horizontal", False)
w, h = widget.width, widget.height
x0, y0 = 30, 10
bw, bh = w - 44, h - 34
if bw <= 0 or bh <= 0:
return
_box(cr, x0, y0, bw, bh, face, ink)
colour = green if frac < 0.6 else amber if frac < 0.8 else red
marker_w = _prop_int(widget, "marker-line-width", 3)
if horizontal:
fill_w = max(0, bw * frac)
_rgb(cr, colour)
cr.rectangle(x0, y0, fill_w, bh)
cr.fill()
cr.save()
_rgb(cr, ink)
cr.set_line_width(marker_w)
cr.move_to(x0 + fill_w, y0)
cr.line_to(x0 + fill_w, y0 + bh)
cr.stroke()
cr.restore()
else:
fill_h = max(0, bh * frac)
_rgb(cr, colour)
cr.rectangle(x0, y0 + bh - fill_h, bw, fill_h)
cr.fill()
cr.save()
_rgb(cr, ink)
cr.set_line_width(marker_w)
cr.move_to(x0, y0 + bh - fill_h)
cr.line_to(x0 + bw, y0 + bh - fill_h)
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=scale_size, bold=True, rgb=ink, align="center",
max_width=36)
else:
# 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)
def _draw_flow_meter(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
face = _color(widget, "face-color", (245 / 255, 245 / 255, 240 / 255))
ink = _color(widget, "ink-color", (40 / 255, 40 / 255, 40 / 255))
red = _color(widget, "red-color", (200 / 255, 30 / 255, 30 / 255))
frac = _frac(widget)
w, h = widget.width, widget.height
cx = w / 2
top_w, bot_w = 26, 52
top_y, bot_y = 12, h - 30
if bot_y - top_y < 10:
return
# Tapered tube (narrow at the top, wide at the bottom).
cr.save()
_rgb(cr, face)
cr.move_to(cx - top_w / 2, top_y)
cr.line_to(cx + top_w / 2, top_y)
cr.line_to(cx + bot_w / 2, bot_y)
cr.line_to(cx - bot_w / 2, bot_y)
cr.close_path()
cr.fill_preserve()
_rgb(cr, ink)
cr.set_line_width(1.5)
cr.stroke()
cr.restore()
# Float rides at the flow level.
fy = bot_y - frac * (bot_y - top_y)
fw = top_w + (bot_w - top_w) * (1 - frac)
cr.save()
_rgb(cr, red)
cr.arc(cx, fy, max(3, fw / 2 - 3), 0, 2 * math.pi)
cr.fill_preserve()
_rgb(cr, ink)
cr.set_line_width(1)
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=scale_size, bold=True,
rgb=ink, align="right", max_width=44)
_wtext(cr, widget, "%.0f L/min" % _value(widget), cx, h - 8,
size=_fs(0.030, h), rgb=ink, align="center", bold=True,
max_width=w - 8)
def _draw_manometer(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
face = _color(widget, "face-color", (245 / 255, 245 / 255, 240 / 255))
ink = _color(widget, "ink-color", (40 / 255, 40 / 255, 40 / 255))
blue = _color(widget, "blue-color", (30 / 255, 120 / 255, 200 / 255))
lo, hi = _range(widget)
value = _value(widget)
frac = (value - lo) / (hi - lo) if hi > lo else 0.5
frac = max(-1.0, min(1.0, frac))
w, h = widget.width, widget.height
mid_y = h / 2
amp = (h - 40) / 2 * 0.8
left_x, right_x = w * 0.3, w * 0.7
tube_w = 16
top = 14
bot = h - 26
if bot - top < 10:
return
cr.save()
_rgb(cr, face)
cr.rectangle(left_x - tube_w / 2, top, tube_w, bot - top)
cr.rectangle(right_x - tube_w / 2, top, tube_w, bot - top)
cr.rectangle(left_x - tube_w / 2, bot - tube_w, right_x - left_x
+ tube_w, tube_w)
cr.fill_preserve()
_rgb(cr, ink)
cr.set_line_width(1.5)
cr.stroke()
cr.restore()
# Liquid: levels move apart with differential pressure.
left_y = mid_y - frac * amp
right_y = mid_y + frac * amp
cr.save()
_rgb(cr, blue)
cr.rectangle(left_x - tube_w / 2 + 1, left_y, tube_w - 2,
bot - left_y)
cr.rectangle(right_x - tube_w / 2 + 1, right_y, tube_w - 2,
bot - right_y)
cr.rectangle(left_x - tube_w / 2 + 1, bot - tube_w + 1,
right_x - left_x + tube_w - 2, tube_w - 2)
cr.fill()
cr.restore()
for i in range(5):
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=_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)
# --- needles -----------------------------------------------------------------
def _draw_needle_tapered(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
face = _color(widget, "face-color", (250 / 255, 246 / 255, 230 / 255))
ink = _color(widget, "ink-color", (40 / 255, 40 / 255, 40 / 255))
needle = _color(widget, "needle-color", (30 / 255, 30 / 255, 30 / 255))
red = _color(widget, "red-color", (200 / 255, 30 / 255, 30 / 255))
w, h = widget.width, widget.height
cx, cy = w / 2, h * 0.62
r = min(w, h) * 0.36
if r < 4:
return
cr.save()
_rgb(cr, face)
cr.arc(cx, cy, r, 0, 2 * math.pi)
cr.fill_preserve()
_rgb(cr, ink)
cr.set_line_width(2)
cr.stroke()
_rgb(cr, red)
cr.set_line_width(3)
cr.arc(cx, cy, r - 5, _dial_angle(0.8), _dial_angle(1.0))
cr.stroke()
frac = _frac(widget)
angle = _dial_angle(frac)
# Tapered needle: a triangle from the hub to the tip.
tip_x, tip_y = cx + (r - 8) * math.cos(angle), \
cy + (r - 8) * math.sin(angle)
perp = angle + math.pi / 2
base = 5
cr.move_to(tip_x, tip_y)
cr.line_to(cx + base * math.cos(perp), cy + base * math.sin(perp))
cr.line_to(cx - base * math.cos(perp), cy - base * math.sin(perp))
cr.close_path()
_rgb(cr, needle)
cr.fill()
_rgb(cr, ink)
cr.arc(cx, cy, 4, 0, 2 * math.pi)
cr.fill()
cr.restore()
# 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)
def _draw_needle_knife(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
face = _color(widget, "face-color", (252 / 255, 252 / 255, 252 / 255))
ink = _color(widget, "ink-color", (40 / 255, 40 / 255, 40 / 255))
needle = _color(widget, "needle-color", (15 / 255, 15 / 255, 15 / 255))
mirror = _color(widget, "mirror-color", (200 / 255, 200 / 255, 200 / 255))
red = _color(widget, "red-color", (200 / 255, 30 / 255, 30 / 255))
w, h = widget.width, widget.height
x0, y0 = 12, 12
bw, bh = w - 24, h - 40
if bw <= 0 or bh <= 0:
return
_box(cr, x0, y0, bw, bh, face, ink)
# Mirror strip under the scale arc.
_rgb(cr, mirror)
cr.rectangle(x0 + 6, y0 + bh * 0.42, bw - 12, 8)
cr.fill()
frac = _frac(widget)
# Knife-edge needle: a thin line pivoting at the bottom centre,
# sweeping from upper-left (frac 0, 1.25 pi) to upper-right
# (frac 1, 1.75 pi).
pivot_x, pivot_y = x0 + bw / 2, y0 + bh
angle = math.pi * (1.25 + 0.5 * frac)
tip_x = pivot_x + bh * 0.85 * math.cos(angle)
tip_y = pivot_y + bh * 0.85 * math.sin(angle)
cr.save()
_rgb(cr, red)
cr.set_line_width(2)
cr.arc(pivot_x, pivot_y, bh * 0.8, math.pi * 1.65, math.pi * 1.75)
cr.stroke()
_rgb(cr, needle)
cr.set_line_width(2)
cr.move_to(pivot_x, pivot_y)
cr.line_to(tip_x, tip_y)
cr.stroke()
_rgb(cr, ink)
cr.arc(pivot_x, pivot_y, 4, 0, 2 * math.pi)
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 + 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)
def _draw_needle_edgewise(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
face = _color(widget, "face-color", (250 / 255, 250 / 255, 248 / 255))
ink = _color(widget, "ink-color", (40 / 255, 40 / 255, 40 / 255))
needle = _color(widget, "needle-color", (15 / 255, 15 / 255, 15 / 255))
red = _color(widget, "red-color", (200 / 255, 30 / 255, 30 / 255))
tick = _color(widget, "tick-color", (20 / 255, 20 / 255, 20 / 255))
w, h = widget.width, widget.height
x0, y0 = 12, 12
bw, bh = w - 24, h - 40
if bw <= 0 or bh <= 0:
return
_box(cr, x0, y0, bw, bh, face, ink)
frac = _frac(widget)
# 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()
_rgb(cr, red)
cr.set_line_width(3)
cr.move_to(x0 + bw * 0.85, y0 + 8)
cr.line_to(x0 + bw - 4, y0 + 8)
cr.stroke()
_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)
cr.move_to(x, y0 + 6)
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 + 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)
tip_x = x0 + 6 + frac * (bw - 12)
cr.move_to(pivot_x, pivot_y)
cr.line_to(tip_x, y0 + 8)
cr.stroke()
_rgb(cr, ink)
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=_fs(0.030, h),
rgb=ink, align="center", bold=True, max_width=w - 8)
def _draw_needle_vu(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
face = _color(widget, "face-color", (248 / 255, 238 / 255, 205 / 255))
ink = _color(widget, "ink-color", (40 / 255, 40 / 255, 40 / 255))
needle = _color(widget, "needle-color", (15 / 255, 15 / 255, 15 / 255))
red = _color(widget, "red-color", (200 / 255, 30 / 255, 30 / 255))
w, h = widget.width, widget.height
x0, y0 = 12, 10
bw, bh = w - 24, h - 36
if bw <= 0 or bh <= 0:
return
_box(cr, x0, y0, bw, bh, face, ink)
frac = _frac(widget)
pivot_x, pivot_y = x0 + bw / 2, y0 + bh + 4
cr.save()
_rgb(cr, red)
cr.set_line_width(2)
cr.arc(pivot_x, pivot_y, bh * 0.75, math.pi * 1.6, math.pi * 1.75)
cr.stroke()
_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)
r0 = bh * 0.72
cr.move_to(pivot_x + r0 * math.cos(angle),
pivot_y + r0 * math.sin(angle))
cr.line_to(pivot_x + (r0 + (8 if i % 5 == 0 else 4))
* math.cos(angle),
pivot_y + (r0 + (8 if i % 5 == 0 else 4))
* math.sin(angle))
if i % 5 == 0:
tx = pivot_x + (r0 + 16) * math.cos(angle)
ty = pivot_y + (r0 + 16) * math.sin(angle)
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)
cr.set_line_width(2)
cr.move_to(pivot_x, pivot_y)
cr.line_to(pivot_x + bh * 0.8 * math.cos(angle),
pivot_y + bh * 0.8 * math.sin(angle))
cr.stroke()
_rgb(cr, ink)
cr.arc(pivot_x, pivot_y, 4, 0, 2 * math.pi)
cr.fill()
cr.restore()
# "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)
# --- tanks ---------------------------------------------------------------------
def _tank_colours(widget):
return {
"fill": _color(widget, "fill-color",
(40 / 255, 120 / 255, 200 / 255)),
"amber": _color(widget, "amber-color",
(220 / 255, 150 / 255, 0.0)),
"red": _color(widget, "red-color",
(200 / 255, 30 / 255, 30 / 255)),
"ink": _color(widget, "ink-color", (60 / 255, 60 / 255, 60 / 255)),
"pale": _color(widget, "pale-color",
(235 / 255, 242 / 255, 248 / 255)),
"white": _color(widget, "white-color", (1.0, 1.0, 1.0)),
"grid": _color(widget, "grid-color",
(210 / 255, 210 / 255, 210 / 255)),
}
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)
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)
cr.set_line_width(2)
if vertical:
cr.move_to(x, top)
cr.line_to(x, bottom)
else:
cr.move_to(x, y)
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=_fs(0.030, widget.height),
bold=True,
rgb=(0.12, 0.12, 0.12), align=align,
max_width=widget.width - 16)
def _draw_vertical_tank(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
cols = _tank_colours(widget)
level = _level(widget)
w, h = widget.width, widget.height
x0, y0 = 24, 16
# 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"])
fill_h = bh * level / 100.0
cr.save()
_rgb(cr, cols["fill"])
cr.rectangle(x0 + 1, y0 + bh - fill_h, bw - 2, fill_h)
cr.fill()
_rgb(cr, cols["grid"])
cr.set_line_width(0.5)
for i in range(1, 10):
y = y0 + bh * i / 10.0
cr.move_to(x0, y)
cr.line_to(x0 + bw, y)
cr.stroke()
cr.restore()
_alarm_lines(cr, widget, x0 + bw + 2, y0, y0 + bh)
_tank_readout(cr, widget, level, x0 + bw / 2, h - 6, align="center")
def _draw_horizontal_tank(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
cols = _tank_colours(widget)
level = _level(widget)
w, h = widget.width, widget.height
x0, y0 = 16, 22
bw, bh = w - 32, h - 48
if bw <= 0 or bh <= 0:
return
_rounded_box(cr, x0, y0, bw, bh, cols["pale"], cols["ink"],
radius=bh / 2)
fill_w = bw * level / 100.0
if fill_w > 0:
cr.save()
_rounded_box(cr, x0 + 1, y0 + 1, max(2, fill_w - 2), bh - 2,
cols["fill"], cols["fill"], radius=bh / 2 - 1)
cr.restore()
hi_hi, hi, lo, lo_lo = _alarms(widget)
for mark, colour in ((hi_hi, cols["red"]), (hi, cols["amber"]),
(lo, cols["amber"]), (lo_lo, cols["red"])):
x = x0 + bw * mark / 100.0
cr.save()
_rgb(cr, colour)
cr.set_line_width(2)
cr.move_to(x, y0)
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")
def _draw_spherical_tank(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
cols = _tank_colours(widget)
level = _level(widget)
w, h = widget.width, widget.height
cx, cy = w / 2, h / 2 - 4
r = min(w, h) / 2 - 14
if r < 4:
return
# Legs.
cr.save()
_rgb(cr, cols["ink"])
cr.set_line_width(2)
cr.move_to(cx - r * 0.6, cy + r * 0.7)
cr.line_to(cx - r * 0.8, h - 8)
cr.move_to(cx + r * 0.6, cy + r * 0.7)
cr.line_to(cx + r * 0.8, h - 8)
cr.stroke()
cr.restore()
cr.save()
_rgb(cr, cols["pale"])
cr.arc(cx, cy, r, 0, 2 * math.pi)
cr.fill_preserve()
cr.clip()
fill_h = 2 * r * level / 100.0
_rgb(cr, cols["fill"])
cr.rectangle(cx - r, cy + r - fill_h, 2 * r, fill_h)
cr.fill()
cr.restore()
cr.save()
_rgb(cr, cols["ink"])
cr.set_line_width(1.5)
cr.arc(cx, cy, r, 0, 2 * math.pi)
cr.stroke()
cr.restore()
_alarm_lines(cr, widget, cx + r + 2, cy - r, cy + r)
_tank_readout(cr, widget, level, cx, h - 4, align="center")
def _draw_sight_glass(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
cols = _tank_colours(widget)
steel = _color(widget, "steel-color",
(150 / 255, 150 / 255, 150 / 255))
level = _level(widget)
w, h = widget.width, widget.height
cx = w / 2
# 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:
return
# Top/bottom pipes.
_box(cr, cx - 4, 6, 8, 14, steel, cols["ink"])
_box(cr, cx - 4, bot, 8, 14, steel, cols["ink"])
_box(cr, x0, top, tube_w, bot - top, cols["white"], steel)
fill_h = (bot - top) * level / 100.0
cr.save()
_rgb(cr, cols["fill"])
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()
_rgb(cr, cols["ink"])
cr.set_line_width(1 if i % 5 else 2)
cr.move_to(x0 - (6 if i % 5 else 10), y)
cr.line_to(x0, y)
cr.stroke()
cr.restore()
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")
def _draw_level_column(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
cols = _tank_colours(widget)
level = _level(widget)
w, h = widget.width, widget.height
cx = w / 2 - 10
col_w = 18
x0 = cx - col_w / 2
top, bot = 16, h - 24
if bot - top < 10:
return
_box(cr, x0, top, col_w, bot - top, cols["pale"], cols["ink"])
fill_h = (bot - top) * level / 100.0
cr.save()
_rgb(cr, cols["fill"])
cr.rectangle(x0 + 1, bot - fill_h, col_w - 2, fill_h)
cr.fill()
cr.restore()
# Float marker: a red bar at the level.
float_y = bot - fill_h
cr.save()
_rgb(cr, cols["red"])
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 + 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")
def _draw_level_transmitter(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
cols = _tank_colours(widget)
level = _level(widget)
ma = 4.0 + 16.0 * level / 100.0
w, h = widget.width, widget.height
x0, y0 = 16, 16
bw, bh = 26, h - 48
if bw <= 0 or bh <= 0:
return
_box(cr, x0, y0, bw, bh, cols["pale"], cols["ink"])
fill_h = bh * level / 100.0
cr.save()
_rgb(cr, cols["fill"])
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)
# 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):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
cols = _tank_colours(widget)
surface = _color(widget, "surface-color",
(20 / 255, 80 / 255, 160 / 255))
level = _level(widget)
w, h = widget.width, widget.height
# 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
cr.save()
_rgb(cr, cols["fill"], 0.75)
cr.rectangle(x0, y0 + bh - fill_h, bw, fill_h)
cr.fill()
_rgb(cr, surface)
cr.set_line_width(2)
cr.move_to(x0, y0 + bh - fill_h)
cr.line_to(x0 + bw, y0 + bh - fill_h)
cr.stroke()
_rgb(cr, cols["ink"])
cr.set_line_width(1.5)
cr.move_to(x0, y0)
cr.line_to(x0, y0 + bh)
cr.line_to(x0 + bw, y0 + bh)
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=scale_size, bold=True, rgb=cols["ink"],
max_width=40)
_tank_readout(cr, widget, level, x0 + bw / 2, h - 6, align="center")
def _draw_tank_alarms(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
cols = _tank_colours(widget)
level = _level(widget)
hi_hi, hi, lo, lo_lo = _alarms(widget)
w, h = widget.width, widget.height
x0, y0 = 16, 16
bw, bh = w - 84, h - 36
if bw <= 0 or bh <= 0:
return
_box(cr, x0, y0, bw, bh, cols["pale"], cols["ink"])
fill_h = bh * level / 100.0
cr.save()
_rgb(cr, cols["fill"])
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, 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 + 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 + 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")
# --- lamps / LEDs --------------------------------------------------------------
def _lens_rgb(lens, on, brightness):
"""Lens colour: dim tint when off, brighter with brightness."""
dim = tuple(0.3 * c + 0.7 * (40 / 255) for c in lens)
if not on:
return dim
f = brightness / 100.0
return tuple(dim[i] + (lens[i] - dim[i]) * (0.35 + 0.65 * f)
for i in range(3))
def _draw_panel_lamp(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
bezel = _color(widget, "bezel-color", (70 / 255, 70 / 255, 70 / 255))
ring = _color(widget, "ring-color", (160 / 255, 160 / 255, 160 / 255))
lens = _color(widget, "lens-color", (220 / 255, 30 / 255, 30 / 255))
on = _on(widget)
brightness = _brightness(widget)
w, h = widget.width, widget.height
# 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()
_rgb(cr, bezel)
cr.arc(cx, cy, r, 0, 2 * math.pi)
cr.fill()
_rgb(cr, ring)
cr.arc(cx, cy, r - 3, 0, 2 * math.pi)
cr.fill()
_rgb(cr, _lens_rgb(lens, on, brightness))
cr.arc(cx, cy, r - 7, 0, 2 * math.pi)
cr.fill()
if on and brightness > 70:
_rgb(cr, (1.0, 1.0, 1.0), 0.35)
cr.arc(cx, cy, r - 2, 0, 2 * math.pi)
cr.set_line_width(2)
cr.stroke()
_rgb(cr, (1.0, 1.0, 1.0), 0.5)
cr.arc(cx - r * 0.3, cy - r * 0.35, r * 0.18, 0, 2 * math.pi)
cr.fill()
cr.restore()
# 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)
def _draw_led(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
dark = _color(widget, "dark-color", (40 / 255, 40 / 255, 40 / 255))
lens = _color(widget, "lens-color", (220 / 255, 30 / 255, 30 / 255))
lead = _color(widget, "lead-color", (120 / 255, 120 / 255, 120 / 255))
on = _on(widget)
brightness = _brightness(widget)
w, h = widget.width, widget.height
cx = w / 2
# 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
cr.save()
_rgb(cr, _lens_rgb(lens, on, brightness))
cr.arc(cx, by + block_h / 2, max(r, 3), 0, 2 * math.pi)
cr.fill()
_rgb(cr, (1.0, 1.0, 1.0), 0.5)
cr.arc(cx - r * 0.3, by + block_h / 2 - r * 0.3, max(r * 0.2, 1),
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, lead_end)
cr.move_to(cx + 10, by + block_h)
cr.line_to(cx + 10, lead_end)
cr.stroke()
cr.restore()
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)
def _draw_rgb_led(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
dark = _color(widget, "dark-color", (40 / 255, 40 / 255, 40 / 255))
red_c = _color(widget, "red-channel-color",
(220 / 255, 30 / 255, 30 / 255))
green_c = _color(widget, "green-channel-color",
(30 / 255, 200 / 255, 60 / 255))
blue_c = _color(widget, "blue-channel-color",
(40 / 255, 120 / 255, 230 / 255))
outline = _color(widget, "swatch-outline-color",
(60 / 255, 60 / 255, 60 / 255))
brightness = _brightness(widget)
all_on = _prop_bool(widget, "all-on", False)
red_on = all_on or _prop_bool(widget, "red-on", False)
green_on = all_on or _prop_bool(widget, "green-on", False)
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, 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 = (
red_c[0] if red_on else 0.12,
green_c[1] if green_on else 0.12,
blue_c[2] if blue_on else 0.12,
)
r = min(block_w, block_h) / 2 - 6
cr.save()
_rgb(cr, _lens_rgb(combined, red_on or green_on or blue_on,
brightness))
cr.arc(cx, by + block_h / 2, max(r, 3), 0, 2 * math.pi)
cr.fill()
cr.restore()
# 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, 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
def _draw_stack_light(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
dark = _color(widget, "dark-color", (40 / 255, 40 / 255, 40 / 255))
red = _color(widget, "red-color", (220 / 255, 30 / 255, 30 / 255))
amber = _color(widget, "amber-color", (230 / 255, 160 / 255, 20 / 255))
green = _color(widget, "green-color", (30 / 255, 200 / 255, 60 / 255))
outline = _color(widget, "tier-outline-color",
(60 / 255, 60 / 255, 60 / 255))
all_on = _prop_bool(widget, "all-on", False)
w, h = widget.width, widget.height
cx = w / 2
pole_h = 18
# 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
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)
_box(cr, cx - tier_w / 2 - 6, y + pole_h, tier_w + 12, 10, dark,
dark)
def _draw_beacon(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
dark = _color(widget, "dark-color", (40 / 255, 40 / 255, 40 / 255))
beacon = _color(widget, "beacon-color",
(230 / 255, 160 / 255, 20 / 255))
on = _on(widget)
phase = _prop_bool(widget, "phase", True)
brightness = _brightness(widget)
lit = on and phase
w, h = widget.width, widget.height
cx = w / 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 - 6
if lit:
cr.save()
_rgb(cr, beacon, 0.25)
cr.move_to(cx, cy)
cr.line_to(4, cy - dome_r * 0.4)
cr.line_to(4, cy + dome_r * 0.4)
cr.close_path()
cr.fill()
cr.move_to(cx, cy)
cr.line_to(w - 4, cy - dome_r * 0.4)
cr.line_to(w - 4, cy + dome_r * 0.4)
cr.close_path()
cr.fill()
cr.restore()
cr.save()
_rgb(cr, _lens_rgb(beacon, lit, brightness))
cr.arc(cx, cy, dome_r, math.pi, 2 * math.pi)
cr.close_path()
cr.fill_preserve()
_rgb(cr, dark)
cr.set_line_width(2)
cr.stroke()
cr.restore()
# 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):
face = _color(widget, "face-color", (200 / 255, 200 / 255, 200 / 255))
bezel = _color(widget, "bezel-color", (70 / 255, 70 / 255, 70 / 255))
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)
# 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)
# --- segment displays ----------------------------------------------------------
# Segment maps are verbatim from the C widgets
# (InstSeg14Display5.h / InstSeg16Display5.h segment_map(),
# InstDigitalReadout.h draw_digit seg[10][7]). C ids: a top,
# b upper-right, c lower-right, d bottom, e lower-left,
# f upper-left, g1/g2 middle halves, i upper centre vertical,
# l lower centre vertical, h/j/k/m diagonals (top-left, top-right,
# bottom-left, bottom-right). 16-segment splits a -> a1/a2 and
# d -> d1/d2; its M ("b c e f h i j") and W ("b c e f k l m") are
# the clean 16-seg forms. (An earlier draft used different ids for
# the centre verticals/diagonals, which made I/K/M/V/W wrong and
# drew the diagonals as full-length round-capped strokes -- a dark
# X blob over every glyph. This block mirrors C exactly.)
_SEVEN_MAP = {
"0": "abcdef", "1": "bc", "2": "abdeg", "3": "abcdg",
"4": "bcfg", "5": "acdfg", "6": "acdefg", "7": "abc",
"8": "abcdefg", "9": "abcdfg", "-": "g", "_": "d", " ": "",
}
_FOURTEEN_MAP = {
" ": "",
'"': "h j",
"'": "j",
"+": "g1 g2 i l",
"-": "g1 g2",
"/": "j k",
"0": "a b c d e f",
"1": "b c",
"2": "a b d e g1 g2",
"3": "a b c d g1 g2",
"4": "b c f g1 g2",
"5": "a c d f g1 g2",
"6": "a c d e f g1 g2",
"7": "a b c",
"8": "a b c d e f g1 g2",
"9": "a b c d f g1 g2",
"=": "d g1 g2",
"A": "a b c e f g1 g2",
"B": "a b c d g1 g2 i l",
"C": "a d e f",
"D": "a b c d i l",
"E": "a d e f g1 g2",
"F": "a e f g1 g2",
"G": "a c d e f g1 g2",
"H": "b c e f g1 g2",
"I": "i l",
"J": "b c d e",
"K": "e f g1 j k",
"L": "d e f",
"M": "b c e f h j",
"N": "b c e f h m",
"O": "a b c d e f",
"P": "a b e f g1 g2",
"Q": "a b c d e f m",
"R": "a b e f g1 g2 m",
"S": "a c d f g1 g2",
"T": "a i l",
"U": "b c d e",
"V": "c e j k",
"W": "b c e f k m",
"X": "h j k m",
"Y": "b c f g1 g2 l",
"Z": "a d j k",
"_": "d",
}
_SIXTEEN_MAP = dict(_FOURTEEN_MAP)
_SIXTEEN_MAP.update({
"0": "a1 a2 b c d1 d2 e f",
"2": "a1 a2 b d1 d2 e g1 g2",
"3": "a1 a2 b c d1 d2 g1 g2",
"5": "a1 a2 c d1 d2 f g1 g2",
"6": "a1 a2 c d1 d2 e f g1 g2",
"7": "a1 a2 b c",
"8": "a1 a2 b c d1 d2 e f g1 g2",
"9": "a1 a2 b c d1 d2 f g1 g2",
"=": "d1 d2 g1 g2",
"A": "a1 a2 b c e f g1 g2",
"B": "a1 a2 b c d1 d2 g1 g2 i l",
"C": "a1 a2 d1 d2 e f",
"D": "a1 a2 b c d1 d2 i l",
"E": "a1 a2 d1 d2 e f g1 g2",
"F": "a1 a2 e f g1 g2",
"G": "a1 a2 c d1 d2 e f g1 g2",
"J": "b c d1 d2 e",
"L": "d1 d2 e f",
"M": "b c e f h i j",
"O": "a1 a2 b c d1 d2 e f",
"P": "a1 a2 b e f g1 g2",
"Q": "a1 a2 b c d1 d2 e f m",
"R": "a1 a2 b e f g1 g2 m",
"S": "a1 a2 c d1 d2 f g1 g2",
"T": "a1 a2 i l",
"U": "b c d1 d2 e",
"W": "b c e f k l m",
"Z": "a1 a2 d1 d2 j k",
"_": "d1 d2",
})
def _seg_thickness(w):
"""C: t = max(2, cell_w / 6) (Seg14 draw); the 7-seg readout
uses a fixed t = 8 at its own cell size, the same scale."""
return max(2.0, w / 6.0)
def _seg_rects(x, y, w, h, segs):
"""Segment name -> rect, C draw_segment() geometry verbatim
(InstSeg14Display5.h; DigitalReadout.h for the 7-seg set).
Diagonals are returned separately as endpoint pairs: C draws
them as polygons (draw_diag), not stroked lines, so they stop
short of the centre instead of bulging into a blob."""
t = _seg_thickness(w)
midx = x + w / 2
midy = y + h / 2
if segs == "seven":
hv = max(1.0, h / 2 - 2 * t)
return {
"a": (x + t, y, w - 2 * t, t),
"b": (x + w - t, y + t, t, hv),
"c": (x + w - t, y + h / 2 + t, t, hv),
"d": (x + t, y + h - t, w - 2 * t, t),
"e": (x, y + h / 2 + t, t, hv),
"f": (x, y + t, t, hv),
"g": (x + t, y + h / 2 - t / 2, w - 2 * t, t),
}, {}
hh = max(1.0, h / 2 - t)
hw = max(1.0, w / 2 - t)
cv = max(1.0, h / 2 - 2 * t)
rects = {
"a": (x + t, y, w - 2 * t, t),
"b": (x + w - t, y + t, t, hh),
"c": (x + w - t, midy, t, hh),
"d": (x + t, y + h - t, w - 2 * t, t),
"e": (x, midy, t, hh),
"f": (x, y + t, t, hh),
"g1": (x + t, midy - t / 2, hw, t),
"g2": (midx, midy - t / 2, hw, t),
"i": (midx - t / 2, y + t, t, cv),
"l": (midx - t / 2, midy + t, t, cv),
}
if segs == "sixteen":
rects["a1"] = (x + t, y, hw, t)
rects["a2"] = (midx, y, hw, t)
rects["d1"] = (x + t, y + h - t, hw, t)
rects["d2"] = (midx, y + h - t, hw, t)
lines = {
"h": (x + t, y + t, midx, midy - t),
"j": (x + w - t, y + t, midx, midy - t),
"k": (x + t, y + h - t, midx, midy + t),
"m": (x + w - t, y + h - t, midx, midy + t),
}
return rects, lines
def _draw_diag(cr, x0, y0, x1, y1, t):
"""C draw_diag: a t-wide parallelogram, not a stroked line."""
dx, dy = x1 - x0, y1 - y0
length = math.hypot(dx, dy)
if length < 1.0:
return
px, py = -dy / length * t / 2.0, dx / length * t / 2.0
cr.move_to(x0 + px, y0 + py)
cr.line_to(x1 + px, y1 + py)
cr.line_to(x1 - px, y1 - py)
cr.line_to(x0 - px, y0 - py)
cr.close_path()
cr.fill()
def _draw_seg_digit(cr, x, y, w, h, ch, on_rgb, off_rgb,
segs="fourteen"):
"""One 7/14/16-segment digit; off segments stay faintly visible.
Maps and geometry are verbatim from the C widgets."""
if segs == "seven":
lit = set(_SEVEN_MAP.get(ch, ""))
universe = ("a", "b", "c", "d", "e", "f", "g")
elif segs == "sixteen":
lit = set(_SIXTEEN_MAP.get(ch.upper(), "").split())
universe = ("a1", "a2", "b", "c", "d1", "d2", "e", "f",
"g1", "g2", "h", "i", "j", "k", "l", "m")
else:
lit = set(_FOURTEEN_MAP.get(ch.upper(), "").split())
universe = ("a", "b", "c", "d", "e", "f", "g1", "g2",
"h", "i", "j", "k", "l", "m")
rects, lines = _seg_rects(x, y, w, h, segs)
t = _seg_thickness(w)
for seg in universe:
cr.save()
_rgb(cr, on_rgb if seg in lit else off_rgb)
if seg in rects:
rx, ry, rw, rh = rects[seg]
cr.rectangle(rx, ry, max(1.0, rw), max(1.0, rh))
cr.fill()
else:
x0, y0, x1, y1 = lines[seg]
# 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
/ decimal_point_after). Returns (digits_str, point_after_index)
where point_after is -1 when there is no point."""
max_value = (10.0 ** digits - 1.0) / (10.0 ** dp) if dp else \
float(10 ** digits - 1)
value = max(0.0, min(max_value, value))
text = "%.*f" % (dp, value)
bare = text.replace(".", "").replace("-", "")
if len(bare) < digits:
bare = "0" * (digits - len(bare)) + bare
else:
bare = bare[-digits:]
point_after = digits - dp - 1 if dp > 0 else -1
return bare, point_after
def _draw_led_digits(cr, widget):
kind = widget.pkind
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))
# 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))
# 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
avail_w = widget.width - 2 * pad - gap * (digits - 1)
dw = avail_w / digits if digits else avail_w
dh = widget.height - 20
if dw <= 2 or dh <= 4:
return
for i, ch in enumerate(text):
x = pad + i * (dw + gap)
_draw_seg_digit(cr, x, 10, dw, dh, ch, lit, dim,
segs="seven")
if i == point_after:
cr.save()
_rgb(cr, lit)
cr.arc(x + dw + gap / 2, 10 + dh, 2.5, 0, 2 * math.pi)
cr.fill()
cr.restore()
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",
(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,
radius=6)
digits = 4
dp = 1
text, point_after = _led_digits_text(_value(widget), digits, dp)
pad = 10
gap = 6
avail_w = widget.width - 2 * pad - gap * (digits - 1)
dw = avail_w / digits
dh = widget.height - 20
if dw <= 2 or dh <= 4:
return
for i, ch in enumerate(text):
x = pad + i * (dw + gap)
_draw_seg_digit(cr, x, 10, dw, dh, ch, on, off, segs="seven")
if i == point_after:
cr.save()
_rgb(cr, on)
cr.arc(x + dw + gap / 2, 10 + dh, 2.5, 0, 2 * math.pi)
cr.fill()
cr.restore()
def _draw_seg_display(cr, widget):
kind = widget.pkind
sixteen = kind.startswith("Seg16")
digits = int(kind.replace("Seg14Display", "")
.replace("Seg16Display", ""))
bezel = _color(widget, "bezel-color", (58 / 255, 58 / 255, 62 / 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))
# 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
if widget.prop_def("value") is not None else "")
chars = []
point_after = -1
for ch in str(raw).upper():
if ch in ".:":
point_after = len(chars) - 1
continue
chars.append(ch)
if len(chars) >= digits:
break
while len(chars) < digits:
chars.append(" ")
pad = 10
gap = 5
avail_w = widget.width - 2 * pad - gap * (digits - 1)
dw = avail_w / digits if digits else avail_w
dh = widget.height - 20
if dw <= 2 or dh <= 4:
return
for i, ch in enumerate(chars):
x = pad + i * (dw + gap)
_draw_seg_digit(cr, x, 10, dw, dh, ch, lit, dim,
segs="sixteen" if sixteen else "fourteen")
if i == point_after:
cr.save()
_rgb(cr, lit)
cr.arc(x + dw + gap / 2, 10 + dh, 2.5, 0, 2 * math.pi)
cr.fill()
cr.restore()
# --- switches ------------------------------------------------------------------
def _draw_rocker(cr, widget, illuminated=False, double=False):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
bezel = _color(widget, "bezel-color", (38 / 255, 38 / 255, 42 / 255))
panel = _color(widget, "panel-color", (58 / 255, 58 / 255, 62 / 255))
rocker = _color(widget, "rocker-color",
(190 / 255, 190 / 255, 195 / 255))
green = _color(widget, "green-color", (0.0, 180 / 255, 0.0))
dimred = _color(widget, "dimred-color", (120 / 255, 30 / 255, 30 / 255))
greenlit = _color(widget, "greenlit-color",
(60 / 255, 255 / 255, 90 / 255))
w, h = widget.width, widget.height
_rounded_box(cr, 6, 6, w - 12, h - 12, panel, bezel, radius=8)
if double:
position = _prop_int(widget, "position", 0)
tilt = 8 if position > 0 else -8 if position < 0 else 0
else:
tilt = 8 if _on(widget) else -8
x0, y0 = 16, 14
rw, rh = w - 32, h - 28
if rw <= 0 or rh <= 0:
return
# Rocker quad: top edge raised when on (up is on).
cr.save()
_rgb(cr, rocker)
cr.move_to(x0, y0 - tilt if tilt > 0 else y0)
cr.line_to(x0 + rw, y0 + tilt if tilt < 0 else y0)
cr.line_to(x0 + rw, y0 + rh + (tilt if tilt > 0 else 0))
cr.line_to(x0, y0 + rh + (-tilt if tilt < 0 else 0))
cr.close_path()
cr.fill_preserve()
_rgb(cr, bezel)
cr.set_line_width(1.5)
cr.stroke()
cr.restore()
# 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)
# 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):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
bezel = _color(widget, "bezel-color", (38 / 255, 38 / 255, 42 / 255))
panel = _color(widget, "panel-color", (58 / 255, 58 / 255, 62 / 255))
plate = _color(widget, "plate-color", (210 / 255, 210 / 255, 210 / 255))
greenlit = _color(widget, "greenlit-color",
(60 / 255, 255 / 255, 90 / 255))
redlit = _color(widget, "redlit-color",
(255 / 255, 70 / 255, 60 / 255))
dimred = _color(widget, "dimred-color", (120 / 255, 30 / 255, 30 / 255))
on = _on(widget)
w, h = widget.width, widget.height
cx = w / 2
_rounded_box(cr, 6, 6, w - 12, h - 12, panel, bezel, radius=8)
_rounded_box(cr, cx - 16, 10, 32, h - 20, plate, bezel, radius=6)
pivot_x, pivot_y = cx, h / 2
lever_w = max(2, _prop_int(widget, "lever-line-width", 10))
lever_len = h * 0.32
angle = -math.pi / 2 if on else math.pi / 2
tip_x = pivot_x + lever_len * math.cos(angle)
tip_y = pivot_y + lever_len * math.sin(angle)
cr.save()
_rgb(cr, bezel)
cr.set_line_width(lever_w)
cr.set_line_cap(1)
cr.move_to(pivot_x, pivot_y)
cr.line_to(tip_x, tip_y)
cr.stroke()
_rgb(cr, (230 / 255, 230 / 255, 230 / 255))
cr.arc(tip_x, tip_y, lever_w / 2 + 2, 0, 2 * math.pi)
cr.fill()
_rgb(cr, bezel)
cr.arc(pivot_x, pivot_y, 6, 0, 2 * math.pi)
cr.fill()
cr.restore()
if illuminated:
_rgb(cr, greenlit if on else dimred)
cr.arc(cx + 22, 18, 5, 0, 2 * math.pi)
cr.fill()
else:
_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=_fs(0.027, h), bold=True,
align="center", rgb=(0.9, 0.9, 0.9), max_width=40)
def _draw_slide_switch(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
bezel = _color(widget, "bezel-color", (38 / 255, 38 / 255, 42 / 255))
panel = _color(widget, "panel-color", (58 / 255, 58 / 255, 62 / 255))
rocker = _color(widget, "rocker-color",
(190 / 255, 190 / 255, 195 / 255))
green = _color(widget, "green-color", (0.0, 180 / 255, 0.0))
on = _on(widget)
w, h = widget.width, widget.height
_rounded_box(cr, 6, 6, w - 12, h - 12, panel, bezel, radius=8)
# 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 = 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)
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)
def _draw_key_switch(cr, widget):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
bezel = _color(widget, "bezel-color", (38 / 255, 38 / 255, 42 / 255))
panel = _color(widget, "panel-color", (58 / 255, 58 / 255, 62 / 255))
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
# 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)
cr.save()
_rgb(cr, plate)
cr.arc(cx, cy, r, 0, 2 * math.pi)
cr.fill_preserve()
_rgb(cr, bezel)
cr.set_line_width(2)
cr.stroke()
# 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 + (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 + (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 + (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()
# 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):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
bezel = _color(widget, "bezel-color", (38 / 255, 38 / 255, 42 / 255))
panel = _color(widget, "panel-color", (58 / 255, 58 / 255, 62 / 255))
plate = _color(widget, "plate-color", (210 / 255, 210 / 255, 210 / 255))
positions = max(2, _prop_int(widget, "positions", 3))
position = max(0, min(positions - 1,
_prop_int(widget, "position", 0)))
w, h = widget.width, widget.height
cx, cy = w / 2, h / 2
r = min(w, h) / 2 - 14
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 + 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()
_rgb(cr, bezel)
cr.set_line_width(2)
cr.stroke()
angle = -math.pi * 0.75 + position * (math.pi * 1.5
/ (positions - 1))
_rgb(cr, bezel)
cr.set_line_width(max(2, _prop_int(widget, "pointer-line-width",
8)))
cr.set_line_cap(1)
cr.move_to(cx, cy)
cr.line_to(cx + (r - 6) * math.cos(angle),
cy + (r - 6) * math.sin(angle))
cr.stroke()
_rgb(cr, bezel)
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):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
bezel = _color(widget, "bezel-color", (38 / 255, 38 / 255, 42 / 255))
greenlit = _color(widget, "greenlit-color",
(60 / 255, 255 / 255, 90 / 255))
redlit = _color(widget, "redlit-color",
(255 / 255, 70 / 255, 60 / 255))
on = _on(widget)
w, h = widget.width, widget.height
# 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()
# 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()
_rgb(cr, bezel)
cr.set_line_width(2)
cr.stroke()
_rgb(cr, (1.0, 1.0, 1.0), 0.5)
cr.arc(cx - r * 0.3, cy - r * 0.35, r * 0.2, 0, 2 * math.pi)
cr.fill()
cr.restore()
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):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
surround = _color(widget, "surround-color",
(255 / 255, 220 / 255, 0.0))
red = _color(widget, "red-color", (200 / 255, 30 / 255, 30 / 255))
redlit = _color(widget, "redlit-color",
(255 / 255, 70 / 255, 60 / 255))
on = _on(widget)
w, h = widget.width, widget.height
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 - 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)
cr.fill()
_rgb(cr, redlit if on else red)
cr.arc(cx, cy - (2 if on else 6), r * 0.8, 0, 2 * math.pi)
cr.fill_preserve()
_rgb(cr, (120 / 255, 20 / 255, 20 / 255))
cr.set_line_width(2)
cr.stroke()
_rgb(cr, (1.0, 1.0, 1.0), 0.4)
cr.arc(cx - r * 0.25, cy - r * 0.35, r * 0.18, 0, 2 * math.pi)
cr.fill()
cr.restore()
# 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):
_bg(cr, widget, (1.0, 1.0, 1.0), stroke=(0.55, 0.55, 0.55))
bezel = _color(widget, "bezel-color", (38 / 255, 38 / 255, 42 / 255))
panel = _color(widget, "panel-color", (58 / 255, 58 / 255, 62 / 255))
plate = _color(widget, "plate-color", (210 / 255, 210 / 255, 210 / 255))
green = _color(widget, "green-color", (0.0, 180 / 255, 0.0))
red = _color(widget, "red-color", (200 / 255, 30 / 255, 30 / 255))
w, h = widget.width, widget.height
_rounded_box(cr, 6, 6, w - 12, h - 12, panel, bezel, radius=8)
bw, bh = min(64, w - 40), h - 36
bx, by = (w - bw) / 2, 14
if bw <= 0 or bh <= 0:
return
_rounded_box(cr, bx, by, bw, bh, plate, bezel, radius=6)
lever_w = max(4, _prop_int(widget, "lever-line-width", 12))
cr.save()
_rgb(cr, bezel)
cr.set_line_width(lever_w)
cr.set_line_cap(1)
cr.move_to(bx + bw / 2, by + bh / 2 + 12)
cr.line_to(bx + bw / 2, by + 12)
cr.stroke()
cr.restore()
_rgb(cr, green)
cr.arc(bx + bw - 10, by + 12, 5, 0, 2 * math.pi)
cr.fill()
_rgb(cr, red)
cr.arc(bx + bw - 10, by + bh - 12, 5, 0, 2 * math.pi)
cr.fill()
# 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 -----------------------------------------------------------
def _draw_bezel(cr, widget):
panel = _color(widget, "panel-color", (210 / 255, 210 / 255, 205 / 255))
ink = _color(widget, "ink-color", (40 / 255, 40 / 255, 40 / 255))
_bg(cr, widget, panel, stroke=ink)
margin = 14
cr.save()
_rgb(cr, (1.0, 1.0, 1.0))
cr.rectangle(margin, margin, widget.width - 2 * margin,
widget.height - 2 * margin)
cr.fill_preserve()
_rgb(cr, ink)
cr.set_line_width(1.5)
cr.stroke()
cr.restore()
_panel_screws(cr, widget)
# 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):
panel = _color(widget, "panel-color", (210 / 255, 210 / 255, 205 / 255))
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)
# 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,
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)
def _draw_nameplate(cr, widget):
dark = _color(widget, "dark-color", (30 / 255, 30 / 255, 30 / 255))
engraved = _color(widget, "engraved-color",
(240 / 255, 220 / 255, 160 / 255))
_rounded_box(cr, 0, 0, widget.width, widget.height, dark, dark,
radius=6)
# 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)
def _draw_control_panel(cr, widget):
face = _color(widget, "face-color", (245 / 255, 245 / 255, 240 / 255))
ink = _color(widget, "ink-color", (40 / 255, 40 / 255, 40 / 255))
panel = _color(widget, "panel-color", (210 / 255, 210 / 255, 205 / 255))
amber = _color(widget, "amber-color", (255 / 255, 176 / 255, 0.0))
rows = max(1, _prop_int(widget, "grid-rows", 3))
cols = max(1, _prop_int(widget, "grid-cols", 2))
_bg(cr, widget, panel, stroke=ink)
# 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,
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, 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 + lab_cap * 0.35,
size=_cap_size(lab_cap), bold=True, align="center",
rgb=ink, max_width=cell_w - 8)
# --- widget class --------------------------------------------------------------
_INST_DRAW = {
"AnalogGauge": _draw_analog_gauge,
"BarMeter": _draw_bar_meter,
"Beacon": _draw_beacon,
"Bezel": _draw_bezel,
"CircuitBreaker": _draw_circuit_breaker,
"ControlPanel": _draw_control_panel,
"DigitalReadout": _draw_digital_readout,
"EmergencyStop": _draw_emergency_stop,
"FlowMeter": _draw_flow_meter,
"HorizontalTankLevel": _draw_horizontal_tank,
"KeySwitch": _draw_key_switch,
"LampTestButton": _draw_lamp_test_button,
"LedBlue": _draw_led,
"LedGreen": _draw_led,
"LedRed": _draw_led,
"LevelColumnGauge": _draw_level_column,
"LevelTransmitter": _draw_level_transmitter,
"Manometer": _draw_manometer,
"Nameplate": _draw_nameplate,
"NeedleEdgewise": _draw_needle_edgewise,
"NeedleKnifeEdge": _draw_needle_knife,
"NeedleTapered": _draw_needle_tapered,
"NeedleVu": _draw_needle_vu,
"OpenChannelLevel": _draw_open_channel,
"PanelLampAmber": _draw_panel_lamp,
"PanelLampBlue": _draw_panel_lamp,
"PanelLampGreen": _draw_panel_lamp,
"PanelLampRed": _draw_panel_lamp,
"PanelLampWhite": _draw_panel_lamp,
"PanelPlate": _draw_panel_plate,
"PressureGauge": _draw_pressure_gauge,
"PushButton": lambda cr, w: _draw_push_button(cr, w, False),
"PushButtonLatching": lambda cr, w: _draw_push_button(cr, w, True),
"RgbStatusLed": _draw_rgb_led,
"RockerSwitch": lambda cr, w: _draw_rocker(cr, w, False, False),
"RockerSwitchDouble": lambda cr, w: _draw_rocker(cr, w, False, True),
"RockerSwitchIlluminated": lambda cr, w: _draw_rocker(cr, w, True,
False),
"Rotary": _draw_rotary,
"SightGlassLevel": _draw_sight_glass,
"SlideSwitch": _draw_slide_switch,
"SphericalTankLevel": _draw_spherical_tank,
"StackLight": _draw_stack_light,
"TankLevelAlarms": _draw_tank_alarms,
"TemperatureGauge": _draw_temperature_gauge,
"ToggleSwitch": lambda cr, w: _draw_toggle_switch(cr, w, False),
"ToggleSwitchIlluminated": lambda cr, w: _draw_toggle_switch(cr, w,
True),
"VerticalTankLevel": _draw_vertical_tank,
"VuMeter": _draw_vu_meter,
}
def _draw_seg_kind(cr, widget):
kind = widget.pkind
if kind.startswith("LedDigits"):
_draw_led_digits(cr, widget)
else:
_draw_seg_display(cr, widget)
class InstWidget(Widget):
"""One of the 66 Instrumentation widgets (any palette archetype
in the Instrumentation section, drawn here instead of the generic
archetype drawing)."""
ARCHETYPE = "Instrument"
def _draw(self, cr):
kind = self.pkind
if kind.startswith(("LedDigits", "Seg14Display",
"Seg16Display")):
_draw_seg_kind(cr, self)
return
draw = _INST_DRAW.get(kind)
if draw is not None:
draw(cr, self)
return
_bg(cr, self, (0.96, 0.97, 0.99), stroke=(0.5, 0.55, 0.65))
_wtext(cr, self, kind, self.width / 2, self.height / 2 + 5,
size=12, align="center", rgb=(0.4, 0.4, 0.4),
max_width=self.width - 12)