InstSeg14Display6 — LightGUI Python widget
InstSeg14Display6 is a Instrumentation widget (Instrument archetype) in the Instrumentation category of the LightGUI Python widget set. It is an instrumentation control (gauge, meter, lamp, switch or readout): it shows a live value or state.
Screenshot

The screenshot above is the example program running under Xvfb.
What it does
It is an instrumentation control (gauge, meter, lamp, switch or readout): it shows a live value or state.
Properties
49 properties (6 custom to this widget, the rest are the generic set every widget has). Set a property in code with widget.set_prop(name, value); model-only properties have no live setter.
| Property | Type | Default | Inspector | Setter |
|---|---|---|---|---|
name | Str | — | Name | set_prop("name", value) |
left | Int | 0 | Left | set_prop("left", value) |
top | Int | 0 | Top | set_prop("top", value) |
width | Int | 100 | Width | set_prop("width", value) |
height | Int | 30 | Height | set_prop("height", value) |
background | Color | — | Color | set_prop("background", value) |
foreground | Color | — | Font.Color | set_prop("foreground", value) |
border-width | Int | 0 | Border.Width | set_prop("border-width", value) |
border-color | Color | — | Border.Color | set_prop("border-color", value) |
border-radius | Int | 0 | Border.Radius | set_prop("border-radius", value) |
tooltip-text | Str | — | Tooltip | model-only — no setter; stored on the widget, emitted as a comment by the generator |
enabled | Bool | true | Enabled | set_prop("enabled", value) |
visible | Bool | true | Visible | set_prop("visible", value) |
font-name | Str | — | Font.Name | set_prop("font-name", value) |
font-size | Int | 13 | Font.Size | set_prop("font-size", value) |
font-bold | Bool | false | Font.Style.Bold | set_prop("font-bold", value) |
font-italic | Bool | false | Font.Style.Italic | set_prop("font-italic", value) |
font-underline | Bool | false | Font.Style.Underline | model-only — no setter; stored on the widget, emitted as a comment by the generator |
font-strikeout | Bool | false | Font.Style.StrikeOut | model-only — no setter; stored on the widget, emitted as a comment by the generator |
hint | Str | — | Hint | model-only — no setter; stored on the widget, emitted as a comment by the generator |
show-hint | Bool | false | ShowHint | model-only — no setter; stored on the widget, emitted as a comment by the generator |
cursor | Str | — | Cursor | model-only — no setter; stored on the widget, emitted as a comment by the generator |
tab-order | Int | 0 | TabOrder | model-only — no setter; stored on the widget, emitted as a comment by the generator |
tab-stop | Bool | true | TabStop | model-only — no setter; stored on the widget, emitted as a comment by the generator |
min-width | Int | 0 | Constraints.MinWidth | set_prop("min-width", value) |
min-height | Int | 0 | Constraints.MinHeight | set_prop("min-height", value) |
max-width | Int | 0 | Constraints.MaxWidth | set_prop("max-width", value) |
max-height | Int | 0 | Constraints.MaxHeight | set_prop("max-height", value) |
margin-left | Int | 0 | BorderSpacing.Left | model-only — no setter; stored on the widget, emitted as a comment by the generator |
margin-top | Int | 0 | BorderSpacing.Top | model-only — no setter; stored on the widget, emitted as a comment by the generator |
margin-right | Int | 0 | BorderSpacing.Right | model-only — no setter; stored on the widget, emitted as a comment by the generator |
margin-bottom | Int | 0 | BorderSpacing.Bottom | model-only — no setter; stored on the widget, emitted as a comment by the generator |
margin-around | Int | 0 | BorderSpacing.Around | model-only — no setter; stored on the widget, emitted as a comment by the generator |
autosize | Bool | false | AutoSize | model-only — no setter; stored on the widget, emitted as a comment by the generator |
tag | Int | 0 | Tag | model-only — no setter; stored on the widget, emitted as a comment by the generator |
anchor-top | Bool | true | Anchors.Top | model-only — no setter; stored on the widget, emitted as a comment by the generator |
anchor-left | Bool | true | Anchors.Left | model-only — no setter; stored on the widget, emitted as a comment by the generator |
anchor-right | Bool | false | Anchors.Right | model-only — no setter; stored on the widget, emitted as a comment by the generator |
anchor-bottom | Bool | false | Anchors.Bottom | model-only — no setter; stored on the widget, emitted as a comment by the generator |
align | Enum (None, Top, Bottom, Left, Right, Client) | 0 | Align | model-only — no setter; stored on the widget, emitted as a comment by the generator |
inner-border | Int | 0 | BorderSpacing.InnerBorder | model-only — no setter; stored on the widget, emitted as a comment by the generator |
cell-align-horizontal | Enum (Left, Center, Right) | 0 | BorderSpacing.CellAlignHorizontal | model-only — no setter; stored on the widget, emitted as a comment by the generator |
cell-align-vertical | Enum (Top, Center, Bottom) | 0 | BorderSpacing.CellAlignVertical | model-only — no setter; stored on the widget, emitted as a comment by the generator |
text | Str | — | Text | set_prop("text", value) |
bezel-color | Color | rgb(58,58,62) | BezelColor | set_prop("bezel-color", value) |
dim-color | Color | rgb(60,42,8) | DimColor | set_prop("dim-color", value) |
label-color | Color | rgb(170,170,170) | LabelColor | set_prop("label-color", value) |
lit-color | Color | rgb(255,176,0) | LitColor | set_prop("lit-color", value) |
value | Str | ABC123 | Value | set_prop("value", value) |
Events
The generated app dispatches mouse events at run time: a button press is hit-tested to the topmost widget under the pointer and fires OnClick (and OnMouseDown); the release goes to the widget that got the press, even if the pointer moved off it, and fires OnMouseUp; a double-click fires OnDblClick. A disabled widget receives no events. Other Lazarus events get a handler stub in the generated code, marked with a NOTE comment, and are kept for hand-wiring.
Events this widget uses:
OnClick— dispatched at run time by the generated appOnChange— stub emitted in the generated code; no run-time wiring, kept for hand-wiringOnMouseDown— dispatched at run time by the generated appOnMouseUp— dispatched at run time by the generated app
The example below wires OnClick to on_InstSeg14Display6_001_OnClick, which prints EVENT InstSeg14Display6_001 OnClick when you click the widget.
Instrumentation: adjusting the level
The level is the value prop — set it in code with widget.set_value(65) or widget.set_prop("value", "65") and the needle, bar or readout moves on the next redraw. minimum and maximum set the scale; marker and needle widths come from the *-line-width props, and the face, ink and zone colours from the *-color props in the table above.
Font and labels
Change the font in code with the font-name, font-size, font-bold and font-italic props — for example widget.set_prop("font-size", "16") and widget.set_prop("font-bold", "true"). Change the caption with the text prop (widget.set_prop("text", "Hello"), or widget.set_text("Hello")).
Styling
Colours and borders are plain props: background is the fill, foreground is the font/text colour, border-width the border thickness in pixels, border-color its colour, and border-radius rounds the corners (0 = square). For example widget.set_prop("background", "#336699"), widget.set_prop("border-width", "2") and widget.set_prop("border-radius", "8").
Working example
A minimal complete Python program: one window, one InstSeg14Display6, with OnClick wired. It is the LightGUI designer's own codegen output for a project holding just this widget. Run it with the LightGUI Python package on PYTHONPATH:
PYTHONPATH=/opt/lightgui_python python3 instseg14display6.pyRunnable copy in the repo: examples/instseg14display6.py
#!/usr/bin/env python3
# Generated by LightGUI (Python/XFrame).
# A plain Python/GTK program: no CMake. Run with:
# python3 instseg14display6.py
# with the LightGUI Python package on PYTHONPATH
# (the designer sets it when it runs this script).
#
# The window is 'InstSeg14Display6 example' (232x122) with 1 widget(s).
import sys
import gi
gi.require_version("Gtk", "3.0")
gi.require_version("Gdk", "3.0")
from gi.repository import Gdk, Gtk # noqa: E402
from lightgui.xframe.core import create, parse_color # noqa: E402
def on_InstSeg14Display6_001_OnClick(widget):
print("EVENT %s %s" % (widget.name, 'OnClick'))
# Event handlers, wired to the widgets in main():
_HANDLERS = {
('InstSeg14Display6_001', 'OnClick'): on_InstSeg14Display6_001_OnClick,
}
# Design-time geometry + effective anchors per widget:
# name -> (top, left, right, bottom, x, y, width, height)
_ANCHORS = {
'InstSeg14Display6_001': (True, True, False, False, 16, 16, 200, 90),
}
def _apply_anchors(widgets, width, height):
"""Reposition anchored widgets for a drawing area of
*width* x *height* (Flag 1: minimal anchor layout).
Computed from the design geometry every time, so a
resize is idempotent — no drift across resizes."""
design_w, design_h = _DESIGN_SIZE
dx = width - design_w
dy = height - design_h
for widget in widgets:
top, left, right, bottom, ox, oy, ow, oh = \
_ANCHORS[widget.name]
x, y, w, h = ox, oy, ow, oh
if right and not left:
x = ox + dx
elif right and left:
w = ow + dx
if bottom and not top:
y = oy + dy
elif bottom and top:
h = oh + dy
widget.move_to(x, y)
widget.resize_to(w, h)
def _build_widgets():
"""Create every placed widget with its props."""
widgets = []
widget = create('InstSeg14Display6', 'InstSeg14Display6_001', 16, 16, 200, 90)
widget.set_prop('text', 'InstSeg14Display6_001')
widgets.append(widget)
return widgets
_DESIGN_SIZE = (232, 122)
_BACKGROUND = ''
_WIDGETS = []
_LAST_SIZE = [None]
_PRESSED = [None] # Task 4: widget that got the ButtonPress
def _hit_widget(widgets, x, y):
"""Topmost visible widget containing (*x*, *y*)."""
for widget in reversed(widgets):
if widget.get_prop("visible", "true") in ("false", "0"):
continue
if widget.contains(x, y):
return widget
return None
def _dispatch_to(widget, event):
"""Call the *event* handler of *widget* (already chosen)."""
if widget is None:
return
if widget.get_prop("enabled", "true") in ("false", "0"):
return
handler = _HANDLERS.get((widget.name, event))
if handler is not None:
handler(widget)
def _dispatch(widgets, x, y, event):
"""Call the *event* handler of the widget at (*x*, *y*),
if it has one wired."""
_dispatch_to(_hit_widget(widgets, x, y), event)
def _on_draw(area, cr):
bg = parse_color(_BACKGROUND, None)
if bg is None:
bg = (1.0, 1.0, 1.0)
cr.set_source_rgb(*bg)
cr.paint()
for widget in _WIDGETS:
widget.draw(cr)
return False
def _on_button_press(area, event):
if event.type == Gdk.EventType.DOUBLE_BUTTON_PRESS:
_dispatch(_WIDGETS, event.x, event.y, "OnDblClick")
elif event.type == Gdk.EventType.BUTTON_PRESS:
_dispatch(_WIDGETS, event.x, event.y, "OnMouseDown")
_dispatch(_WIDGETS, event.x, event.y, "OnClick")
# Task 4: remember the pressed widget; release goes there.
_PRESSED[0] = _hit_widget(_WIDGETS, event.x, event.y)
return False
def _on_button_release(area, event):
# Task 4: release goes to the widget that got the press,
# even if the pointer moved off it.
widget = _PRESSED[0]
_PRESSED[0] = None
_dispatch_to(widget, "OnMouseUp")
return False
def _on_area_resize(area, allocation):
size = (allocation.width, allocation.height)
if size == _LAST_SIZE[0]:
return False
_LAST_SIZE[0] = size
_apply_anchors(_WIDGETS, size[0], size[1])
area.queue_draw()
return False
def main():
window = Gtk.Window(title='InstSeg14Display6 example')
window.set_default_size(232, 122)
window.connect("destroy", Gtk.main_quit)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
spacing=0)
window.add(vbox)
area = Gtk.DrawingArea()
area.set_hexpand(True)
area.set_vexpand(True)
area.add_events(Gdk.EventMask.BUTTON_PRESS_MASK |
Gdk.EventMask.BUTTON_RELEASE_MASK)
area.connect("draw", _on_draw)
area.connect("button-press-event", _on_button_press)
area.connect("button-release-event", _on_button_release)
area.connect("size-allocate", _on_area_resize)
vbox.pack_start(area, True, True, 0)
_WIDGETS.extend(_build_widgets())
window.show_all()
Gtk.main()
return 0
if __name__ == "__main__":
sys.exit(main())