StockMoneyFlowChart — LightGUI Python widget
StockMoneyFlowChart is a Stock Market widget (Chart archetype) in the Stock category of the LightGUI Python widget set. It is a stock chart: it renders the built-in deterministic demo price series as candles or lines.
Screenshot

The screenshot above is the example program running under Xvfb.
What it does
It is a stock chart: it renders the built-in deterministic demo price series as candles or lines.
Properties
50 properties (7 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) |
down-color | Color | rgb(200,30,30) | DownColor | set_prop("down-color", value) |
up-color | Color | rgb(0,150,0) | UpColor | set_prop("up-color", value) |
zero-line-color | Color | rgb(120,120,120) | ZeroLineColor | set_prop("zero-line-color", value) |
symbol | Str | SYM | Symbol | model-only — no setter; stored on the widget, emitted as a comment by the generator |
view-count | Double | 0 | ViewCount | set_prop("view-count", value) |
view-first | Double | 0 | ViewFirst | set_prop("view-first", 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_StockMoneyFlowChart_001_OnClick, which prints EVENT StockMoneyFlowChart_001 OnClick when you click the widget.
Stock widgets: clear and populate
Charts and indicators in this set render the built-in deterministic demo price series, so the example runs and draws without feeding any data in. To feed a widget real data, use the series methods on the widget: widget.set_series(bars) replaces the plotted series with a list of (open, high, low, close, volume) bars, and widget.load_csv('file.csv') loads the same bars from an OHLCV file -- both are runtime state only, never saved in .fdj files. Clear it with widget.clear() and repopulate with widget.populate(bars) (or set_series(bars)); widget.set_series(None) restores the demo series. The 'Plotting your own data (CSV)' section below has the full file format and a working example. Label the series with the symbol prop (widget.set_prop("symbol", "AAPL")); view-count and view-first only window which bars are visible -- they do not feed data, and set_series resets the window; set the title with the text prop. The series colours come from the line-color and family colour props in the table above.
Plotting your own data (CSV)
With no data fed in, this widget renders the built-in deterministic demo series: 250 bars from demo_series() (seed 42), a random walk starting at 100.0. The money-flow line is rebuilt from the loaded bars. To plot your own data, feed it a series with set_series() or load an OHLCV file with load_csv() -- both are methods on the widget, not Inspector props, and the data is runtime state only (it is not saved in .fdj files).
The CSV format is date,open,high,low,close,volume, one bar per row. The header row is optional: with one, columns are matched by name in any order (extra columns ignored); without one they must be in that order. Dates accept YYYY-MM-DD, YYYY/MM/DD, DD-MM-YYYY, an ISO datetime, or epoch seconds -- they are validated but not stored, and the x-axis plots bar index, not dates. Bad rows raise ValueError naming the row. A ready-made file is tests/data/ohlcv_30.csv (30 weekday bars, 2026-01-05 to 2026-02-13). Full spec: docs/stock-charts-data.md.
In the generated program, add one line in _build_widgets(), right after the widget is created:
widget.load_csv('tests/data/ohlcv_30.csv')Clear and repopulate with widget.clear() and widget.populate(bars) (or set_series(bars)); widget.set_series(None) restores the demo series. A cleared widget draws a no-data placeholder.

The screenshot above is the example program running under Xvfb with the 30-bar CSV loaded (last close 95.71, down from 100.00).
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 StockMoneyFlowChart, 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 stockmoneyflowchart.pyRunnable copy in the repo: examples/stockmoneyflowchart.py
#!/usr/bin/env python3
# Generated by LightGUI (Python/XFrame).
# A plain Python/GTK program: no CMake. Run with:
# python3 stockmoneyflowchart.py
# with the LightGUI Python package on PYTHONPATH
# (the designer sets it when it runs this script).
#
# The window is 'StockMoneyFlowChart 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_StockMoneyFlowChart_001_OnClick(widget):
print("EVENT %s %s" % (widget.name, 'OnClick'))
# Event handlers, wired to the widgets in main():
_HANDLERS = {
('StockMoneyFlowChart_001', 'OnClick'): on_StockMoneyFlowChart_001_OnClick,
}
# Design-time geometry + effective anchors per widget:
# name -> (top, left, right, bottom, x, y, width, height)
_ANCHORS = {
'StockMoneyFlowChart_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('StockMoneyFlowChart', 'StockMoneyFlowChart_001', 16, 16, 200, 90)
widget.set_prop('text', 'StockMoneyFlowChart_001')
# NOTE (model-only, no XFrame setter): symbol='AAPL'
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='StockMoneyFlowChart 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())