Phase 2: property tables (props.py) generated from C props.h
- tools/gen_props.py parses /opt/lightgui/src/props.h (common_props + props_for tables, enum labels/values) and the 547-kind palette, emitting lightgui/props.py; REQUIRED spot-checks enforce the proposal SS2.1-SS2.10 lists against the C tables. - Every kind gets the 43-prop generic set (Name, geometry, Color, Font Name/Size/Color/Style, Border, Enabled, Visible, Hint, ShowHint, Cursor, TabOrder, TabStop, Constraints, BorderSpacing, AutoSize, Tag, Align, Anchors); 38 family custom tables cover the generic widgets. Stock/Instrumentation get the generic set only (Phase 6 adds theirs via register_custom_table()). - Lazarus display names + model_only flags (stored, generator comments, no live canvas effect); validate() canonicalises bool/int/double/enum/color or raises ValueError.
This commit is contained in:
1 parent
ff1cadbd80
commit
eeccee6c9a
2 files changed
+1460
No files matched your search
@@ -0,0 +1,760 @@
|
||||
"""Property tables for the LightGUI Python port.
|
||||
|
||||
GENERATED -- do not edit by hand. Run tools/gen_props.py
|
||||
to regenerate from /opt/lightgui/src/props.h (C tables,
|
||||
canonical) and lightgui/xframe/palette.py (the 547 kinds).
|
||||
Curated mappings (kind -> C table, Lazarus display names,
|
||||
model-only flags) live in tools/gen_props.py.
|
||||
|
||||
Every palette kind gets the generic set (Name, geometry,
|
||||
Color, Font, Border, Enabled, Visible, Hint, ShowHint,
|
||||
Cursor, TabOrder, TabStop, Constraints, BorderSpacing,
|
||||
AutoSize, Tag, Align, Anchors) plus its family custom
|
||||
props from proposal SS2.1-SS2.21. Stock / Instrumentation
|
||||
kinds get the generic set only in Phase 2; Phase 6 adds
|
||||
their tables via register_custom_table().
|
||||
|
||||
Internal names stay the C/GTK-era names (proposal SS5.3);
|
||||
`display` is the Lazarus name shown in the Inspector.
|
||||
`model_only` props are stored on the widget and emitted
|
||||
by the generator as comments; they do not change the live
|
||||
canvas widget. Note `editable` is inverted ReadOnly
|
||||
(ReadOnly = not editable, proposal SS2.2) and `foreground`
|
||||
is the font/text colour.
|
||||
"""
|
||||
|
||||
import re
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
PropDef = namedtuple(
|
||||
"PropDef",
|
||||
"name kind default lo hi enum_labels enum_values "
|
||||
"display model_only")
|
||||
|
||||
EVENTS = ("OnClick", "OnChange", "OnKeyPress", "OnKeyDown", "OnKeyUp", "OnMouseDown", "OnMouseUp", "OnMouseMove", "OnDblClick", "OnEnter", "OnExit", "OnResize", "OnChangeBounds", "OnMouseEnter", "OnMouseLeave", "OnMouseWheel", "OnContextPopup")
|
||||
|
||||
GENERIC_PROPS = (
|
||||
PropDef("name", "Str", "", 0, 0, (), (), "Name", False),
|
||||
PropDef("left", "Int", "0", 0, 100000, (), (), "Left", False),
|
||||
PropDef("top", "Int", "0", 0, 100000, (), (), "Top", False),
|
||||
PropDef("width", "Int", "100", 10, 100000, (), (), "Width", False),
|
||||
PropDef("height", "Int", "30", 10, 100000, (), (), "Height", False),
|
||||
PropDef("background", "Color", "", 0, 0, (), (), "Color", False),
|
||||
PropDef("foreground", "Color", "", 0, 0, (), (), "Font.Color", False),
|
||||
PropDef("border-width", "Int", "0", 0, 100, (), (), "Border.Width", False),
|
||||
PropDef("border-color", "Color", "", 0, 0, (), (), "Border.Color", False),
|
||||
PropDef("border-radius", "Int", "0", 0, 1000, (), (), "Border.Radius", False),
|
||||
PropDef("tooltip-text", "Str", "", 0, 0, (), (), "Hint", True),
|
||||
PropDef("enabled", "Bool", "true", 0, 0, (), (), "Enabled", False),
|
||||
PropDef("visible", "Bool", "true", 0, 0, (), (), "Visible", False),
|
||||
PropDef("font-name", "Str", "", 0, 0, (), (), "Font.Name", False),
|
||||
PropDef("font-size", "Int", "13", 6, 72, (), (), "Font.Size", False),
|
||||
PropDef("font-bold", "Bool", "false", 0, 0, (), (), "Font.Style.Bold", False),
|
||||
PropDef("font-italic", "Bool", "false", 0, 0, (), (), "Font.Style.Italic", False),
|
||||
PropDef("font-underline", "Bool", "false", 0, 0, (), (), "Font.Style.Underline", True),
|
||||
PropDef("font-strikeout", "Bool", "false", 0, 0, (), (), "Font.Style.StrikeOut", True),
|
||||
PropDef("hint", "Str", "", 0, 0, (), (), "Hint", True),
|
||||
PropDef("show-hint", "Bool", "false", 0, 0, (), (), "ShowHint", True),
|
||||
PropDef("cursor", "Str", "", 0, 0, (), (), "Cursor", True),
|
||||
PropDef("tab-order", "Int", "0", 0, 100000, (), (), "TabOrder", True),
|
||||
PropDef("tab-stop", "Bool", "true", 0, 0, (), (), "TabStop", True),
|
||||
PropDef("min-width", "Int", "0", 0, 100000, (), (), "Constraints.MinWidth", False),
|
||||
PropDef("min-height", "Int", "0", 0, 100000, (), (), "Constraints.MinHeight", False),
|
||||
PropDef("max-width", "Int", "0", 0, 100000, (), (), "Constraints.MaxWidth", False),
|
||||
PropDef("max-height", "Int", "0", 0, 100000, (), (), "Constraints.MaxHeight", False),
|
||||
PropDef("margin-left", "Int", "0", 0, 100000, (), (), "BorderSpacing.Left", True),
|
||||
PropDef("margin-top", "Int", "0", 0, 100000, (), (), "BorderSpacing.Top", True),
|
||||
PropDef("margin-right", "Int", "0", 0, 100000, (), (), "BorderSpacing.Right", True),
|
||||
PropDef("margin-bottom", "Int", "0", 0, 100000, (), (), "BorderSpacing.Bottom", True),
|
||||
PropDef("margin-around", "Int", "0", 0, 100000, (), (), "BorderSpacing.Around", True),
|
||||
PropDef("autosize", "Bool", "false", 0, 0, (), (), "AutoSize", True),
|
||||
PropDef("tag", "Int", "0", -1000000, 1000000, (), (), "Tag", True),
|
||||
PropDef("anchor-top", "Bool", "true", 0, 0, (), (), "Anchors.Top", True),
|
||||
PropDef("anchor-left", "Bool", "true", 0, 0, (), (), "Anchors.Left", True),
|
||||
PropDef("anchor-right", "Bool", "false", 0, 0, (), (), "Anchors.Right", True),
|
||||
PropDef("anchor-bottom", "Bool", "false", 0, 0, (), (), "Anchors.Bottom", True),
|
||||
PropDef("align", "Enum", "0", 0, 0, ("None", "Top", "Bottom", "Left", "Right", "Client"), (0, 1, 2, 3, 4, 5), "Align", True),
|
||||
PropDef("inner-border", "Int", "0", 0, 100000, (), (), "BorderSpacing.InnerBorder", True),
|
||||
PropDef("cell-align-horizontal", "Enum", "0", 0, 0, ("Left", "Center", "Right"), (), "BorderSpacing.CellAlignHorizontal", True),
|
||||
PropDef("cell-align-vertical", "Enum", "0", 0, 0, ("Top", "Center", "Bottom"), (), "BorderSpacing.CellAlignVertical", True),
|
||||
)
|
||||
|
||||
GENERIC_NAMES = frozenset(p.name for p in GENERIC_PROPS)
|
||||
|
||||
DIALOG_PROPS = (
|
||||
PropDef("title", "Str", "", 0, 0, (), (), "Title", False),
|
||||
)
|
||||
|
||||
LABEL_PROPS = (
|
||||
PropDef("label", "Str", "", 0, 0, (), (), "Caption", False),
|
||||
PropDef("xalign", "Double", "0.5", 0, 1, (), (), "Alignment", False),
|
||||
PropDef("yalign", "Double", "0.5", 0, 1, (), (), "Layout", False),
|
||||
PropDef("selectable", "Bool", "false", 0, 0, (), (), "Selectable", True),
|
||||
PropDef("wrap", "Bool", "false", 0, 0, (), (), "WordWrap", False),
|
||||
PropDef("transparent", "Bool", "false", 0, 0, (), (), "Transparent", False),
|
||||
PropDef("show-accel-char", "Bool", "true", 0, 0, (), (), "ShowAccelChar", False),
|
||||
PropDef("focus-control", "Str", "", 0, 0, (), (), "FocusControl", True),
|
||||
)
|
||||
|
||||
BUTTON_PROPS = (
|
||||
PropDef("label", "Str", "", 0, 0, (), (), "Caption", False),
|
||||
PropDef("relief", "Enum", "0", 0, 0, ("Normal", "Half", "None"), (0, 1, 2), "Relief", True),
|
||||
PropDef("focus-on-click", "Bool", "true", 0, 0, (), (), "FocusOnClick", True),
|
||||
PropDef("default", "Bool", "false", 0, 0, (), (), "Default", True),
|
||||
PropDef("cancel", "Bool", "false", 0, 0, (), (), "Cancel", True),
|
||||
PropDef("kind", "Enum", "0", 0, 0, ("None", "OK", "Cancel", "Yes", "No", "Close", "Help", "Retry", "Ignore", "Abort"), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9), "Kind", True),
|
||||
PropDef("modal-result", "Int", "0", 0, 100, (), (), "ModalResult", True),
|
||||
PropDef("layout", "Enum", "0", 0, 0, ("Left", "Right", "Top", "Bottom"), (0, 1, 2, 3), "Layout", True),
|
||||
PropDef("glyph", "Str", "", 0, 0, (), (), "Glyph", True),
|
||||
)
|
||||
|
||||
TOPLEVEL_PROPS = (
|
||||
PropDef("title", "Str", "", 0, 0, (), (), "Title", True),
|
||||
PropDef("resizable", "Bool", "true", 0, 0, (), (), "Resizable", True),
|
||||
PropDef("border-style", "Enum", "0", 0, 0, ("Default", "None", "Single", "Dialog"), (0, 1, 2, 3), "BorderStyle", True),
|
||||
PropDef("icon", "Str", "", 0, 0, (), (), "Icon", True),
|
||||
PropDef("position", "Enum", "0", 0, 0, ("Default", "Center", "ScreenCenter", "MainFormCenter", "Designed"), (0, 1, 2, 3, 4), "Position", True),
|
||||
PropDef("window-state", "Enum", "0", 0, 0, ("Normal", "Minimized", "Maximized", "Fullscreen"), (0, 1, 2, 3), "WindowState", True),
|
||||
)
|
||||
|
||||
FRAME_PROPS = (
|
||||
PropDef("label", "Str", "", 0, 0, (), (), "Caption", False),
|
||||
PropDef("label-xalign", "Double", "0", 0, 1, (), (), "Alignment", False),
|
||||
PropDef("inset", "Int", "8", 0, 1000, (), (), "Inset", False),
|
||||
PropDef("top-inset", "Int", "14", 0, 1000, (), (), "TopInset", False),
|
||||
PropDef("shadow-type", "Enum", "3", 0, 0, ("None", "In", "Out", "Etched in", "Etched out"), (0, 1, 2, 3, 4), "Bevel", False),
|
||||
)
|
||||
|
||||
DATETIMEPICKER_PROPS = (
|
||||
PropDef("date", "Str", "", 0, 0, (), (), "Date", False),
|
||||
PropDef("show-heading", "Bool", "true", 0, 0, (), (), "ShowHeading", False),
|
||||
PropDef("show-day-names", "Bool", "true", 0, 0, (), (), "ShowDayNames", False),
|
||||
PropDef("show-week-numbers", "Bool", "false", 0, 0, (), (), "ShowWeekNumbers", False),
|
||||
PropDef("grid-color", "Color", "rgb(205,205,205)", 0, 0, (), (), "GridColor", False),
|
||||
PropDef("selected-fill-color", "Color", "rgb(52,101,164)", 0, 0, (), (), "SelectedFillColor", False),
|
||||
PropDef("selected-text-color", "Color", "rgb(255,255,255)", 0, 0, (), (), "SelectedTextColor", False),
|
||||
PropDef("today-color", "Color", "rgb(200,50,50)", 0, 0, (), (), "TodayColor", False),
|
||||
PropDef("dim-text-color", "Color", "rgb(110,110,110)", 0, 0, (), (), "DimTextColor", False),
|
||||
PropDef("weekends-color", "Color", "rgb(170,60,60)", 0, 0, (), (), "WeekendsColor", False),
|
||||
PropDef("disabled-color", "Color", "rgb(150,150,150)", 0, 0, (), (), "DisabledColor", False),
|
||||
)
|
||||
|
||||
CHECKBUTTON_PROPS = (
|
||||
PropDef("label", "Str", "", 0, 0, (), (), "Caption", False),
|
||||
PropDef("active", "Bool", "false", 0, 0, (), (), "Checked", False),
|
||||
PropDef("inconsistent", "Bool", "false", 0, 0, (), (), "State", False),
|
||||
PropDef("allow-grayed", "Bool", "false", 0, 0, (), (), "AllowGrayed", False),
|
||||
PropDef("alignment", "Enum", "0", 0, 0, ("Left", "Right"), (0, 1), "Alignment", False),
|
||||
PropDef("value-checked", "Str", "", 0, 0, (), (), "ValueChecked", True),
|
||||
PropDef("value-unchecked", "Str", "", 0, 0, (), (), "ValueUnchecked", True),
|
||||
)
|
||||
|
||||
COLORBOX_PROPS = (
|
||||
PropDef("color", "Color", "rgb(53,132,228)", 0, 0, (), (), "Selected", False),
|
||||
PropDef("style", "Enum", "0", 0, 0, ("Standard", "Extended", "System", "Custom"), (0, 1, 2, 3), "Style", True),
|
||||
PropDef("default-color", "Color", "rgb(255,255,255)", 0, 0, (), (), "DefaultColor", False),
|
||||
PropDef("none-color", "Color", "rgb(0,0,0)", 0, 0, (), (), "NoneColor", False),
|
||||
PropDef("use-alpha", "Bool", "false", 0, 0, (), (), "UseAlpha", False),
|
||||
PropDef("title", "Str", "", 0, 0, (), (), "Title", False),
|
||||
)
|
||||
|
||||
LISTVIEW_PROPS = (
|
||||
PropDef("columns", "Str", "Name|Value", 0, 0, (), (), "Columns", True),
|
||||
PropDef("items", "Str", "Row 1,Value 1;Row 2,Value 2", 0, 0, (), (), "Items", False),
|
||||
PropDef("headers-visible", "Bool", "true", 0, 0, (), (), "HeadersVisible", False),
|
||||
PropDef("item-index", "Int", "-1", -1, 100000, (), (), "ItemIndex", False),
|
||||
PropDef("item-height", "Int", "0", 0, 1000, (), (), "ItemHeight", False),
|
||||
PropDef("view-style", "Enum", "0", 0, 0, ("Report", "Icon", "SmallIcon", "List"), (0, 1, 2, 3), "ViewStyle", True),
|
||||
PropDef("grid-lines", "Bool", "false", 0, 0, (), (), "GridLines", False),
|
||||
PropDef("row-select", "Bool", "true", 0, 0, (), (), "RowSelect", False),
|
||||
PropDef("multi-select", "Bool", "false", 0, 0, (), (), "MultiSelect", False),
|
||||
PropDef("sort-type", "Enum", "0", 0, 0, ("None", "Ascending", "Descending"), (0, 1, 2), "SortType", True),
|
||||
)
|
||||
|
||||
COMBOBOX_PROPS = (
|
||||
PropDef("items", "Str", "Item 1|Item 2|Item 3", 0, 0, (), (), "Items", False),
|
||||
PropDef("active", "Int", "0", -1, 1000, (), (), "ItemIndex", False),
|
||||
PropDef("text", "Str", "", 0, 0, (), (), "Text", False),
|
||||
PropDef("style", "Enum", "0", 0, 0, ("DropDown", "Simple", "DropDownList"), (0, 1, 2), "Style", True),
|
||||
PropDef("drop-down-count", "Int", "8", 1, 100, (), (), "DropDownCount", True),
|
||||
PropDef("drop-down-width", "Int", "0", 0, 10000, (), (), "DropDownWidth", True),
|
||||
PropDef("sorted", "Bool", "false", 0, 0, (), (), "Sorted", True),
|
||||
PropDef("read-only", "Bool", "false", 0, 0, (), (), "ReadOnly", False),
|
||||
PropDef("max-length", "Int", "0", 0, 100000, (), (), "MaxLength", True),
|
||||
PropDef("auto-complete", "Bool", "false", 0, 0, (), (), "AutoComplete", True),
|
||||
PropDef("char-case", "Enum", "0", 0, 0, ("Normal", "Upper", "Lower"), (0, 1, 2), "CharCase", True),
|
||||
)
|
||||
|
||||
ENTRY_PROPS = (
|
||||
PropDef("text", "Str", "", 0, 0, (), (), "Text", False),
|
||||
PropDef("placeholder-text", "Str", "", 0, 0, (), (), "TextHint", False),
|
||||
PropDef("max-length", "Int", "0", 0, 100000, (), (), "MaxLength", True),
|
||||
PropDef("width-chars", "Int", "-1", -1, 1000, (), (), "WidthChars", True),
|
||||
PropDef("editable", "Bool", "true", 0, 0, (), (), "ReadOnly", False),
|
||||
PropDef("password", "Bool", "false", 0, 0, (), (), "PasswordChar", False),
|
||||
PropDef("show-password", "Bool", "false", 0, 0, (), (), "ShowPassword", False),
|
||||
PropDef("alignment", "Enum", "0", 0, 0, ("Left", "Center", "Right"), (0, 1, 2), "Alignment", False),
|
||||
PropDef("char-case", "Enum", "0", 0, 0, ("Normal", "Upper", "Lower"), (0, 1, 2), "CharCase", True),
|
||||
PropDef("numbers-only", "Bool", "false", 0, 0, (), (), "NumbersOnly", True),
|
||||
PropDef("hide-selection", "Bool", "false", 0, 0, (), (), "HideSelection", True),
|
||||
PropDef("auto-select", "Bool", "false", 0, 0, (), (), "AutoSelect", True),
|
||||
)
|
||||
|
||||
LISTBOX_PROPS = (
|
||||
PropDef("items", "Str", "Item 1|Item 2|Item 3", 0, 0, (), (), "Items", False),
|
||||
PropDef("selection-mode", "Enum", "1", 0, 0, ("None", "Single", "Browse", "Multiple"), (0, 1, 2, 3), "SelectionMode", False),
|
||||
PropDef("item-index", "Int", "-1", -1, 100000, (), (), "ItemIndex", False),
|
||||
PropDef("sorted", "Bool", "false", 0, 0, (), (), "Sorted", True),
|
||||
PropDef("columns", "Int", "1", 1, 100, (), (), "Columns", True),
|
||||
PropDef("item-height", "Int", "0", 0, 1000, (), (), "ItemHeight", False),
|
||||
PropDef("integral-height", "Bool", "false", 0, 0, (), (), "IntegralHeight", True),
|
||||
)
|
||||
|
||||
IMAGE_PROPS = (
|
||||
PropDef("file", "Str", "", 0, 0, (), (), "Picture", False),
|
||||
PropDef("pixel-size", "Int", "-1", -1, 512, (), (), "PixelSize", False),
|
||||
PropDef("stretch", "Bool", "false", 0, 0, (), (), "Stretch", False),
|
||||
PropDef("proportional", "Bool", "true", 0, 0, (), (), "Proportional", False),
|
||||
PropDef("center", "Bool", "true", 0, 0, (), (), "Center", False),
|
||||
PropDef("transparent", "Bool", "false", 0, 0, (), (), "Transparent", False),
|
||||
)
|
||||
|
||||
SCALE_PROPS = (
|
||||
PropDef("value", "Double", "0", 0, 100, (), (), "Position", False),
|
||||
PropDef("minimum", "Double", "0", -1000000, 1000000, (), (), "Min", False),
|
||||
PropDef("maximum", "Double", "100", -1000000, 1000000, (), (), "Max", False),
|
||||
PropDef("digits", "Int", "1", -1, 10, (), (), "DecimalPlaces", False),
|
||||
PropDef("draw-value", "Bool", "true", 0, 0, (), (), "DrawValue", False),
|
||||
PropDef("inverted", "Bool", "false", 0, 0, (), (), "Inverted", False),
|
||||
PropDef("page-step", "Double", "10", 0, 1000000, (), (), "PageSize", False),
|
||||
PropDef("tick-marks", "Enum", "0", 0, 0, ("None", "TopLeft", "BottomRight", "Both"), (0, 1, 2, 3), "TickMarks", False),
|
||||
PropDef("frequency", "Int", "10", 1, 1000000, (), (), "Frequency", False),
|
||||
PropDef("show-sel-range", "Bool", "false", 0, 0, (), (), "ShowSelRange", False),
|
||||
PropDef("sel-start", "Double", "0", -1000000, 1000000, (), (), "SelStart", False),
|
||||
PropDef("sel-end", "Double", "0", -1000000, 1000000, (), (), "SelEnd", False),
|
||||
)
|
||||
|
||||
MENUBAR_PROPS = (
|
||||
PropDef("menus", "Str", "File|Edit|Help", 0, 0, (), (), "Menus", False),
|
||||
)
|
||||
|
||||
MENUBUTTON_PROPS = (
|
||||
PropDef("label", "Str", "", 0, 0, (), (), "Caption", False),
|
||||
PropDef("direction", "Enum", "1", 0, 0, ("Up", "Down", "Left", "Right", "None"), (0, 1, 2, 3, 4), "Direction", False),
|
||||
)
|
||||
|
||||
MENUITEM_PROPS = (
|
||||
PropDef("label", "Str", "", 0, 0, (), (), "Caption", False),
|
||||
)
|
||||
|
||||
NOTEBOOK_PROPS = (
|
||||
PropDef("pages", "Str", "Tab 1|Tab 2|Tab 3", 0, 0, (), (), "Pages", False),
|
||||
PropDef("page", "Int", "0", 0, 100, (), (), "ActivePage", False),
|
||||
PropDef("tab-height", "Int", "26", 0, 1000, (), (), "TabHeight", False),
|
||||
PropDef("tab-position", "Enum", "0", 0, 0, ("Top", "Bottom", "Left", "Right"), (0, 1, 2, 3), "TabPosition", False),
|
||||
PropDef("tab-width", "Int", "0", 0, 1000, (), (), "TabWidth", False),
|
||||
)
|
||||
|
||||
SPLITTER_PROPS = (
|
||||
PropDef("position", "Int", "100", 0, 10000, (), (), "Position", False),
|
||||
PropDef("orientation", "Enum", "0", 0, 0, ("Horizontal", "Vertical"), (0, 1), "Kind", False),
|
||||
PropDef("min-size", "Int", "0", 0, 10000, (), (), "MinSize", True),
|
||||
PropDef("resize-style", "Enum", "0", 0, 0, ("Update", "Line"), (0, 1), "ResizeStyle", True),
|
||||
PropDef("auto-snap", "Bool", "false", 0, 0, (), (), "AutoSnap", True),
|
||||
)
|
||||
|
||||
PROGRESSBAR_PROPS = (
|
||||
PropDef("fraction", "Double", "0", 0, 1, (), (), "Fraction", False),
|
||||
PropDef("position", "Double", "45", -1000000, 1000000, (), (), "Position", False),
|
||||
PropDef("minimum", "Double", "0", -1000000, 1000000, (), (), "Min", False),
|
||||
PropDef("maximum", "Double", "100", -1000000, 1000000, (), (), "Max", False),
|
||||
PropDef("step", "Double", "1", 0, 1000000, (), (), "Step", False),
|
||||
PropDef("show-text", "Bool", "false", 0, 0, (), (), "BarShowText", False),
|
||||
PropDef("text", "Str", "", 0, 0, (), (), "Text", False),
|
||||
PropDef("pulsing", "Bool", "false", 0, 0, (), (), "Style", False),
|
||||
PropDef("inverted", "Bool", "false", 0, 0, (), (), "Inverted", False),
|
||||
PropDef("bar-color", "Color", "rgb(52,101,164)", 0, 0, (), (), "BarColor", False),
|
||||
PropDef("trough-color", "Color", "rgb(225,225,225)", 0, 0, (), (), "TroughColor", False),
|
||||
)
|
||||
|
||||
RADIOBUTTON_PROPS = (
|
||||
PropDef("label", "Str", "", 0, 0, (), (), "Caption", False),
|
||||
PropDef("active", "Bool", "false", 0, 0, (), (), "Checked", False),
|
||||
PropDef("group", "Int", "0", 0, 100000, (), (), "Group", True),
|
||||
)
|
||||
|
||||
SCROLLBAR_PROPS = (
|
||||
PropDef("value", "Double", "0", 0, 100, (), (), "Position", False),
|
||||
PropDef("lower", "Double", "0", -1000000, 1000000, (), (), "Min", False),
|
||||
PropDef("upper", "Double", "100", -1000000, 1000000, (), (), "Max", False),
|
||||
PropDef("step-increment", "Double", "1", 0, 1000000, (), (), "SmallChange", False),
|
||||
PropDef("page-increment", "Double", "10", 0, 1000000, (), (), "LargeChange", False),
|
||||
PropDef("page-size", "Double", "10", 0, 1000000, (), (), "PageSize", False),
|
||||
PropDef("inverted", "Bool", "false", 0, 0, (), (), "Inverted", False),
|
||||
PropDef("orientation", "Enum", "0", 0, 0, ("Horizontal", "Vertical"), (0, 1), "Kind", False),
|
||||
PropDef("large-change", "Double", "10", 0, 1000000, (), (), "large-change", False),
|
||||
)
|
||||
|
||||
SCROLLBOX_PROPS = (
|
||||
PropDef("label", "Str", "", 0, 0, (), (), "Caption", False),
|
||||
)
|
||||
|
||||
SPINEDIT_PROPS = (
|
||||
PropDef("minimum", "Int", "0", -1000000, 1000000, (), (), "Min", False),
|
||||
PropDef("maximum", "Int", "100", -1000000, 1000000, (), (), "Max", False),
|
||||
PropDef("step", "Int", "1", 1, 1000, (), (), "Increment", False),
|
||||
PropDef("value", "Double", "0", -1000000, 1000000, (), (), "Value", False),
|
||||
PropDef("digits", "Int", "0", 0, 10, (), (), "DecimalPlaces", False),
|
||||
PropDef("numeric", "Bool", "true", 0, 0, (), (), "numeric", True),
|
||||
PropDef("wrap", "Bool", "false", 0, 0, (), (), "WordWrap", False),
|
||||
PropDef("editor-enabled", "Bool", "true", 0, 0, (), (), "editor-enabled", True),
|
||||
)
|
||||
|
||||
STATUSBAR_PROPS = (
|
||||
PropDef("text", "Str", "", 0, 0, (), (), "Text", False),
|
||||
PropDef("panels", "Str", "", 0, 0, (), (), "Panels", False),
|
||||
PropDef("size-grip", "Bool", "true", 0, 0, (), (), "SizeGrip", False),
|
||||
)
|
||||
|
||||
TOGGLEBUTTON_PROPS = (
|
||||
PropDef("text", "Str", "", 0, 0, (), (), "Caption", False),
|
||||
PropDef("active", "Bool", "false", 0, 0, (), (), "Down", False),
|
||||
PropDef("group-index", "Int", "0", 0, 100000, (), (), "GroupIndex", True),
|
||||
PropDef("allow-all-up", "Bool", "false", 0, 0, (), (), "AllowAllUp", True),
|
||||
PropDef("flat", "Bool", "false", 0, 0, (), (), "Flat", False),
|
||||
PropDef("glyph", "Str", "", 0, 0, (), (), "Glyph", True),
|
||||
)
|
||||
|
||||
TEXT_PROPS = (
|
||||
PropDef("text", "Str", "", 0, 0, (), (), "Text", False),
|
||||
PropDef("editable", "Bool", "true", 0, 0, (), (), "ReadOnly", False),
|
||||
PropDef("cursor-visible", "Bool", "true", 0, 0, (), (), "CursorVisible", False),
|
||||
PropDef("wrap-mode", "Enum", "0", 0, 0, ("None", "Char", "Word", "Word-char"), (0, 1, 2, 3), "WordWrap", False),
|
||||
PropDef("max-length", "Int", "0", 0, 100000, (), (), "MaxLength", True),
|
||||
PropDef("scroll-bars", "Enum", "0", 0, 0, ("None", "Horizontal", "Vertical", "Both"), (0, 1, 2, 3), "ScrollBars", False),
|
||||
PropDef("want-tabs", "Bool", "true", 0, 0, (), (), "WantTabs", True),
|
||||
PropDef("want-returns", "Bool", "true", 0, 0, (), (), "WantReturns", True),
|
||||
PropDef("hide-selection", "Bool", "false", 0, 0, (), (), "HideSelection", True),
|
||||
PropDef("alignment", "Enum", "0", 0, 0, ("Left", "Center", "Right"), (0, 1, 2), "Alignment", False),
|
||||
)
|
||||
|
||||
TOOLBAR_PROPS = (
|
||||
PropDef("items", "Str", "New|Open|Save", 0, 0, (), (), "Items", False),
|
||||
PropDef("toolbar-style", "Enum", "2", 0, 0, ("Icons", "Text", "Both", "Both horizontal"), (0, 1, 2, 3), "Style", False),
|
||||
PropDef("show-captions", "Bool", "true", 0, 0, (), (), "ShowCaptions", False),
|
||||
PropDef("flat", "Bool", "false", 0, 0, (), (), "Flat", False),
|
||||
PropDef("button-width", "Int", "0", 0, 1000, (), (), "ButtonWidth", False),
|
||||
PropDef("button-height", "Int", "0", 0, 1000, (), (), "ButtonHeight", False),
|
||||
)
|
||||
|
||||
TREEVIEW_PROPS = (
|
||||
PropDef("items", "Str", "Root/Child 1;Root/Child 2;Other", 0, 0, (), (), "Items", False),
|
||||
PropDef("headers-visible", "Bool", "true", 0, 0, (), (), "HeadersVisible", False),
|
||||
PropDef("item-index", "Int", "-1", -1, 100000, (), (), "ItemIndex", False),
|
||||
PropDef("item-height", "Int", "0", 0, 1000, (), (), "ItemHeight", False),
|
||||
PropDef("header-height", "Int", "22", 0, 1000, (), (), "HeaderHeight", False),
|
||||
PropDef("grid-lines", "Bool", "false", 0, 0, (), (), "GridLines", False),
|
||||
PropDef("row-select", "Bool", "true", 0, 0, (), (), "RowSelect", False),
|
||||
PropDef("multi-select", "Bool", "false", 0, 0, (), (), "MultiSelect", False),
|
||||
PropDef("sort-type", "Enum", "0", 0, 0, ("None", "Ascending", "Descending"), (0, 1, 2), "SortType", True),
|
||||
PropDef("indent", "Int", "16", 0, 1000, (), (), "Indent", False),
|
||||
PropDef("show-buttons", "Bool", "true", 0, 0, (), (), "ShowButtons", False),
|
||||
PropDef("show-lines", "Bool", "true", 0, 0, (), (), "ShowLines", False),
|
||||
PropDef("show-root", "Bool", "true", 0, 0, (), (), "ShowRoot", False),
|
||||
)
|
||||
|
||||
PANEL_PROPS = (
|
||||
PropDef("label", "Str", "", 0, 0, (), (), "Caption", False),
|
||||
PropDef("label-xalign", "Double", "0", 0, 1, (), (), "Alignment", False),
|
||||
PropDef("inset", "Int", "8", 0, 1000, (), (), "Inset", False),
|
||||
PropDef("top-inset", "Int", "14", 0, 1000, (), (), "TopInset", False),
|
||||
PropDef("shadow-type", "Enum", "3", 0, 0, ("None", "In", "Out", "Etched in", "Etched out"), (0, 1, 2, 3, 4), "Bevel", False),
|
||||
)
|
||||
|
||||
CHECKLISTBOX_PROPS = (
|
||||
PropDef("items", "Str", "Item 1|Item 2|Item 3", 0, 0, (), (), "Items", False),
|
||||
PropDef("checked-items", "Str", "", 0, 0, (), (), "Checked", False),
|
||||
PropDef("item-index", "Int", "-1", -1, 100000, (), (), "ItemIndex", False),
|
||||
PropDef("item-height", "Int", "0", 0, 1000, (), (), "ItemHeight", False),
|
||||
PropDef("sorted", "Bool", "false", 0, 0, (), (), "Sorted", True),
|
||||
)
|
||||
|
||||
STRINGGRID_PROPS = (
|
||||
PropDef("rows", "Int", "5", 1, 50, (), (), "RowCount", False),
|
||||
PropDef("columns", "Int", "4", 1, 26, (), (), "Columns", True),
|
||||
PropDef("headers-visible", "Bool", "true", 0, 0, (), (), "HeadersVisible", False),
|
||||
PropDef("fixed-cols", "Int", "0", 0, 26, (), (), "FixedCols", False),
|
||||
PropDef("fixed-rows", "Int", "0", 0, 50, (), (), "FixedRows", False),
|
||||
PropDef("default-col-width", "Int", "84", 1, 1000, (), (), "DefaultColWidth", False),
|
||||
PropDef("default-row-height", "Int", "20", 1, 1000, (), (), "DefaultRowHeight", False),
|
||||
PropDef("grid-line-width", "Int", "1", 0, 100, (), (), "GridLineWidth", False),
|
||||
)
|
||||
|
||||
GROUPBOX_PROPS = (
|
||||
PropDef("label", "Str", "", 0, 0, (), (), "Caption", False),
|
||||
PropDef("label-xalign", "Double", "0", 0, 1, (), (), "Alignment", False),
|
||||
PropDef("inset", "Int", "8", 0, 1000, (), (), "Inset", False),
|
||||
PropDef("top-inset", "Int", "14", 0, 1000, (), (), "TopInset", False),
|
||||
PropDef("shadow-type", "Enum", "3", 0, 0, ("None", "In", "Out", "Etched in", "Etched out"), (0, 1, 2, 3, 4), "Bevel", False),
|
||||
)
|
||||
|
||||
MEMO_PROPS = (
|
||||
PropDef("text", "Str", "", 0, 0, (), (), "Text", False),
|
||||
PropDef("editable", "Bool", "true", 0, 0, (), (), "ReadOnly", False),
|
||||
PropDef("cursor-visible", "Bool", "true", 0, 0, (), (), "CursorVisible", False),
|
||||
PropDef("wrap-mode", "Enum", "0", 0, 0, ("None", "Char", "Word", "Word-char"), (0, 1, 2, 3), "WordWrap", False),
|
||||
PropDef("max-length", "Int", "0", 0, 100000, (), (), "MaxLength", True),
|
||||
PropDef("scroll-bars", "Enum", "3", 0, 0, ("None", "Horizontal", "Vertical", "Both"), (0, 1, 2, 3), "ScrollBars", False),
|
||||
PropDef("want-tabs", "Bool", "true", 0, 0, (), (), "WantTabs", True),
|
||||
PropDef("want-returns", "Bool", "true", 0, 0, (), (), "WantReturns", True),
|
||||
PropDef("hide-selection", "Bool", "false", 0, 0, (), (), "HideSelection", True),
|
||||
PropDef("alignment", "Enum", "0", 0, 0, ("Left", "Center", "Right"), (0, 1, 2), "Alignment", False),
|
||||
)
|
||||
|
||||
SHAPE_PROPS = (
|
||||
PropDef("shape", "Enum", "0", 0, 0, ("Rectangle", "Square", "RoundRect", "RoundSquare", "Ellipse", "Circle", "Triangle", "Diamond", "Pentagon", "Hexagon"), (0, 1, 2, 3, 4, 5, 6, 7, 8, 9), "Shape", False),
|
||||
PropDef("fill-color", "Color", "rgb(70,130,200)", 0, 0, (), (), "FillColor", False),
|
||||
PropDef("pen-color", "Color", "rgb(20,40,80)", 0, 0, (), (), "PenColor", False),
|
||||
PropDef("pen-width", "Int", "2", 1, 100, (), (), "PenWidth", False),
|
||||
)
|
||||
|
||||
TRACKBAR_PROPS = (
|
||||
PropDef("minimum", "Int", "0", -1000000, 1000000, (), (), "Min", False),
|
||||
PropDef("maximum", "Int", "100", -1000000, 1000000, (), (), "Max", False),
|
||||
PropDef("step", "Int", "1", 1, 1000, (), (), "Step", False),
|
||||
PropDef("value", "Double", "0", 0, 100, (), (), "Position", False),
|
||||
PropDef("digits", "Int", "1", 0, 10, (), (), "DecimalPlaces", False),
|
||||
PropDef("draw-value", "Bool", "true", 0, 0, (), (), "DrawValue", False),
|
||||
PropDef("inverted", "Bool", "false", 0, 0, (), (), "Inverted", False),
|
||||
PropDef("orientation", "Enum", "0", 0, 0, ("Horizontal", "Vertical"), (0, 1), "Kind", False),
|
||||
PropDef("page-step", "Double", "10", 0, 1000000, (), (), "PageSize", False),
|
||||
PropDef("tick-marks", "Enum", "0", 0, 0, ("None", "TopLeft", "BottomRight", "Both"), (0, 1, 2, 3), "TickMarks", False),
|
||||
PropDef("frequency", "Int", "10", 1, 1000000, (), (), "Frequency", False),
|
||||
PropDef("show-sel-range", "Bool", "false", 0, 0, (), (), "ShowSelRange", False),
|
||||
PropDef("sel-start", "Double", "0", -1000000, 1000000, (), (), "SelStart", False),
|
||||
PropDef("sel-end", "Double", "0", -1000000, 1000000, (), (), "SelEnd", False),
|
||||
)
|
||||
|
||||
PLOT_PROPS = (
|
||||
PropDef("title", "Str", "", 0, 0, (), (), "Title", False),
|
||||
PropDef("line-color", "Color", "rgb(220,0,0)", 0, 0, (), (), "LineColor", False),
|
||||
)
|
||||
|
||||
SPREADSHEET_PROPS = (
|
||||
PropDef("rows", "Int", "5", 1, 50, (), (), "RowCount", False),
|
||||
PropDef("columns", "Int", "4", 1, 26, (), (), "Columns", True),
|
||||
PropDef("fixed-cols", "Int", "0", 0, 26, (), (), "FixedCols", False),
|
||||
PropDef("fixed-rows", "Int", "0", 0, 50, (), (), "FixedRows", False),
|
||||
PropDef("default-col-width", "Int", "84", 1, 1000, (), (), "DefaultColWidth", False),
|
||||
PropDef("default-row-height", "Int", "20", 1, 1000, (), (), "DefaultRowHeight", False),
|
||||
PropDef("grid-line-width", "Int", "1", 0, 100, (), (), "GridLineWidth", False),
|
||||
)
|
||||
|
||||
# palette kind -> custom (non-generic) props tuple
|
||||
CUSTOM_PROPS = {
|
||||
"AboutDialog": DIALOG_PROPS,
|
||||
"AccelLabel": LABEL_PROPS,
|
||||
"AppChooserButton": BUTTON_PROPS,
|
||||
"AppChooserDialog": DIALOG_PROPS,
|
||||
"ApplicationWindow": TOPLEVEL_PROPS,
|
||||
"AspectFrame": FRAME_PROPS,
|
||||
"Assistant": DIALOG_PROPS,
|
||||
"Button": BUTTON_PROPS,
|
||||
"Calendar": DATETIMEPICKER_PROPS,
|
||||
"CheckButton": CHECKBUTTON_PROPS,
|
||||
"CheckMenuItem": CHECKBUTTON_PROPS,
|
||||
"ColorButton": COLORBOX_PROPS,
|
||||
"ColorChooserDialog": DIALOG_PROPS,
|
||||
"ColorChooserWidget": COLORBOX_PROPS,
|
||||
"ColorDialogButton": COLORBOX_PROPS,
|
||||
"ColumnView": LISTVIEW_PROPS,
|
||||
"ComboBox": COMBOBOX_PROPS,
|
||||
"ComboBoxText": COMBOBOX_PROPS,
|
||||
"Dialog": DIALOG_PROPS,
|
||||
"DropDown": COMBOBOX_PROPS,
|
||||
"EditableLabel": ENTRY_PROPS,
|
||||
"Entry": ENTRY_PROPS,
|
||||
"EntryCompletion": COMBOBOX_PROPS,
|
||||
"FileChooserButton": BUTTON_PROPS,
|
||||
"FileChooserDialog": DIALOG_PROPS,
|
||||
"FlowBox": LISTBOX_PROPS,
|
||||
"FontButton": BUTTON_PROPS,
|
||||
"FontChooserDialog": DIALOG_PROPS,
|
||||
"Frame": FRAME_PROPS,
|
||||
"GridView": LISTVIEW_PROPS,
|
||||
"IconView": LISTVIEW_PROPS,
|
||||
"Image": IMAGE_PROPS,
|
||||
"Inscription": LABEL_PROPS,
|
||||
"Label": LABEL_PROPS,
|
||||
"LevelBar": SCALE_PROPS,
|
||||
"LinkButton": BUTTON_PROPS,
|
||||
"ListBox": LISTBOX_PROPS,
|
||||
"ListView": LISTVIEW_PROPS,
|
||||
"LockButton": BUTTON_PROPS,
|
||||
"Menu": MENUBAR_PROPS,
|
||||
"MenuBar": MENUBAR_PROPS,
|
||||
"MenuButton": MENUBUTTON_PROPS,
|
||||
"MenuItem": MENUITEM_PROPS,
|
||||
"MessageDialog": DIALOG_PROPS,
|
||||
"ModelButton": BUTTON_PROPS,
|
||||
"Notebook": NOTEBOOK_PROPS,
|
||||
"Paned": SPLITTER_PROPS,
|
||||
"PasswordEntry": ENTRY_PROPS,
|
||||
"Picture": IMAGE_PROPS,
|
||||
"PlacesSidebar": LISTBOX_PROPS,
|
||||
"PrintUnixDialog": DIALOG_PROPS,
|
||||
"ProgressBar": PROGRESSBAR_PROPS,
|
||||
"RadioButton": RADIOBUTTON_PROPS,
|
||||
"RadioMenuItem": RADIOBUTTON_PROPS,
|
||||
"Scale": SCALE_PROPS,
|
||||
"ScaleButton": SCALE_PROPS,
|
||||
"Scrollbar": SCROLLBAR_PROPS,
|
||||
"ScrolledWindow": SCROLLBOX_PROPS,
|
||||
"SearchEntry": ENTRY_PROPS,
|
||||
"ShortcutsWindow": DIALOG_PROPS,
|
||||
"SpinButton": SPINEDIT_PROPS,
|
||||
"StackSidebar": LISTBOX_PROPS,
|
||||
"StackSwitcher": LISTBOX_PROPS,
|
||||
"Statusbar": STATUSBAR_PROPS,
|
||||
"Switch": TOGGLEBUTTON_PROPS,
|
||||
"TextView": TEXT_PROPS,
|
||||
"ToggleButton": TOGGLEBUTTON_PROPS,
|
||||
"ToggleToolButton": BUTTON_PROPS,
|
||||
"ToolButton": BUTTON_PROPS,
|
||||
"Toolbar": TOOLBAR_PROPS,
|
||||
"TreeView": TREEVIEW_PROPS,
|
||||
"VolumeButton": BUTTON_PROPS,
|
||||
"Window": TOPLEVEL_PROPS,
|
||||
"BitBtn": BUTTON_PROPS,
|
||||
"Button": BUTTON_PROPS,
|
||||
"ButtonPanel": PANEL_PROPS,
|
||||
"CalcEdit": ENTRY_PROPS,
|
||||
"CalculatorDialog": DIALOG_PROPS,
|
||||
"Calendar": DATETIMEPICKER_PROPS,
|
||||
"CalendarDialog": DIALOG_PROPS,
|
||||
"CheckBox": CHECKBUTTON_PROPS,
|
||||
"CheckComboBox": COMBOBOX_PROPS,
|
||||
"CheckGroup": LISTBOX_PROPS,
|
||||
"CheckListBox": CHECKLISTBOX_PROPS,
|
||||
"ColorBox": COLORBOX_PROPS,
|
||||
"ColorButton": COLORBOX_PROPS,
|
||||
"ColorDialog": DIALOG_PROPS,
|
||||
"ColorListBox": COLORBOX_PROPS,
|
||||
"ComboBox": COMBOBOX_PROPS,
|
||||
"ComboBoxEx": COMBOBOX_PROPS,
|
||||
"ControlBar": TOOLBAR_PROPS,
|
||||
"CoolBar": TOOLBAR_PROPS,
|
||||
"DateEdit": ENTRY_PROPS,
|
||||
"DateTimePicker": DATETIMEPICKER_PROPS,
|
||||
"DirectoryEdit": ENTRY_PROPS,
|
||||
"DrawGrid": STRINGGRID_PROPS,
|
||||
"Edit": ENTRY_PROPS,
|
||||
"EditButton": BUTTON_PROPS,
|
||||
"FileListBox": LISTBOX_PROPS,
|
||||
"FileNameEdit": ENTRY_PROPS,
|
||||
"FilterComboBox": COMBOBOX_PROPS,
|
||||
"FindDialog": DIALOG_PROPS,
|
||||
"FloatSpinEdit": SPINEDIT_PROPS,
|
||||
"FontDialog": DIALOG_PROPS,
|
||||
"Form": TOPLEVEL_PROPS,
|
||||
"Frame": FRAME_PROPS,
|
||||
"GroupBox": GROUPBOX_PROPS,
|
||||
"HeaderControl": TOOLBAR_PROPS,
|
||||
"Image": IMAGE_PROPS,
|
||||
"Label": LABEL_PROPS,
|
||||
"LabeledEdit": ENTRY_PROPS,
|
||||
"ListBox": LISTBOX_PROPS,
|
||||
"ListView": LISTVIEW_PROPS,
|
||||
"MainMenu": MENUBAR_PROPS,
|
||||
"MaskEdit": ENTRY_PROPS,
|
||||
"Memo": MEMO_PROPS,
|
||||
"Notebook": NOTEBOOK_PROPS,
|
||||
"OpenDialog": DIALOG_PROPS,
|
||||
"OpenPictureDialog": DIALOG_PROPS,
|
||||
"PageControl": NOTEBOOK_PROPS,
|
||||
"PageSetupDialog": DIALOG_PROPS,
|
||||
"PairSplitter": SPLITTER_PROPS,
|
||||
"Panel": PANEL_PROPS,
|
||||
"PopupMenu": MENUBAR_PROPS,
|
||||
"PrintDialog": DIALOG_PROPS,
|
||||
"PrinterSetupDialog": DIALOG_PROPS,
|
||||
"ProgressBar": PROGRESSBAR_PROPS,
|
||||
"RadioButton": RADIOBUTTON_PROPS,
|
||||
"RadioGroup": LISTBOX_PROPS,
|
||||
"ReplaceDialog": DIALOG_PROPS,
|
||||
"SaveDialog": DIALOG_PROPS,
|
||||
"SavePictureDialog": DIALOG_PROPS,
|
||||
"ScrollBar": SCROLLBAR_PROPS,
|
||||
"ScrollBox": SCROLLBOX_PROPS,
|
||||
"SelectDirectoryDialog": DIALOG_PROPS,
|
||||
"Shape": SHAPE_PROPS,
|
||||
"ShellListView": LISTVIEW_PROPS,
|
||||
"ShellTreeView": TREEVIEW_PROPS,
|
||||
"SpeedButton": TOGGLEBUTTON_PROPS,
|
||||
"SpinEdit": SPINEDIT_PROPS,
|
||||
"Splitter": SPLITTER_PROPS,
|
||||
"StaticText": LABEL_PROPS,
|
||||
"StatusBar": STATUSBAR_PROPS,
|
||||
"StringGrid": STRINGGRID_PROPS,
|
||||
"TabControl": NOTEBOOK_PROPS,
|
||||
"TaskDialog": DIALOG_PROPS,
|
||||
"TimeEdit": ENTRY_PROPS,
|
||||
"ToggleBox": TOGGLEBUTTON_PROPS,
|
||||
"ToolBar": TOOLBAR_PROPS,
|
||||
"TrackBar": TRACKBAR_PROPS,
|
||||
"TreeView": TREEVIEW_PROPS,
|
||||
"UpDown": SPINEDIT_PROPS,
|
||||
"ValueListEditor": STRINGGRID_PROPS,
|
||||
"XGraph": PLOT_PROPS,
|
||||
"XSpreadsheet": SPREADSHEET_PROPS,
|
||||
}
|
||||
|
||||
# Registry names (GtkButton, TButton, ...) resolve through
|
||||
# the palette; this is the kind-level custom table only.
|
||||
_CUSTOM_BY_KIND = dict(CUSTOM_PROPS)
|
||||
|
||||
|
||||
def props_for(kind_or_name):
|
||||
"""Full table (generic + custom) for a palette kind or
|
||||
a registry name (e.g. "GtkButton" or "Button").
|
||||
Unknown names get the generic set only."""
|
||||
kind = _resolve_kind(kind_or_name)
|
||||
custom = _CUSTOM_BY_KIND.get(kind, ())
|
||||
seen = {p.name for p in custom}
|
||||
return tuple(p for p in GENERIC_PROPS
|
||||
if p.name not in seen) + tuple(custom)
|
||||
|
||||
|
||||
def custom_props_for(kind_or_name):
|
||||
"""Custom (non-generic) props only, or () if none."""
|
||||
return _CUSTOM_BY_KIND.get(_resolve_kind(kind_or_name), ())
|
||||
|
||||
|
||||
def prop_names(kind_or_name):
|
||||
return frozenset(p.name for p in props_for(kind_or_name))
|
||||
|
||||
|
||||
def find_prop(kind_or_name, name):
|
||||
for prop in props_for(kind_or_name):
|
||||
if prop.name == name:
|
||||
return prop
|
||||
return None
|
||||
|
||||
|
||||
def is_model_only(kind_or_name, name):
|
||||
prop = find_prop(kind_or_name, name)
|
||||
return bool(prop.model_only) if prop is not None else False
|
||||
|
||||
|
||||
def register_custom_table(kind, props):
|
||||
"""Add/replace the custom table for one palette kind.
|
||||
Phase 6 uses this for the Stock / Instrumentation
|
||||
families; it never touches the generated tables."""
|
||||
_CUSTOM_BY_KIND[str(kind)] = tuple(props)
|
||||
|
||||
|
||||
def _resolve_kind(kind_or_name):
|
||||
name = str(kind_or_name)
|
||||
if name in _CUSTOM_BY_KIND or name in _ALL_KINDS:
|
||||
return name
|
||||
try:
|
||||
from lightgui.xframe import palette as _palette
|
||||
entry = _palette.find(name)
|
||||
if entry is not None:
|
||||
return entry.kind
|
||||
except Exception:
|
||||
pass
|
||||
return name
|
||||
|
||||
|
||||
def validate(kind_or_name, name, value):
|
||||
"""Validate *value* against the table for *kind* and
|
||||
return its canonical string form. Raises ValueError
|
||||
for an unknown prop, a bad bool/int/double, an enum
|
||||
label or value outside its range."""
|
||||
prop = find_prop(kind_or_name, name)
|
||||
if prop is None:
|
||||
raise ValueError("unknown property %r for %r"
|
||||
% (name, kind_or_name))
|
||||
return _canonical(prop, value)
|
||||
|
||||
|
||||
def _canonical(prop, value):
|
||||
kind = prop.kind
|
||||
if kind == "Bool":
|
||||
if isinstance(value, bool):
|
||||
return "true" if value else "false"
|
||||
text = str(value).strip().lower()
|
||||
if text in ("true", "1", "yes", "on"):
|
||||
return "true"
|
||||
if text in ("false", "0", "no", "off"):
|
||||
return "false"
|
||||
raise ValueError("not a bool: %r" % (value,))
|
||||
if kind == "Int":
|
||||
try:
|
||||
number = int(str(value).strip())
|
||||
except (TypeError, ValueError):
|
||||
raise ValueError("not an int: %r" % (value,))
|
||||
if prop.lo or prop.hi:
|
||||
if number < prop.lo or number > prop.hi:
|
||||
raise ValueError(
|
||||
"%s out of range %d..%d: %r"
|
||||
% (prop.name, prop.lo, prop.hi, value))
|
||||
return str(number)
|
||||
if kind == "Double":
|
||||
try:
|
||||
number = float(str(value).strip())
|
||||
except (TypeError, ValueError):
|
||||
raise ValueError("not a number: %r" % (value,))
|
||||
if prop.lo or prop.hi:
|
||||
if number < prop.lo or number > prop.hi:
|
||||
raise ValueError(
|
||||
"%s out of range %s..%s: %r"
|
||||
% (prop.name, prop.lo, prop.hi, value))
|
||||
return "%g" % number
|
||||
if kind == "Enum":
|
||||
text = str(value).strip()
|
||||
if prop.enum_labels and text in prop.enum_labels:
|
||||
return str(prop.enum_values[
|
||||
prop.enum_labels.index(text)]
|
||||
if prop.enum_values else text)
|
||||
try:
|
||||
number = int(text)
|
||||
except ValueError:
|
||||
raise ValueError("not an enum value: %r" % (value,))
|
||||
if prop.enum_values and number not in prop.enum_values:
|
||||
raise ValueError("enum value out of range: %r"
|
||||
% (value,))
|
||||
return str(number)
|
||||
if kind == "Color":
|
||||
return _canonical_color(str(value))
|
||||
return "" if value is None else str(value)
|
||||
|
||||
|
||||
def _canonical_color(text):
|
||||
text = text.strip()
|
||||
if not text:
|
||||
return ""
|
||||
if text.startswith("#") and len(text) in (4, 7, 9):
|
||||
digits = text[1:]
|
||||
if all(c in "0123456789abcdefABCDEF" for c in digits):
|
||||
return text.lower()
|
||||
match = re.match(r"rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)",
|
||||
text)
|
||||
if match:
|
||||
r, g, b = (int(v) for v in match.groups())
|
||||
if max(r, g, b) <= 255:
|
||||
return "rgb(%d,%d,%d)" % (r, g, b)
|
||||
if text.lower() in _NAMED_COLORS:
|
||||
return text.lower()
|
||||
raise ValueError("not a color: %r" % (text,))
|
||||
|
||||
|
||||
_NAMED_COLORS = frozenset([
|
||||
"black", "white", "red", "green", "blue", "yellow",
|
||||
"orange", "purple", "teal", "magenta", "brown", "gray",
|
||||
"grey", "pink", "cyan", "transparent"])
|
||||
|
||||
_ALL_KINDS = frozenset(("AboutDialog", "AccelLabel", "ActionBar", "AppChooserButton", "AppChooserDialog", "AppChooserWidget", "ApplicationWindow", "AspectFrame", "Assistant", "Box", "Button", "ButtonBox", "Calendar", "CellView", "CenterBox", "CheckButton", "CheckMenuItem", "ColorButton", "ColorChooserDialog", "ColorChooserWidget", "ColorDialogButton", "ColumnView", "ComboBox", "ComboBoxText", "Dialog", "DrawingArea", "DropDown", "EditableLabel", "Entry", "EntryCompletion", "EventBox", "Expander", "FileChooserButton", "FileChooserDialog", "FileChooserWidget", "Fixed", "FlowBox", "FontButton", "FontChooserDialog", "FontChooserWidget", "Frame", "GLArea", "Grid", "GridView", "HeaderBar", "IconView", "Image", "InfoBar", "Inscription", "Invisible", "Label", "Layout", "LevelBar", "LinkButton", "ListBox", "ListView", "LockButton", "MediaControls", "Menu", "MenuBar", "MenuButton", "MenuItem", "MessageDialog", "ModelButton", "Notebook", "Overlay", "Paned", "PasswordEntry", "Picture", "PlacesSidebar", "Popover", "PrintUnixDialog", "ProgressBar", "RadioButton", "RadioMenuItem", "Revealer", "Scale", "ScaleButton", "Scrollbar", "ScrolledWindow", "SearchBar", "SearchEntry", "Separator", "SeparatorMenuItem", "ShortcutsWindow", "SpinButton", "Spinner", "Stack", "StackSidebar", "StackSwitcher", "Statusbar", "Switch", "TextView", "ToggleButton", "ToggleToolButton", "ToolButton", "Toolbar", "TreeView", "Video", "Viewport", "VolumeButton", "Window", "ADX", "ADXR", "ALMA", "APO", "ATR", "Accelerator Oscillator", "A/D Line", "Accumulative Swing Index", "Cyber Cycle", "RSI", "Alligator", "Alligator", "Alligator", "VWAP", "Aroon", "Aroon Oscillator", "Aroon", "autocorrelation", "Awesome Oscillator", "Balance of Power", "Bear Power", "Bollinger Bands", "Bollinger Bandwidth", "Bollinger %B", "Bull Power", "CCI", "Pivot Points Camarilla", "CG Oscillator", "Chaikin Money Flow", "Chaikin Oscillator", "Chaikin Volatility", "Forecast Oscillator", "chande_kroll_stop", "CMO", "Chandelier Exit", "Chandelier Exit", "Chandelier Exit", "Ichimoku", "Choppiness Index", "close_volatility", "Connors RSI", "Coppock Curve", "correlation", "correlation_coefficient", "covariance", "cumulative_volume_delta", "RSI", "Cyber Cycle", "DEMA", "DPO", "d_s_s", "DX", "DeMarker", "Decycler", "Demand Index", "DPO", "Disparity Index", "Cyber Cycle", "HT DC Period", "Donchian Channels", "Donchian Channels", "Donchian Channels", "Donchian Channels", "double_stochastic", "Momentum", "EMA", "Ease of Movement", "Efficiency Ratio", "Decycler", "RSI", "Super Smoother", "HT Trendline", "Force Index", "Elder Impulse", "Bear Power", "Bull Power", "elder_safe_zone", "TSI", "even_better_sine_wave", "FAMA", "FRAMA", "Pivot Points Fibonacci", "Fisher Transform", "fractal_dimension", "Polarized Fractal Efficiency", "Williams Fractals", "Williams Fractals", "gann_hi_lo_activator", "gann_swing_oscillator", "Garman-Klass Volatility", "Gator Oscillator", "Gaussian Filter", "gopalakrishnan_range_index", "Guppy MMA", "HMA", "half_trend", "high_low_range", "Historical Volatility", "hurst_exponent", "inertia", "Intraday Intensity", "Momentum", "Fisher Transform", "Jurik MA", "jurik_velocity", "KAMA", "k_d_j", "KST", "kairi", "keltner_bandwidth", "Keltner Channels", "Ichimoku", "Klinger Oscillator", "Kurtosis", "LSMA", "Laguerre Filter", "Laguerre RSI", "TSF", "Linear Regression Angle", "Linear Regression Intercept", "Linear Regression Slope", "TSF", "Linear Regression Intercept", "Forecast Oscillator", "Linear Regression Slope", "MACD", "MACD Histogram", "RSI", "MA Envelope", "MA Envelope", "MAMA", "Mass Index", "McGinley Dynamic", "median_m_a", "Median Price", "Minus DI", "Momentum", "MFI", "money_flow_volume", "moving_average_ribbon", "NATR", "NVI", "ROC", "OBV", "PPO", "Parabolic SAR", "Parkinson Volatility", "percent_rank", "Volume", "percentile_rank", "Pivot Points Standard", "Plus DI", "PVI", "pretty_good_oscillator", "Momentum", "Qstick", "SMMA", "ROC", "ROC", "RSI", "RSI", "R-Squared", "Random Walk Index", "Random Walk Index", "rainbow_oscillator", "range_expansion_index", "reflex", "Linear Regression Channel", "RMI", "Relative Vigor Index", "Relative Volatility Index", "Volume", "Rogers-Satchell Volatility", "Roofing Filter", "SMA", "SMI", "SMMA", "s_s_l_channel", "Schaff Trend Cycle", "Ichimoku", "Ichimoku", "shannon_entropy", "WMA", "HT Sine", "Skewness", "ROC", "spearman_rank", "special_k", "Standard Error", "Pivot Points Standard", "Standard Deviation", "Stochastic RSI", "Stochastic Fast", "Stochastic Full", "stochastic_pop", "Stochastic Slow", "Super Smoother", "Supertrend", "swenlin_trading_oscillator", "Swing Index", "T3", "t_d_sequential", "TEMA", "TRIMA", "TRIX", "TSF", "TSI", "t_s_m_a", "Squeeze Momentum", "Ichimoku", "trend_flex", "Trend Intensity Index", "True Range", "Twiggs Money Flow", "Typical Price", "u_t_bot", "Ulcer Index", "Ultimate Oscillator", "up_down_ratio", "up_down_volume_ratio", "VHF", "VIDYA", "VWAP", "VWAP Bands", "v_w_e_m_a", "VWMA", "Variance", "Line truncated
|
||||
|
||||
@@ -0,0 +1,700 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate lightgui/props.py from the C property tables.
|
||||
|
||||
Sources (read, never modified):
|
||||
/opt/lightgui/src/props.h -- common_props() + props_for() tables
|
||||
/opt/lightgui_python/lightgui/xframe/palette.py -- the 547 palette kinds
|
||||
|
||||
The generated file keeps the C tables verbatim (internal GTK-era names,
|
||||
kinds, defaults, ranges, enum labels/values -- proposal SS5.3) and adds:
|
||||
* the generic set on EVERY palette kind (Name + geometry + the C
|
||||
common set, plus the Lazarus BorderSpacing sub-props that have no C
|
||||
counterpart, flagged model-only),
|
||||
* a per-kind custom table, by mapping each palette kind onto the C
|
||||
table for its family (KIND_TABLE below),
|
||||
* a Lazarus display name per prop and a model_only flag (props that
|
||||
are stored in the model and emitted by the generator as comments
|
||||
but do not change the live canvas widget),
|
||||
* an EVENTS list (Lazarus names, per proposal SS4.10),
|
||||
* register_custom_table() so Phase 6 can add the Stock /
|
||||
Instrumentation tables later without touching this generator.
|
||||
|
||||
Stock (37) and Instrumentation (66) kinds get the generic set only in
|
||||
Phase 2; their per-widget tables are Phase 6 work.
|
||||
|
||||
Re-run: python3 tools/gen_props.py (from the repo root)
|
||||
"""
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
REPO = Path(__file__).resolve().parent.parent
|
||||
C_PROPS = Path("/opt/lightgui/src/props.h")
|
||||
|
||||
# --- curated: palette kind -> C props_for() table name -------------------
|
||||
# Keyed by palette `kind` (palette.py), not by registry name: GtkButton
|
||||
# and TButton both have kind "Button" and share the table.
|
||||
KIND_TABLE = {
|
||||
"Button": "button", "BitBtn": "button",
|
||||
"AppChooserButton": "button", "FileChooserButton": "button",
|
||||
"FontButton": "button", "LinkButton": "button", "LockButton": "button",
|
||||
"ModelButton": "button", "ToolButton": "button",
|
||||
"ToggleToolButton": "button", "VolumeButton": "button",
|
||||
"EditButton": "button",
|
||||
"ColorButton": "colorbox", "ColorDialogButton": "colorbox",
|
||||
"ColorBox": "colorbox", "ColorListBox": "colorbox",
|
||||
"Label": "label", "AccelLabel": "label", "Inscription": "label",
|
||||
"StaticText": "label",
|
||||
"Entry": "entry", "Edit": "entry", "CalcEdit": "entry",
|
||||
"DateEdit": "entry", "DirectoryEdit": "entry", "FileNameEdit": "entry",
|
||||
"LabeledEdit": "entry", "MaskEdit": "entry", "TimeEdit": "entry",
|
||||
"SearchEntry": "entry", "PasswordEntry": "entry",
|
||||
"EditableLabel": "entry",
|
||||
"CheckButton": "checkbutton", "CheckBox": "checkbutton",
|
||||
"CheckMenuItem": "checkbutton",
|
||||
"RadioButton": "radiobutton", "RadioMenuItem": "radiobutton",
|
||||
"ToggleButton": "togglebutton", "ToggleBox": "togglebutton",
|
||||
"SpeedButton": "togglebutton",
|
||||
"Frame": "frame", "AspectFrame": "frame",
|
||||
"GroupBox": "groupbox", "Panel": "panel", "ButtonPanel": "panel",
|
||||
"ComboBox": "combobox", "ComboBoxText": "combobox",
|
||||
"ComboBoxEx": "combobox", "CheckComboBox": "combobox",
|
||||
"FilterComboBox": "combobox", "DropDown": "combobox",
|
||||
"ListBox": "listbox", "CheckGroup": "listbox", "FileListBox": "listbox",
|
||||
"RadioGroup": "listbox",
|
||||
"CheckListBox": "checklistbox",
|
||||
"MenuButton": "menubutton",
|
||||
"Scale": "scale", "LevelBar": "scale",
|
||||
"TrackBar": "trackbar",
|
||||
"Scrollbar": "scrollbar", "ScrollBar": "scrollbar",
|
||||
"SpinButton": "spinedit", "SpinEdit": "spinedit",
|
||||
"FloatSpinEdit": "spinedit", "UpDown": "spinedit",
|
||||
"TextView": "text", "Memo": "memo",
|
||||
"Image": "image", "Picture": "image",
|
||||
"Shape": "shape",
|
||||
"Notebook": "notebook", "PageControl": "notebook",
|
||||
"TabControl": "notebook",
|
||||
"ScrollBox": "scrollbox",
|
||||
"Splitter": "splitter", "PairSplitter": "splitter",
|
||||
"Statusbar": "statusbar", "StatusBar": "statusbar",
|
||||
"Toolbar": "toolbar", "ToolBar": "toolbar", "ControlBar": "toolbar",
|
||||
"CoolBar": "toolbar", "HeaderControl": "toolbar",
|
||||
"MenuBar": "menubar", "MainMenu": "menubar", "PopupMenu": "menubar",
|
||||
"ProgressBar": "progressbar",
|
||||
"Calendar": "datetimepicker", "DateTimePicker": "datetimepicker",
|
||||
"ListView": "listview", "ShellListView": "listview",
|
||||
"ColumnView": "listview", "GridView": "listview", "IconView": "listview",
|
||||
"TreeView": "treeview", "ShellTreeView": "treeview",
|
||||
"StringGrid": "stringgrid", "DrawGrid": "stringgrid",
|
||||
"ValueListEditor": "stringgrid",
|
||||
"XSpreadsheet": "spreadsheet",
|
||||
"XGraph": "plot",
|
||||
|
||||
"Switch": "togglebutton", "ScaleButton": "scale",
|
||||
"Menu": "menubar", "MenuItem": "menuitem",
|
||||
"FlowBox": "listbox", "StackSidebar": "listbox",
|
||||
"StackSwitcher": "listbox", "EntryCompletion": "combobox",
|
||||
"Paned": "splitter", "ScrolledWindow": "scrollbox",
|
||||
"PlacesSidebar": "listbox",
|
||||
"ColorChooserWidget": "colorbox",
|
||||
|
||||
"AboutDialog": "dialog", "AppChooserDialog": "dialog",
|
||||
"Assistant": "dialog", "CalculatorDialog": "dialog",
|
||||
"CalendarDialog": "dialog", "ColorChooserDialog": "dialog",
|
||||
"ColorDialog": "dialog", "Dialog": "dialog",
|
||||
"FileChooserDialog": "dialog", "FindDialog": "dialog",
|
||||
"FontChooserDialog": "dialog", "FontDialog": "dialog",
|
||||
"MessageDialog": "dialog", "OpenDialog": "dialog",
|
||||
"OpenPictureDialog": "dialog", "PageSetupDialog": "dialog",
|
||||
"PrintDialog": "dialog", "PrintUnixDialog": "dialog",
|
||||
"PrinterSetupDialog": "dialog", "ReplaceDialog": "dialog",
|
||||
"SaveDialog": "dialog", "SavePictureDialog": "dialog",
|
||||
"SelectDirectoryDialog": "dialog", "TaskDialog": "dialog",
|
||||
"ShortcutsWindow": "dialog",
|
||||
"Window": "toplevel", "Form": "toplevel",
|
||||
"ApplicationWindow": "toplevel",
|
||||
}
|
||||
|
||||
|
||||
# --- extra tables (no C counterpart; small and explicit) ----------------
|
||||
# C props_for() has no table for dialogs (title) or menu items
|
||||
# (caption). Everything else unmapped keeps the generic set only.
|
||||
EXTRA_TABLES = {
|
||||
"dialog": [
|
||||
{"name": "title", "kind": "Str", "default": "", "lo": 0.0,
|
||||
"hi": 0.0, "labels": None, "values": None},
|
||||
],
|
||||
"menuitem": [
|
||||
{"name": "label", "kind": "Str", "default": "", "lo": 0.0,
|
||||
"hi": 0.0, "labels": None, "values": None},
|
||||
],
|
||||
}
|
||||
|
||||
# --- curated: Lazarus display names ---------------------------------------
|
||||
DISPLAY = {
|
||||
"name": "Name", "left": "Left", "top": "Top", "width": "Width",
|
||||
"height": "Height",
|
||||
"background": "Color", "foreground": "Font.Color",
|
||||
"font-name": "Font.Name", "font-size": "Font.Size",
|
||||
"font-bold": "Font.Style.Bold", "font-italic": "Font.Style.Italic",
|
||||
"font-underline": "Font.Style.Underline",
|
||||
"font-strikeout": "Font.Style.StrikeOut",
|
||||
"border-width": "Border.Width", "border-color": "Border.Color",
|
||||
"border-radius": "Border.Radius",
|
||||
"tooltip-text": "Hint", "hint": "Hint", "show-hint": "ShowHint",
|
||||
"cursor": "Cursor", "tab-order": "TabOrder", "tab-stop": "TabStop",
|
||||
"min-width": "Constraints.MinWidth",
|
||||
"min-height": "Constraints.MinHeight",
|
||||
"max-width": "Constraints.MaxWidth",
|
||||
"max-height": "Constraints.MaxHeight",
|
||||
"margin-left": "BorderSpacing.Left", "margin-top": "BorderSpacing.Top",
|
||||
"margin-right": "BorderSpacing.Right",
|
||||
"margin-bottom": "BorderSpacing.Bottom",
|
||||
"margin-around": "BorderSpacing.Around",
|
||||
"inner-border": "BorderSpacing.InnerBorder",
|
||||
"cell-align-horizontal": "BorderSpacing.CellAlignHorizontal",
|
||||
"cell-align-vertical": "BorderSpacing.CellAlignVertical",
|
||||
"autosize": "AutoSize", "tag": "Tag",
|
||||
"anchor-top": "Anchors.Top", "anchor-left": "Anchors.Left",
|
||||
"anchor-right": "Anchors.Right", "anchor-bottom": "Anchors.Bottom",
|
||||
"align": "Align", "enabled": "Enabled", "visible": "Visible",
|
||||
"label": "Caption", "text": "Text", "active": "Checked",
|
||||
"value": "Position", "minimum": "Min", "maximum": "Max",
|
||||
"lower": "Min", "upper": "Max",
|
||||
"step-increment": "SmallChange", "page-increment": "LargeChange",
|
||||
"page-size": "PageSize", "step": "Step",
|
||||
"items": "Items", "item-index": "ItemIndex",
|
||||
"selection-mode": "SelectionMode",
|
||||
"password": "PasswordChar", "show-password": "ShowPassword",
|
||||
"placeholder-text": "TextHint", "editable": "ReadOnly",
|
||||
"max-length": "MaxLength", "alignment": "Alignment",
|
||||
"char-case": "CharCase", "numbers-only": "NumbersOnly",
|
||||
"hide-selection": "HideSelection", "auto-select": "AutoSelect",
|
||||
"xalign": "Alignment", "yalign": "Layout", "wrap": "WordWrap",
|
||||
"selectable": "Selectable", "transparent": "Transparent",
|
||||
"show-accel-char": "ShowAccelChar", "focus-control": "FocusControl",
|
||||
"inconsistent": "State", "allow-grayed": "AllowGrayed",
|
||||
"value-checked": "ValueChecked", "value-unchecked": "ValueUnchecked",
|
||||
"group": "Group", "group-index": "GroupIndex",
|
||||
"allow-all-up": "AllowAllUp", "flat": "Flat", "glyph": "Glyph",
|
||||
"kind": "Kind", "layout": "Layout", "modal-result": "ModalResult",
|
||||
"default": "Default", "cancel": "Cancel",
|
||||
"relief": "Relief", "focus-on-click": "FocusOnClick",
|
||||
"style": "Style", "drop-down-count": "DropDownCount",
|
||||
"drop-down-width": "DropDownWidth", "sorted": "Sorted",
|
||||
"read-only": "ReadOnly", "auto-complete": "AutoComplete",
|
||||
"columns": "Columns", "item-height": "ItemHeight",
|
||||
"integral-height": "IntegralHeight",
|
||||
"checked-items": "Checked", "direction": "Direction",
|
||||
"digits": "DecimalPlaces", "draw-value": "DrawValue",
|
||||
"inverted": "Inverted", "page-step": "PageSize",
|
||||
"tick-marks": "TickMarks", "frequency": "Frequency",
|
||||
"show-sel-range": "ShowSelRange", "sel-start": "SelStart",
|
||||
"sel-end": "SelEnd", "orientation": "Kind",
|
||||
"cursor-visible": "CursorVisible", "wrap-mode": "WordWrap",
|
||||
"scroll-bars": "ScrollBars", "want-tabs": "WantTabs",
|
||||
"want-returns": "WantReturns",
|
||||
"label-xalign": "Alignment", "inset": "Inset",
|
||||
"top-inset": "TopInset", "shadow-type": "Bevel",
|
||||
"file": "Picture", "pixel-size": "PixelSize",
|
||||
"stretch": "Stretch", "proportional": "Proportional",
|
||||
"center": "Center", "shape": "Shape", "fill-color": "FillColor",
|
||||
"pen-color": "PenColor", "pen-width": "PenWidth",
|
||||
"pages": "Pages", "page": "ActivePage", "tab-height": "TabHeight",
|
||||
"tab-position": "TabPosition", "tab-width": "TabWidth",
|
||||
"position": "Position", "min-size": "MinSize",
|
||||
"resize-style": "ResizeStyle", "auto-snap": "AutoSnap",
|
||||
"panels": "Panels", "size-grip": "SizeGrip",
|
||||
"toolbar-style": "Style", "show-captions": "ShowCaptions",
|
||||
"button-width": "ButtonWidth", "button-height": "ButtonHeight",
|
||||
"menus": "Menus", "fraction": "Fraction",
|
||||
"show-text": "BarShowText", "pulsing": "Style",
|
||||
"bar-color": "BarColor", "trough-color": "TroughColor",
|
||||
"date": "Date", "show-heading": "ShowHeading",
|
||||
"show-day-names": "ShowDayNames",
|
||||
"show-week-numbers": "ShowWeekNumbers",
|
||||
"grid-color": "GridColor", "selected-fill-color": "SelectedFillColor",
|
||||
"selected-text-color": "SelectedTextColor",
|
||||
"today-color": "TodayColor", "dim-text-color": "DimTextColor",
|
||||
"weekends-color": "WeekendsColor", "disabled-color": "DisabledColor",
|
||||
"color": "Color", "default-color": "DefaultColor",
|
||||
"none-color": "NoneColor", "use-alpha": "UseAlpha", "title": "Title",
|
||||
"headers-visible": "HeadersVisible",
|
||||
"view-style": "ViewStyle", "grid-lines": "GridLines",
|
||||
"row-select": "RowSelect", "multi-select": "MultiSelect",
|
||||
"sort-type": "SortType", "header-height": "HeaderHeight",
|
||||
"indent": "Indent", "show-buttons": "ShowButtons",
|
||||
"show-lines": "ShowLines", "show-root": "ShowRoot",
|
||||
"rows": "RowCount", "fixed-cols": "FixedCols",
|
||||
"fixed-rows": "FixedRows", "default-col-width": "DefaultColWidth",
|
||||
"default-row-height": "DefaultRowHeight",
|
||||
"grid-line-width": "GridLineWidth", "line-color": "LineColor",
|
||||
"border-style": "BorderStyle", "icon": "Icon",
|
||||
"window-state": "WindowState", "resizable": "Resizable",
|
||||
"width-chars": "WidthChars",
|
||||
}
|
||||
# Per-(C-table, prop) display overrides (ComboBox "active" is an
|
||||
# ItemIndex, not a Checked flag; Scale "value" is a Position, etc.).
|
||||
DISPLAY_OVERRIDES = {
|
||||
("combobox", "active"): "ItemIndex",
|
||||
("combobox", "text"): "Text",
|
||||
("listbox", "active"): "ItemIndex",
|
||||
("checkbutton", "active"): "Checked",
|
||||
("radiobutton", "active"): "Checked",
|
||||
("togglebutton", "active"): "Down",
|
||||
("togglebutton", "text"): "Caption",
|
||||
("spinedit", "step"): "Increment",
|
||||
("spinedit", "value"): "Value",
|
||||
("progressbar", "value"): "Position",
|
||||
("progressbar", "position"): "Position",
|
||||
("scale", "value"): "Position",
|
||||
("trackbar", "value"): "Position",
|
||||
("scrollbar", "value"): "Position",
|
||||
("datetimepicker", "date"): "Date",
|
||||
("frame", "label"): "Caption",
|
||||
("groupbox", "label"): "Caption",
|
||||
("panel", "label"): "Caption",
|
||||
("menubutton", "label"): "Caption",
|
||||
("colorbox", "color"): "Selected",
|
||||
("text", "text"): "Text",
|
||||
("memo", "text"): "Text",
|
||||
("entry", "text"): "Text",
|
||||
("entry", "editable"): "ReadOnly",
|
||||
("text", "editable"): "ReadOnly",
|
||||
("memo", "editable"): "ReadOnly",
|
||||
}
|
||||
|
||||
# Props that are stored in the model and emitted by the generator (as
|
||||
# comments where the generated XFrame API has no setter) but do not
|
||||
# change the live canvas widget in this phase. Everything not listed
|
||||
# here is live-applied by Widget.set_prop (state change + canvas
|
||||
# redraw); the canvas draw code reads the live ones.
|
||||
MODEL_ONLY = {
|
||||
"font-underline", "font-strikeout", "cursor", "tab-order", "tab-stop",
|
||||
"margin-left", "margin-top", "margin-right", "margin-bottom",
|
||||
"margin-around", "inner-border", "cell-align-horizontal",
|
||||
"cell-align-vertical", "autosize", "tag", "anchor-top", "anchor-left",
|
||||
"anchor-right", "anchor-bottom", "align", "hint", "show-hint",
|
||||
"tooltip-text", "glyph", "focus-control", "value-checked",
|
||||
"value-unchecked", "group", "group-index", "allow-all-up",
|
||||
"modal-result", "default", "cancel", "kind", "layout", "relief",
|
||||
"focus-on-click", "char-case", "numbers-only", "auto-select",
|
||||
"auto-complete", "hide-selection", "width-chars", "max-length",
|
||||
"sorted", "drop-down-count", "drop-down-width", "style", "columns",
|
||||
"integral-height", "view-style", "sort-type", "min-size",
|
||||
"resize-style", "auto-snap", "numeric", "editor-enabled",
|
||||
"position", "window-state", "resizable", "border-style", "icon",
|
||||
"selectable", "want-tabs", "want-returns",
|
||||
}
|
||||
# (C-table, prop) forced live even though the name is in MODEL_ONLY
|
||||
# above (e.g. Splitter/ProgressBar "position" is drawn; toplevel
|
||||
# "position" is a window-placement hint and stays model-only).
|
||||
LIVE_OVERRIDES = {
|
||||
("splitter", "position"), ("progressbar", "position"),
|
||||
("scale", "position"), ("trackbar", "position"),
|
||||
("scrollbar", "position"),
|
||||
}
|
||||
# (C-table, prop) forced model-only even though the name is not in
|
||||
# MODEL_ONLY above.
|
||||
MODEL_ONLY_OVERRIDES = {
|
||||
("toplevel", "position"), ("toplevel", "title"),
|
||||
("entry", "max-length"), ("text", "max-length"),
|
||||
("memo", "max-length"),
|
||||
}
|
||||
|
||||
# Lazarus event names (proposal SS4.10): the Inspector shows these,
|
||||
# not GTK signal names.
|
||||
EVENTS = (
|
||||
"OnClick", "OnChange", "OnKeyPress", "OnKeyDown", "OnKeyUp",
|
||||
"OnMouseDown", "OnMouseUp", "OnMouseMove", "OnDblClick",
|
||||
"OnEnter", "OnExit", "OnResize", "OnChangeBounds",
|
||||
"OnMouseEnter", "OnMouseLeave", "OnMouseWheel", "OnContextPopup",
|
||||
)
|
||||
|
||||
# Proposal SS2.1-SS2.10 spot-checks: (C table, required prop names).
|
||||
# The generator fails if the C tables ever stop covering the proposal.
|
||||
REQUIRED = {
|
||||
"button": ["label", "default", "cancel", "kind", "layout", "glyph",
|
||||
"modal-result"],
|
||||
"entry": ["text", "editable", "max-length", "placeholder-text",
|
||||
"password", "alignment", "char-case", "numbers-only",
|
||||
"hide-selection", "auto-select"],
|
||||
"label": ["label", "xalign", "yalign", "wrap", "selectable",
|
||||
"transparent", "focus-control", "show-accel-char"],
|
||||
"checkbutton": ["label", "active", "inconsistent", "allow-grayed",
|
||||
"alignment", "value-checked", "value-unchecked"],
|
||||
"radiobutton": ["label", "active", "group"],
|
||||
"combobox": ["items", "active", "text", "style", "drop-down-count",
|
||||
"drop-down-width", "sorted", "read-only", "max-length"],
|
||||
"listbox": ["items", "selection-mode", "item-index", "sorted",
|
||||
"columns", "item-height", "integral-height"],
|
||||
"checklistbox": ["items", "checked-items", "item-index",
|
||||
"item-height", "sorted"],
|
||||
"scrollbar": ["value", "lower", "upper", "step-increment",
|
||||
"page-increment", "page-size", "orientation",
|
||||
"large-change"],
|
||||
"scale": ["value", "minimum", "maximum", "draw-value",
|
||||
"page-step", "tick-marks", "frequency", "show-sel-range"],
|
||||
"trackbar": ["value", "minimum", "maximum", "step", "page-step",
|
||||
"draw-value", "tick-marks", "frequency"],
|
||||
"text": ["text", "editable", "cursor-visible", "wrap-mode",
|
||||
"max-length", "scroll-bars", "want-tabs", "want-returns",
|
||||
"hide-selection", "alignment"],
|
||||
"memo": ["text", "editable", "cursor-visible", "wrap-mode",
|
||||
"max-length", "scroll-bars", "want-tabs", "want-returns",
|
||||
"hide-selection", "alignment"],
|
||||
}
|
||||
|
||||
# Extra generic props with no C counterpart (Lazarus BorderSpacing
|
||||
# sub-props, proposal SS1): name, kind, default, lo, hi, enum labels.
|
||||
GENERIC_EXTRAS = [
|
||||
("inner-border", "Int", "0", 0, 100000, None),
|
||||
("cell-align-horizontal", "Enum", "0", 0, 0,
|
||||
"Left|Center|Right"),
|
||||
("cell-align-vertical", "Enum", "0", 0, 0, "Top|Center|Bottom"),
|
||||
]
|
||||
|
||||
# --- parsing /opt/lightgui/src/props.h ------------------------------------
|
||||
_ENTRY_RE = re.compile(
|
||||
r'\{\s*"(?P<name>[^"]+)"\s*,\s*(?:K|PropKind)::(?P<kind>\w+)\s*,\s*"(?P<default>[^"]*)"'
|
||||
r'(?:\s*,\s*(?P<lo>-?[\d.]+)\s*,\s*(?P<hi>-?[\d.]+)'
|
||||
r'(?:\s*,\s*"(?P<labels>[^"]*)"\s*,\s*(?P<values>\w+))?)?\s*\}')
|
||||
_VECTOR_RE = re.compile(
|
||||
r"static const std::vector<PropDef> (\w+) = \{(.*?)\};", re.S)
|
||||
_ENUM_ARR_RE = re.compile(
|
||||
r"inline const int (k\w+Values)\[\] = \{([^}]*)\};")
|
||||
_COMMON_RE = re.compile(
|
||||
r"common_props\(\) \{(.*?)return v;\n\}", re.S)
|
||||
|
||||
|
||||
def _parse(text):
|
||||
enums = {}
|
||||
for name, body in _ENUM_ARR_RE.findall(text):
|
||||
enums[name] = [int(v) for v in body.replace(",", " ").split()
|
||||
if v.strip().lstrip("-").isdigit()]
|
||||
|
||||
def entries(body):
|
||||
out = []
|
||||
for m in _ENTRY_RE.finditer(body):
|
||||
d = m.groupdict()
|
||||
labels = d["labels"].split("|") if d["labels"] else None
|
||||
values = enums.get(d["values"]) if d["values"] else None
|
||||
out.append({
|
||||
"name": d["name"], "kind": d["kind"],
|
||||
"default": d["default"],
|
||||
"lo": float(d["lo"]) if d["lo"] is not None else 0.0,
|
||||
"hi": float(d["hi"]) if d["hi"] is not None else 0.0,
|
||||
"labels": labels, "values": values,
|
||||
})
|
||||
return out
|
||||
|
||||
common_m = _COMMON_RE.search(text)
|
||||
if not common_m:
|
||||
raise SystemExit("gen_props: common_props() not found in props.h")
|
||||
tables = {"common": entries(common_m.group(1))}
|
||||
for var, body in _VECTOR_RE.findall(text):
|
||||
tables[var] = entries(body)
|
||||
return tables
|
||||
|
||||
|
||||
def _model_only(table, name):
|
||||
if (table, name) in LIVE_OVERRIDES:
|
||||
return False
|
||||
if (table, name) in MODEL_ONLY_OVERRIDES:
|
||||
return True
|
||||
return name in MODEL_ONLY
|
||||
|
||||
|
||||
def _display(table, name):
|
||||
return DISPLAY_OVERRIDES.get((table, name),
|
||||
DISPLAY.get(name, name))
|
||||
|
||||
|
||||
def _py_str(value):
|
||||
return '"%s"' % value.replace("\\", "\\\\").replace('"', '\\"')
|
||||
|
||||
|
||||
def _num(value):
|
||||
if value == int(value):
|
||||
return str(int(value))
|
||||
return repr(value)
|
||||
|
||||
|
||||
def _emit_table(name, table, props):
|
||||
lines = ["%s = (" % name]
|
||||
for p in props:
|
||||
disp = _display(table, p["name"])
|
||||
mo = _model_only(table, p["name"])
|
||||
labels = (", ".join(_py_str(x) for x in p["labels"])
|
||||
if p["labels"] else "")
|
||||
values = (", ".join(str(v) for v in p["values"])
|
||||
if p["values"] else "")
|
||||
lines.append(
|
||||
' PropDef(%s, %s, %s, %s, %s, (%s), (%s), %s, %s),'
|
||||
% (_py_str(p["name"]), _py_str(p["kind"]),
|
||||
_py_str(p["default"]),
|
||||
_num(p["lo"]), _num(p["hi"]), labels, values,
|
||||
_py_str(disp), "True" if mo else "False"))
|
||||
lines.append(")")
|
||||
return lines
|
||||
|
||||
def main():
|
||||
tables = _parse(C_PROPS.read_text(encoding="utf-8"))
|
||||
for table, required in REQUIRED.items():
|
||||
have = {p["name"] for p in tables.get(table, [])}
|
||||
missing = [r for r in required if r not in have]
|
||||
if missing:
|
||||
raise SystemExit(
|
||||
"gen_props: C table %r is missing proposal props: %s"
|
||||
% (table, ", ".join(missing)))
|
||||
sys.path.insert(0, str(REPO))
|
||||
from lightgui.xframe import palette
|
||||
kinds = [e.kind for e in palette.PALETTE]
|
||||
generic_kinds = {e.kind for e in palette.PALETTE
|
||||
if e.section not in ("Stock Market", "Instrumentation")}
|
||||
unknown = sorted({k for k in KIND_TABLE if k not in kinds})
|
||||
if unknown:
|
||||
raise SystemExit("gen_props: KIND_TABLE kinds not in palette: %s"
|
||||
% ", ".join(unknown))
|
||||
for k in sorted(k for k in generic_kinds if k not in KIND_TABLE):
|
||||
print("gen_props: NOTE generic kind %r has no custom table "
|
||||
"(generic set only)" % k, file=sys.stderr)
|
||||
|
||||
out = []
|
||||
out.append('"""Property tables for the LightGUI Python port.')
|
||||
out.append('')
|
||||
out.append('GENERATED -- do not edit by hand. Run tools/gen_props.py')
|
||||
out.append('to regenerate from /opt/lightgui/src/props.h (C tables,')
|
||||
out.append('canonical) and lightgui/xframe/palette.py (the 547 kinds).')
|
||||
out.append('Curated mappings (kind -> C table, Lazarus display names,')
|
||||
out.append('model-only flags) live in tools/gen_props.py.')
|
||||
out.append('')
|
||||
out.append('Every palette kind gets the generic set (Name, geometry,')
|
||||
out.append('Color, Font, Border, Enabled, Visible, Hint, ShowHint,')
|
||||
out.append('Cursor, TabOrder, TabStop, Constraints, BorderSpacing,')
|
||||
out.append('AutoSize, Tag, Align, Anchors) plus its family custom')
|
||||
out.append('props from proposal SS2.1-SS2.21. Stock / Instrumentation')
|
||||
out.append('kinds get the generic set only in Phase 2; Phase 6 adds')
|
||||
out.append('their tables via register_custom_table().')
|
||||
out.append('')
|
||||
out.append('Internal names stay the C/GTK-era names (proposal SS5.3);')
|
||||
out.append('`display` is the Lazarus name shown in the Inspector.')
|
||||
out.append('`model_only` props are stored on the widget and emitted')
|
||||
out.append('by the generator as comments; they do not change the live')
|
||||
out.append('canvas widget. Note `editable` is inverted ReadOnly')
|
||||
out.append('(ReadOnly = not editable, proposal SS2.2) and `foreground`')
|
||||
out.append('is the font/text colour.')
|
||||
out.append('"""')
|
||||
out.append('')
|
||||
out.append('import re')
|
||||
out.append('from collections import namedtuple')
|
||||
out.append('')
|
||||
out.append('')
|
||||
out.append('PropDef = namedtuple(')
|
||||
out.append(' "PropDef",')
|
||||
out.append(' "name kind default lo hi enum_labels enum_values "')
|
||||
out.append(' "display model_only")')
|
||||
out.append('')
|
||||
out.append('EVENTS = (%s)' % ", ".join(_py_str(e) for e in EVENTS))
|
||||
out.append('')
|
||||
generic = [
|
||||
{"name": "name", "kind": "Str", "default": "", "lo": 0.0,
|
||||
"hi": 0.0, "labels": None, "values": None},
|
||||
{"name": "left", "kind": "Int", "default": "0", "lo": 0.0,
|
||||
"hi": 100000.0, "labels": None, "values": None},
|
||||
{"name": "top", "kind": "Int", "default": "0", "lo": 0.0,
|
||||
"hi": 100000.0, "labels": None, "values": None},
|
||||
{"name": "width", "kind": "Int", "default": "100", "lo": 10.0,
|
||||
"hi": 100000.0, "labels": None, "values": None},
|
||||
{"name": "height", "kind": "Int", "default": "30", "lo": 10.0,
|
||||
"hi": 100000.0, "labels": None, "values": None},
|
||||
]
|
||||
generic.extend(tables["common"])
|
||||
for name, kind, default, lo, hi, labels in GENERIC_EXTRAS:
|
||||
generic.append({"name": name, "kind": kind, "default": default,
|
||||
"lo": float(lo), "hi": float(hi),
|
||||
"labels": labels.split("|") if labels else None,
|
||||
"values": None})
|
||||
out.extend(_emit_table("GENERIC_PROPS", "common", generic))
|
||||
out.append('')
|
||||
out.append('GENERIC_NAMES = frozenset(p.name for p in GENERIC_PROPS)')
|
||||
out.append('')
|
||||
tables.update(EXTRA_TABLES)
|
||||
used = []
|
||||
for kind in kinds:
|
||||
table = KIND_TABLE.get(kind)
|
||||
if table and table not in used:
|
||||
used.append(table)
|
||||
for table in used:
|
||||
out.extend(_emit_table(table.upper() + "_PROPS", table,
|
||||
tables[table]))
|
||||
out.append('')
|
||||
out.append('# palette kind -> custom (non-generic) props tuple')
|
||||
out.append('CUSTOM_PROPS = {')
|
||||
for kind in kinds:
|
||||
table = KIND_TABLE.get(kind)
|
||||
if table:
|
||||
out.append(' %s: %s_PROPS,' % (_py_str(kind),
|
||||
table.upper()))
|
||||
out.append('}')
|
||||
out.append('')
|
||||
out.append('# Registry names (GtkButton, TButton, ...) resolve through')
|
||||
out.append('# the palette; this is the kind-level custom table only.')
|
||||
out.append('_CUSTOM_BY_KIND = dict(CUSTOM_PROPS)')
|
||||
out.append('')
|
||||
out.append('')
|
||||
out.append('def props_for(kind_or_name):')
|
||||
out.append(' """Full table (generic + custom) for a palette kind or')
|
||||
out.append(' a registry name (e.g. "GtkButton" or "Button").')
|
||||
out.append(' Unknown names get the generic set only."""')
|
||||
out.append(' kind = _resolve_kind(kind_or_name)')
|
||||
out.append(' custom = _CUSTOM_BY_KIND.get(kind, ())')
|
||||
out.append(' seen = {p.name for p in custom}')
|
||||
out.append(' return tuple(p for p in GENERIC_PROPS')
|
||||
out.append(' if p.name not in seen) + tuple(custom)')
|
||||
out.append('')
|
||||
out.append('')
|
||||
out.append('def custom_props_for(kind_or_name):')
|
||||
out.append(' """Custom (non-generic) props only, or () if none."""')
|
||||
out.append(' return _CUSTOM_BY_KIND.get(_resolve_kind(kind_or_name), ())')
|
||||
out.append('')
|
||||
out.append('')
|
||||
out.append('def prop_names(kind_or_name):')
|
||||
out.append(' return frozenset(p.name for p in props_for(kind_or_name))')
|
||||
out.append('')
|
||||
out.append('')
|
||||
out.append('def find_prop(kind_or_name, name):')
|
||||
out.append(' for prop in props_for(kind_or_name):')
|
||||
out.append(' if prop.name == name:')
|
||||
out.append(' return prop')
|
||||
out.append(' return None')
|
||||
out.append('')
|
||||
out.append('')
|
||||
out.append('def is_model_only(kind_or_name, name):')
|
||||
out.append(' prop = find_prop(kind_or_name, name)')
|
||||
out.append(' return bool(prop.model_only) if prop is not None else False')
|
||||
out.append('')
|
||||
out.append('')
|
||||
out.append('def register_custom_table(kind, props):')
|
||||
out.append(' """Add/replace the custom table for one palette kind.')
|
||||
out.append(' Phase 6 uses this for the Stock / Instrumentation')
|
||||
out.append(' families; it never touches the generated tables."""')
|
||||
out.append(' _CUSTOM_BY_KIND[str(kind)] = tuple(props)')
|
||||
out.append('')
|
||||
out.append('')
|
||||
out.append('def _resolve_kind(kind_or_name):')
|
||||
out.append(' name = str(kind_or_name)')
|
||||
out.append(' if name in _CUSTOM_BY_KIND or name in _ALL_KINDS:')
|
||||
out.append(' return name')
|
||||
out.append(' try:')
|
||||
out.append(' from lightgui.xframe import palette as _palette')
|
||||
out.append(' entry = _palette.find(name)')
|
||||
out.append(' if entry is not None:')
|
||||
out.append(' return entry.kind')
|
||||
out.append(' except Exception:')
|
||||
out.append(' pass')
|
||||
out.append(' return name')
|
||||
out.append('')
|
||||
out.append('')
|
||||
out.append('def validate(kind_or_name, name, value):')
|
||||
out.append(' """Validate *value* against the table for *kind* and')
|
||||
out.append(' return its canonical string form. Raises ValueError')
|
||||
out.append(' for an unknown prop, a bad bool/int/double, an enum')
|
||||
out.append(' label or value outside its range."""')
|
||||
out.append(' prop = find_prop(kind_or_name, name)')
|
||||
out.append(' if prop is None:')
|
||||
out.append(' raise ValueError("unknown property %r for %r"')
|
||||
out.append(' % (name, kind_or_name))')
|
||||
out.append(' return _canonical(prop, value)')
|
||||
out.append('')
|
||||
out.append('')
|
||||
out.append('def _canonical(prop, value):')
|
||||
out.append(' kind = prop.kind')
|
||||
out.append(' if kind == "Bool":')
|
||||
out.append(' if isinstance(value, bool):')
|
||||
out.append(' return "true" if value else "false"')
|
||||
out.append(' text = str(value).strip().lower()')
|
||||
out.append(' if text in ("true", "1", "yes", "on"):')
|
||||
out.append(' return "true"')
|
||||
out.append(' if text in ("false", "0", "no", "off"):')
|
||||
out.append(' return "false"')
|
||||
out.append(' raise ValueError("not a bool: %r" % (value,))')
|
||||
out.append(' if kind == "Int":')
|
||||
out.append(' try:')
|
||||
out.append(' number = int(str(value).strip())')
|
||||
out.append(' except (TypeError, ValueError):')
|
||||
out.append(' raise ValueError("not an int: %r" % (value,))')
|
||||
out.append(' if prop.lo or prop.hi:')
|
||||
out.append(' if number < prop.lo or number > prop.hi:')
|
||||
out.append(' raise ValueError(')
|
||||
out.append(' "%s out of range %d..%d: %r"')
|
||||
out.append(' % (prop.name, prop.lo, prop.hi, value))')
|
||||
out.append(' return str(number)')
|
||||
out.append(' if kind == "Double":')
|
||||
out.append(' try:')
|
||||
out.append(' number = float(str(value).strip())')
|
||||
out.append(' except (TypeError, ValueError):')
|
||||
out.append(' raise ValueError("not a number: %r" % (value,))')
|
||||
out.append(' if prop.lo or prop.hi:')
|
||||
out.append(' if number < prop.lo or number > prop.hi:')
|
||||
out.append(' raise ValueError(')
|
||||
out.append(' "%s out of range %s..%s: %r"')
|
||||
out.append(' % (prop.name, prop.lo, prop.hi, value))')
|
||||
out.append(' return "%g" % number')
|
||||
out.append(' if kind == "Enum":')
|
||||
out.append(' text = str(value).strip()')
|
||||
out.append(' if prop.enum_labels and text in prop.enum_labels:')
|
||||
out.append(' return str(prop.enum_values[')
|
||||
out.append(' prop.enum_labels.index(text)]')
|
||||
out.append(' if prop.enum_values else text)')
|
||||
out.append(' try:')
|
||||
out.append(' number = int(text)')
|
||||
out.append(' except ValueError:')
|
||||
out.append(' raise ValueError("not an enum value: %r" % (value,))')
|
||||
out.append(' if prop.enum_values and number not in prop.enum_values:')
|
||||
out.append(' raise ValueError("enum value out of range: %r"')
|
||||
out.append(' % (value,))')
|
||||
out.append(' return str(number)')
|
||||
out.append(' if kind == "Color":')
|
||||
out.append(' return _canonical_color(str(value))')
|
||||
out.append(' return "" if value is None else str(value)')
|
||||
out.append('')
|
||||
out.append('')
|
||||
out.append('def _canonical_color(text):')
|
||||
out.append(' text = text.strip()')
|
||||
out.append(' if not text:')
|
||||
out.append(' return ""')
|
||||
out.append(' if text.startswith("#") and len(text) in (4, 7, 9):')
|
||||
out.append(' digits = text[1:]')
|
||||
out.append(' if all(c in "0123456789abcdefABCDEF" for c in digits):')
|
||||
out.append(' return text.lower()')
|
||||
out.append(' match = re.match(r"rgb\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)",')
|
||||
out.append(' text)')
|
||||
out.append(' if match:')
|
||||
out.append(' r, g, b = (int(v) for v in match.groups())')
|
||||
out.append(' if max(r, g, b) <= 255:')
|
||||
out.append(' return "rgb(%d,%d,%d)" % (r, g, b)')
|
||||
out.append(' if text.lower() in _NAMED_COLORS:')
|
||||
out.append(' return text.lower()')
|
||||
out.append(' raise ValueError("not a color: %r" % (text,))')
|
||||
out.append('')
|
||||
out.append('')
|
||||
out.append('_NAMED_COLORS = frozenset([')
|
||||
out.append(' "black", "white", "red", "green", "blue", "yellow",')
|
||||
out.append(' "orange", "purple", "teal", "magenta", "brown", "gray",')
|
||||
out.append(' "grey", "pink", "cyan", "transparent"])')
|
||||
out.append('')
|
||||
out.append('_ALL_KINDS = frozenset(%s)' % _py_list(kinds))
|
||||
out.append('')
|
||||
(REPO / "lightgui" / "props.py").write_text(
|
||||
"\n".join(out) + "\n", encoding="utf-8")
|
||||
print("gen_props: wrote lightgui/props.py: %d kinds, %d custom tables"
|
||||
% (len(kinds), len(used)))
|
||||
|
||||
|
||||
def _py_list(values):
|
||||
return "(%s)" % ", ".join(_py_str(v) for v in values)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user