GtkCellView — LightGUI Python widget
GtkCellView is a Display widget (Display archetype) in the XFrame category of the LightGUI Python widget set. It is a display-only widget: it draws information and does not take input.
Screenshot

The screenshot above is the example program running under Xvfb.
What it does
It is a display-only widget: it draws information and does not take input.
Properties
43 properties (0 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 |
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 appOnMouseDown— dispatched at run time by the generated appOnMouseUp— dispatched at run time by the generated app
The example below wires OnClick to on_GtkCellView_001_OnClick, which prints EVENT GtkCellView_001 OnClick when you click the widget.
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"). This widget has no text or label prop.
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 GtkCellView, 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 gtkcellview.pyRunnable copy in the repo: examples/gtkcellview.py
#!/usr/bin/env python3
# Generated by LightGUI (Python/XFrame).
# A plain Python/GTK program: no CMake. Run with:
# python3 gtkcellview.py
# with the LightGUI Python package on PYTHONPATH
# (the designer sets it when it runs this script).
#
# The window is 'GtkCellView 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_GtkCellView_001_OnClick(widget):
print("EVENT %s %s" % (widget.name, 'OnClick'))
# Event handlers, wired to the widgets in main():
_HANDLERS = {
('GtkCellView_001', 'OnClick'): on_GtkCellView_001_OnClick,
}
# Design-time geometry + effective anchors per widget:
# name -> (top, left, right, bottom, x, y, width, height)
_ANCHORS = {
'GtkCellView_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('GtkCellView', 'GtkCellView_001', 16, 16, 200, 90)
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='GtkCellView 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())