Phase 6: Stock (37) + Instrumentation (66) widgets -- drawing + property tables
Cairo drawings for all 103 kinds in lightgui/xframe/stock.py and instruments.py (seeded 250-bar demo series so charts show their colours with no series data; ddaf4bd anchor guard: ParallelChannel / Pitchfork draw with 0-2 anchors; plot guard below 16px height). Property tables generated by tools/gen_props_phase6.py from the C Phase 4 tables (103 kinds, 1008 props, 116 distinct names; symbol model-only; corrected up/down rgb(0,150,0)/rgb(200,30,30)). Registry-name dispatch in core.lookup so kind-sharing entries (IndVWAP/IndAnchoredVWAP kind VWAP, TArrow kind Arrow) keep their own archetype drawings and generic-only tables.
This commit is contained in:
1 parent
ba3b144383
commit
4333f72ed5
5 files changed
+5089
-2
No files matched your search
File diff suppressed because it is too large.
Load diff
+39
-2
@@ -23,8 +23,9 @@ scrollbars, scales, text views, containers, images, progress bars,
|
||||
spin edits, calendars, colour pickers, list/tree views, notebooks,
|
||||
menus/toolbars/statusbar/splitter/shape, dialogs/windows. Pixel
|
||||
parity with C is NOT required; drawings must be recognisable as the
|
||||
widget. Stock / Instrumentation families keep the Phase 1 panel
|
||||
drawing; their faithful rendering is Phase 6 work.
|
||||
widget. Stock / Instrumentation families draw in their own modules
|
||||
(lightgui/xframe/stock.py and instruments.py, Phase 6); the generic
|
||||
panel drawing survives only as a fallback in those modules.
|
||||
|
||||
Live-apply (Phase 2): ``Widget.set_prop`` validates against the
|
||||
property table in :mod:`lightgui.props`, updates state, marks the
|
||||
@@ -2380,6 +2381,16 @@ def lookup(kind):
|
||||
entry = _palette.find(kind)
|
||||
if entry is None:
|
||||
return None
|
||||
# Phase 6: the Stock (37) + Instrumentation (66) registry names
|
||||
# draw in their own modules (stock.py / instruments.py), not in
|
||||
# the generic archetype classes. Dispatch is on the registry
|
||||
# NAME, not the palette kind: kinds are shared across families
|
||||
# (kind "VWAP" is IndAnchoredVWAP, IndVWAP and StockVWAP; kind
|
||||
# "Arrow" is StockArrow and TArrow), so kind-keyed dispatch
|
||||
# would hijack the Ind*/T* entries into the Phase 6 classes.
|
||||
cls = _KIND_CLASSES.get(entry.name)
|
||||
if cls is not None:
|
||||
return cls
|
||||
return ARCHETYPE_CLASSES[entry.archetype]
|
||||
|
||||
|
||||
@@ -2403,3 +2414,29 @@ def create(kind, name, x=0, y=0, width=None, height=None, props=None,
|
||||
|
||||
def is_known_kind(kind):
|
||||
return _palette.find(kind) is not None
|
||||
|
||||
|
||||
# --- Phase 6: Stock + Instrumentation --------------------------------------
|
||||
# The two family modules live beside core.py; they import the Widget
|
||||
# base + draw helpers from here, so they are imported at the bottom
|
||||
# (after every name they need exists) rather than at the top, which
|
||||
# would be circular. Their registry-name -> class map overrides the
|
||||
# archetype dispatch in lookup() above. props_phase6 registers the 103
|
||||
# property tables on import, so set_prop validation and the
|
||||
# generator's model-only comments work in the designer and in
|
||||
# generated apps (which import only this module).
|
||||
_KIND_CLASSES = {}
|
||||
|
||||
from lightgui.xframe import stock as _stock_mod
|
||||
from lightgui.xframe import instruments as _inst_mod
|
||||
# Keyed by registry NAME (see lookup()): the Stock* names draw in
|
||||
# StockWidget, the Inst* names in InstWidget. Everything else keeps
|
||||
# the archetype dispatch -- in particular IndVWAP/IndAnchoredVWAP
|
||||
# (kind "VWAP") stay IndicatorWidget and TArrow (kind "Arrow")
|
||||
# stays a Button.
|
||||
for _entry in _palette.PALETTE:
|
||||
if _entry.name.startswith("Stock"):
|
||||
_KIND_CLASSES[_entry.name] = _stock_mod.StockWidget
|
||||
elif _entry.name.startswith("Inst"):
|
||||
_KIND_CLASSES[_entry.name] = _inst_mod.InstWidget
|
||||
from lightgui import props_phase6 # noqa: F401
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,216 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate lightgui/props_phase6.py from the C Phase 4 tables.
|
||||
|
||||
Sources (read, never modified):
|
||||
/opt/lightgui/tools/gen_phase4_props.py
|
||||
-- the single source of truth the C work used: it parses the
|
||||
Stock*/Inst* widget headers under
|
||||
/opt/lightgui/widgets/components and derives one property
|
||||
table per widget (103 widgets, 1008 props, 116 distinct
|
||||
names, 0 missing defaults).
|
||||
/opt/lightgui_python/lightgui/xframe/palette.py
|
||||
-- the 547 palette kinds; the C class name maps to a palette
|
||||
kind through the palette's own registry-name table (mostly
|
||||
stripping the "Stock"/"Inst" prefix, but StockPriceLabel ->
|
||||
Price and InstRotarySelector -> Rotary, so the palette is
|
||||
the authority, not the prefix rule).
|
||||
|
||||
The generated file keeps the C tables verbatim (internal prop names,
|
||||
kinds, defaults, ranges) and adds:
|
||||
* a Lazarus display name per prop (mechanical CamelCase of the
|
||||
internal name, e.g. up-color -> UpColor, anchor-1-bar ->
|
||||
Anchor1Bar), matching the style of the Phase 2 tables,
|
||||
* a model_only flag: only "symbol" (the ticker symbol stored on
|
||||
chart widgets; in C symbol_ is settable/readable but never drawn,
|
||||
so it is stored in the model and emitted by the generator as a
|
||||
comment). Every other Phase 6 prop is honoured by the draw code
|
||||
(colours, ranges, levels, values, anchors, view window, alarm
|
||||
bands, brick-size, bins, labels, ...) and live-applies.
|
||||
* registration via props.register_custom_table() on import, so the
|
||||
Inspector and the generator pick the tables up with no other
|
||||
change (props.py's register_custom_table() is the Phase 6 hook).
|
||||
|
||||
StockChart up/down defaults are the corrected values from the C
|
||||
tables: up-color rgb(0,150,0), down-color rgb(200,30,30).
|
||||
|
||||
Re-run: python3 tools/gen_props_phase6.py (from the repo root)
|
||||
"""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
REPO = Path(__file__).resolve().parent.parent
|
||||
C_TOOLS = Path("/opt/lightgui/tools")
|
||||
WIDGETS_DIR = Path("/opt/lightgui/widgets/components")
|
||||
|
||||
sys.path.insert(0, str(C_TOOLS))
|
||||
import gen_phase4_props as c_gen # noqa: E402
|
||||
|
||||
# Palette kind -> C class name is the reverse of this strip; verified
|
||||
# against palette.py at generation time (must be exactly the 37 Stock
|
||||
# + 66 Instrumentation kinds, no duplicates, no strays).
|
||||
MODEL_ONLY = frozenset({"symbol"})
|
||||
|
||||
|
||||
def _display_name(prop):
|
||||
"""Mechanical Lazarus display name: up-color -> UpColor,
|
||||
anchor-1-bar -> Anchor1Bar, y-min -> YMin."""
|
||||
parts = prop.replace("-", " ").split()
|
||||
return "".join(p[:1].upper() + p[1:] for p in parts)
|
||||
|
||||
|
||||
def _kind_of(class_name):
|
||||
return _REGISTRY_KIND[class_name]
|
||||
|
||||
|
||||
def _parse_palette_kinds():
|
||||
"""Registry name -> palette kind for the Stock/Inst entries,
|
||||
parsed statically from palette.py (no package import: importing
|
||||
the palette would import core, which imports the file being
|
||||
generated). Most names map by stripping the Stock/Inst prefix,
|
||||
but not all (StockPriceLabel -> Price, InstRotarySelector ->
|
||||
Rotary), so the palette table is the authority."""
|
||||
import re
|
||||
palette_text = (REPO / "lightgui" / "xframe" / "palette.py") \
|
||||
.read_text(encoding="utf-8")
|
||||
out = {}
|
||||
for match in re.finditer(
|
||||
r"PaletteEntry\(\d+, '((?:Stock|Inst)\w+)', '\w+', "
|
||||
r"'(?:Stock Market|Instrumentation)', \d+, \d+, \d+, "
|
||||
r"'\w+', '([^']+)'\)", palette_text):
|
||||
out[match.group(1)] = match.group(2)
|
||||
return out
|
||||
|
||||
|
||||
def _parse_all_palette_kinds():
|
||||
"""Registry name -> palette kind for ALL 547 entries, parsed
|
||||
statically (see _parse_palette_kinds). Used to find the
|
||||
shadowed names: entries outside the Stock/Inst families whose
|
||||
kind is a Phase 6 kind (kinds are shared across families)."""
|
||||
import re
|
||||
palette_text = (REPO / "lightgui" / "xframe" / "palette.py") \
|
||||
.read_text(encoding="utf-8")
|
||||
out = {}
|
||||
for match in re.finditer(
|
||||
r"PaletteEntry\(\d+, '(\w+)', '\w+', '[^']+', \d+, \d+, "
|
||||
r"\d+, '\w+', '([^']+)'\)", palette_text):
|
||||
out[match.group(1)] = match.group(2)
|
||||
return out
|
||||
|
||||
|
||||
_REGISTRY_KIND = _parse_palette_kinds()
|
||||
|
||||
|
||||
def main():
|
||||
widgets = c_gen.parse_widgets(str(WIDGETS_DIR))
|
||||
assert len(widgets) == 103, "expected 103 widgets, got %d" \
|
||||
% len(widgets)
|
||||
tables = {}
|
||||
total = 0
|
||||
for class_name in sorted(widgets):
|
||||
props, missing = c_gen.props_for_widget(widgets, class_name)
|
||||
assert not missing, "missing defaults for %s: %s" \
|
||||
% (class_name, missing)
|
||||
kind = _kind_of(class_name)
|
||||
assert kind not in tables, "duplicate kind %r" % kind
|
||||
tables[kind] = (class_name, props)
|
||||
total += len(props)
|
||||
assert total == 1008, "expected 1008 props, got %d" % total
|
||||
distinct = {p[0] for _c, props in tables.values() for p in props}
|
||||
assert len(distinct) == 116, "expected 116 distinct names, got %d" \
|
||||
% len(distinct)
|
||||
|
||||
# Cross-check against the palette: exactly the Stock + Inst kinds.
|
||||
palette_kinds = set(_REGISTRY_KIND.values())
|
||||
assert palette_kinds == set(tables), \
|
||||
"palette/generator kind mismatch: %s" % (
|
||||
palette_kinds ^ set(tables),)
|
||||
|
||||
# Shadowed names: entries outside the Stock/Inst families whose
|
||||
# kind is a Phase 6 kind. props._resolve_kind() maps a registry
|
||||
# name to its kind, so without an explicit table these would
|
||||
# inherit the Phase 6 table (IndVWAP would get StockVWAP's
|
||||
# props; TArrow would get StockArrow's). They keep the generic
|
||||
# set only, as in Phase 2 -- register them with empty tables so
|
||||
# _resolve_kind() keeps the registry name.
|
||||
all_kinds = _parse_all_palette_kinds()
|
||||
shadowed = sorted(name for name, kind in all_kinds.items()
|
||||
if kind in tables and name not in _REGISTRY_KIND)
|
||||
assert shadowed, "expected shadowed names, found none"
|
||||
assert not (set(shadowed) & set(tables)), \
|
||||
"shadowed name collides with a Phase 6 kind: %s" % shadowed
|
||||
|
||||
lines = []
|
||||
lines.append('"""Property tables for the Stock (37) + Instrumentation')
|
||||
lines.append('(66) families -- Phase 6.')
|
||||
lines.append('')
|
||||
lines.append('GENERATED -- do not edit by hand. Run')
|
||||
lines.append('tools/gen_props_phase6.py to regenerate from')
|
||||
lines.append('/opt/lightgui/tools/gen_phase4_props.py (the C tables,')
|
||||
lines.append('canonical) and lightgui/xframe/palette.py.')
|
||||
lines.append('')
|
||||
lines.append('103 widgets, 1008 props, 116 distinct prop names.')
|
||||
lines.append('Generic set first (from lightgui.props.props_for), then')
|
||||
lines.append('each widget\'s own props below (register_custom_table).')
|
||||
lines.append('StockChart up/down defaults are the corrected values')
|
||||
lines.append('up-color rgb(0,150,0) / down-color rgb(200,30,30).')
|
||||
lines.append('Model-only: "symbol" only -- the ticker symbol stored on')
|
||||
lines.append('chart widgets; in C symbol_ is never drawn, so it is')
|
||||
lines.append('stored in the model and emitted by the generator as a')
|
||||
lines.append('comment. Every other prop here is honoured by the draw')
|
||||
lines.append('code and live-applies.')
|
||||
lines.append('Shadowed registry names (empty tables, generic set')
|
||||
lines.append('only): entries outside the Stock/Inst families whose')
|
||||
lines.append('palette kind is a Phase 6 kind -- kinds are shared')
|
||||
lines.append('across families, so without an explicit table')
|
||||
lines.append('props._resolve_kind() would map them onto the Phase 6')
|
||||
lines.append('table (IndVWAP onto StockVWAP, TArrow onto')
|
||||
lines.append('StockArrow).')
|
||||
lines.append('"""')
|
||||
lines.append('')
|
||||
lines.append('from lightgui.props import PropDef, register_custom_table')
|
||||
lines.append('')
|
||||
lines.append('')
|
||||
lines.append('# C class name -> palette kind, for reference.')
|
||||
lines.append('PHASE6_CLASSES = {')
|
||||
for kind in sorted(tables):
|
||||
class_name, _props = tables[kind]
|
||||
lines.append(' %r: %r,' % (kind, class_name))
|
||||
lines.append('}')
|
||||
lines.append('')
|
||||
lines.append('# Registry names outside the Stock/Inst families whose')
|
||||
lines.append('# kind is a Phase 6 kind; generic set only (see above).')
|
||||
lines.append('SHADOWED = (')
|
||||
for name in shadowed:
|
||||
lines.append(' %r,' % name)
|
||||
lines.append(')')
|
||||
lines.append('')
|
||||
lines.append('TABLES = {')
|
||||
for kind in sorted(tables):
|
||||
_class_name, props = tables[kind]
|
||||
lines.append(' %r: (' % kind)
|
||||
for (prop, pkind, lo, hi, default, _setter) in props:
|
||||
lo_s = "0" if lo is None else repr(lo)
|
||||
hi_s = "0" if hi is None else repr(hi)
|
||||
model_only = "True" if prop in MODEL_ONLY else "False"
|
||||
lines.append(
|
||||
' PropDef(%r, %r, %r, %s, %s, (), (), %r, %s),'
|
||||
% (prop, pkind, default, lo_s, hi_s,
|
||||
_display_name(prop), model_only))
|
||||
lines.append(' ),')
|
||||
lines.append('}')
|
||||
lines.append('')
|
||||
lines.append('')
|
||||
lines.append('for _kind, _props in TABLES.items():')
|
||||
lines.append(' register_custom_table(_kind, _props)')
|
||||
lines.append('for _name in SHADOWED:')
|
||||
lines.append(' register_custom_table(_name, ())')
|
||||
lines.append('')
|
||||
|
||||
out = REPO / "lightgui" / "props_phase6.py"
|
||||
out.write_text("\n".join(lines), encoding="utf-8")
|
||||
print("wrote %s: %d kinds, %d props, %d distinct names, %d shadowed"
|
||||
% (out, len(tables), total, len(distinct), len(shadowed)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user