ScriptWeaver Reflection API

The Reflection API allows JavaScript code (like the Designer) to introspect the available GUI widgets, their properties, and their supported commands at runtime. The API exposes a static, build-time generated snapshot of the generator_data.go structures.

sw.reflect.getWidgetDef(className)

Returns the definition of a given widget class (e.g., 'TButton', 'TFrame'), or null if the class does not exist.

Example:

const def = sw.reflect.getWidgetDef('TButton');

Schema:

{
  // The underlying Tk widget command (e.g., "ttk::button").
  // May be omitted if the class doesn't map to a Tk widget (e.g., StringVar).
  tkWidget: "ttk::button",

  // The tkpath item type (e.g., "ptext"), if this is a canvas item.
  // Omitted if not a tkpath item.
  tkType: "ptext",

  // True if this widget can contain other widgets (e.g., TFrame).
  isContainer: false,

  // True if this is a canvas item (e.g., Path, PText) rather than a widget.
  isItem: false,

  // An array of supported command names (e.g., ["invoke"]). Always an array.
  commands: ["invoke"],

  // A map of camelCase option names to their definitions.
  options: {
    "text": {
      // The underlying Tk option flag (e.g., "text" for "-text").
      // The empty string ("") means the option is JS-only and has no Tk
      // backing — currently just the `onChange` callback on the variable
      // classes (BoolVar / DoubleVar / IntVar / StringVar), which is wired
      // via Tcl variable traces rather than a widget option.
      tkOption: "text",

      // True if the option binds a JS function to a Tcl callback.
      // Also true for the JS-only `onChange` callback above.
      isEventHandler: false,

      // True if the option is a boolean flag.
      isFlag: false,

      // True if the option can only be passed at widget creation time
      // and cannot be re-configured later (e.g., "orient" on TPanedWindow).
      isStatic: false
    }
  }
}

sw.reflect.getWidgetOptions(className)

A convenience method that returns the options map for a given widget class, or null if the class does not exist. Equivalent to calling sw.reflect.getWidgetDef(className)?.options.


Note: The internal sw.reflect._widgetData map is used to back these methods. It is considered an internal implementation detail and its schema or presence is not guaranteed for direct iteration.