From cef7988a84faacc1c02c183eb3c6e39892299943 Mon Sep 17 00:00:00 2001 From: cnmcdee Date: Tue, 1 Dec 2026 02:23:54 +0000 Subject: [PATCH] Phase 1: XFrame core + canvas + palette data + project model - xframe/core.py: Widget base, 14 archetype draw classes (Cairo), registry over all 547 kinds; 13px handles, 8px grab pad, 450ms double-click, 8px drag threshold, 24x16 resize floor (C/Rust) - xframe/canvas.py: CanvasState state machine (display-free, tested) + Gtk.DrawingArea shell; placement, selection, double-click handles, drag, handle resize, Delete/Escape, viewport tracking - xframe/palette.py: generated from Rust registry_gen.rs, cross-checked vs C xframe_palette.h; 547 entries in 11 sections + 36 legacy model.h type keys as LEGACY_TYPES (583 total in the Rust data file) - model.py: Project + .fdj save/load byte-compatible with the C writer - app.py: main window with filterable palette list + canvas + status bar - tests/: 62 stdlib unittest tests --- lightgui/app.py | 144 +++++++- lightgui/model.py | 374 ++++++++++++++++++++ lightgui/xframe/__init__.py | 25 ++ lightgui/xframe/canvas.py | 358 +++++++++++++++++++ lightgui/xframe/core.py | 571 +++++++++++++++++++++++++++++++ lightgui/xframe/palette.py | 661 ++++++++++++++++++++++++++++++++++++ tests/test_canvas.py | 165 +++++++++ tests/test_core.py | 125 +++++++ tests/test_model.py | 151 ++++++++ tests/test_palette.py | 78 +++++ 10 files changed, 2646 insertions(+), 6 deletions(-) create mode 100644 lightgui/model.py create mode 100644 lightgui/xframe/__init__.py create mode 100644 lightgui/xframe/canvas.py create mode 100644 lightgui/xframe/core.py create mode 100644 lightgui/xframe/palette.py create mode 100644 tests/test_canvas.py create mode 100644 tests/test_core.py create mode 100644 tests/test_model.py create mode 100644 tests/test_palette.py diff --git a/lightgui/app.py b/lightgui/app.py index 27bc546..1a8071e 100644 --- a/lightgui/app.py +++ b/lightgui/app.py @@ -1,25 +1,157 @@ """Application bootstrap and main window assembly (IDE chrome). -Phase 0 skeleton: opens the main designer window. The canvas, palette, -Inspector and code view are wired in by later phases. +Phase 1: a minimal palette list on the side (pick a kind, click the +canvas to place it — the full palette window is a later phase) and the +XFrame canvas filling the centre. The canvas tracks its viewport size +on resize; there is no fixed 800x600 canvas. """ import gi gi.require_version("Gtk", "3.0") -from gi.repository import Gtk +from gi.repository import Gdk, Gtk # noqa: E402 -from lightgui import __version__ +from lightgui import __version__ # noqa: E402 +from lightgui.model import Project # noqa: E402 +from lightgui.xframe import palette as palette_data # noqa: E402 +from lightgui.xframe.canvas import Canvas # noqa: E402 class Application: def __init__(self): + self.project = Project() self.window = Gtk.Window(title="LightGUI — Python/GTK") self.window.set_default_size(1280, 800) self.window.connect("destroy", Gtk.main_quit) - label = Gtk.Label(label=f"LightGUI Python port {__version__} — skeleton") - self.window.add(label) + self.window.connect("key-press-event", self._on_window_key_press) + + vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) + self.window.add(vbox) + + paned = Gtk.Paned(orientation=Gtk.Orientation.HORIZONTAL) + paned.set_position(280) + vbox.pack_start(paned, True, True, 0) + + paned.pack1(self._build_palette_pane(), False, False) + self.canvas = Canvas(self.project) + self.canvas.state.on_change = self._on_canvas_change + paned.pack2(self.canvas, True, False) + + self.statusbar = Gtk.Label(label="Ready", xalign=0) + self.statusbar.set_margin_start(6) + vbox.pack_start(self.statusbar, False, False, 0) + self._update_status() + + # --- palette pane ------------------------------------------------------- + def _build_palette_pane(self): + pane = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=0) + search = Gtk.SearchEntry() + search.set_placeholder_text("Filter palette…") + search.connect("search-changed", self._on_palette_filter) + pane.pack_start(search, False, False, 0) + self._palette_filter_text = "" + + # TreeStore: section rows (bold) -> widget rows (kind, name). + self.palette_store = Gtk.TreeStore(str, str) + for section in palette_data.SECTIONS: + parent = self.palette_store.append(None, [section, ""]) + for entry in palette_data.by_section(section): + self.palette_store.append(parent, [entry.name, entry.name]) + self.palette_filter = self.palette_store.filter_new() + self.palette_filter.set_visible_func(self._palette_visible) + + tree = Gtk.TreeView(model=self.palette_filter) + tree.set_headers_visible(False) + renderer = Gtk.CellRendererText() + column = Gtk.TreeViewColumn("Palette", renderer, text=0) + tree.append_column(column) + tree.connect("cursor-changed", self._on_palette_cursor_changed) + tree.connect("row-activated", self._on_palette_row_activated) + self.palette_tree = tree + + scrolled = Gtk.ScrolledWindow() + scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) + scrolled.add(tree) + pane.pack_start(scrolled, True, True, 0) + + hint = Gtk.Label( + label="Pick a widget, then click the canvas to place it.", + xalign=0) + hint.set_margin_start(6) + hint.set_margin_top(4) + pane.pack_start(hint, False, False, 0) + return pane + + def _palette_visible(self, model, tree_iter, _data): + if not self._palette_filter_text: + return True + section = model.get_value(tree_iter, 0) + kind = model.get_value(tree_iter, 1) + if kind: + return self._palette_filter_text in kind.lower() + # Section row: visible when any child matches. + child = model.iter_children(tree_iter) + while child is not None: + if self._palette_filter_text in \ + model.get_value(child, 0).lower(): + return True + child = model.iter_next(child) + return False + + def _on_palette_filter(self, entry): + self._palette_filter_text = entry.get_text().strip().lower() + self.palette_filter.refilter() + self.palette_tree.expand_all() + + def _selected_palette_kind(self): + selection = self.palette_tree.get_selection() + model, tree_iter = selection.get_selected() + if tree_iter is None: + return None + kind = model.get_value(tree_iter, 1) + return kind or None + + def _on_palette_cursor_changed(self, _tree): + kind = self._selected_palette_kind() + if kind is not None: + self.canvas.set_pending_kind(kind) + self._update_status() + + def _on_palette_row_activated(self, _tree, _path, _column): + # Double-click a palette row: arm placement and focus the canvas. + kind = self._selected_palette_kind() + if kind is not None: + self.canvas.set_pending_kind(kind) + self.canvas.grab_focus() + + # --- canvas / status ------------------------------------------------------ + def _on_canvas_change(self): + self._update_status() + self.canvas.queue_draw() + + def _update_status(self): + parts = ["%d widget(s)" % len(self.project.widgets)] + pending = self.canvas.pending_kind + if pending: + parts.append("placing: %s" % pending) + selected = self.project.selected + if selected is not None: + parts.append("selected: %s (%s) at %d,%d %dx%d" + % (selected.name, selected.kind, selected.x, + selected.y, selected.width, selected.height)) + if self.canvas.state.handles_on: + parts.append("handles on") + self.statusbar.set_text(" | ".join(parts)) + + def _on_window_key_press(self, _window, event): + # The canvas handles Delete/Escape when focused; forward them + # here too so they work when the palette has focus. + key_name = Gdk.keyval_name(event.keyval) + if key_name in ("Delete", "BackSpace", "Escape"): + if self.canvas.state.key(key_name): + return True + return False def run(self): self.window.show_all() diff --git a/lightgui/model.py b/lightgui/model.py new file mode 100644 index 0000000..6043edf --- /dev/null +++ b/lightgui/model.py @@ -0,0 +1,374 @@ +"""Project model: placed-widget list, selection, and the .fdj file format. + +The .fdj format is the C designer's JSON format (src/project_io.cpp, +format version 1), which the Rust port is byte-compatible with: + + { "format": "lightgui", "version": 1, + "window": { "title", "class_name", "width", "height", "background", + "menubar", "border_style", "icon", "position", + "window_state" }, + "widgets": [ { "name", "type", "x", "y", "width", "height", + "props": {...}, "signals": [...] } ] } + +``save_text`` reproduces the C writer's output byte for byte (same key +order, indentation, and escaping) so files written here load in the C +and Rust designers unchanged. Loading is tolerant of unknown keys and +missing fields but strict about the format tag and version, like the +C loader; widgets whose type is not a known XFrame kind are skipped +(XFrame-only .fdj: legacy GTK widgets are dropped, never converted). +""" + +import json + +from lightgui.xframe import core as _core + +FORMAT = "lightgui" +FORMAT_VERSION = 1 + +DEFAULT_TITLE = "Main Window" +DEFAULT_CLASS_NAME = "MyWindow" +DEFAULT_WIDTH = 800 +DEFAULT_HEIGHT = 600 + +_MIN_WINDOW = 50 +_MAX_WINDOW = 20000 +_MIN_WIDGET = 10 + + +def _clamp_window_size(value, default): + try: + value = int(value) + except (TypeError, ValueError): + return default + if value < _MIN_WINDOW or value > _MAX_WINDOW: + return default + return value + + +def _clamp_range(value, low, high, default): + try: + value = int(value) + except (TypeError, ValueError): + return default + if value < low or value > high: + return default + return value + + +class Project: + """The designed window as data: window settings + placed widgets.""" + + def __init__(self, title=DEFAULT_TITLE, class_name=DEFAULT_CLASS_NAME, + win_width=DEFAULT_WIDTH, win_height=DEFAULT_HEIGHT): + self.title = title + self.class_name = class_name + self.win_width = win_width + self.win_height = win_height + self.background = "" + self.menubar = "" + self.border_style = 0 + self.icon = "" + self.position = 0 + self.window_state = 0 + self.widgets = [] # list[core.Widget], placement order + self.selected_id = None # id of the selected widget, or None + self.skipped = [] # type names skipped by the last load + self._next_id = 1 + self._counters = {} # kind -> count, for unique names + + # --- naming ----------------------------------------------------------- + def next_name(self, kind): + n = self._counters.get(kind, 0) + 1 + self._counters[kind] = n + return "%s_%03d" % (kind, n) + + # --- placed-widget list ------------------------------------------------ + def add_widget(self, kind, x=0, y=0, width=None, height=None, + name=None, props=None, signals=None): + """Place a widget of registry *kind*; returns it, or None if the + kind is unknown. The new widget is selected. Label/text props + are seeded to the instance name, like the Rust designer.""" + if name is None: + name = self.next_name(kind) + widget = _core.create(kind, name, x, y, width, height, + props=props, signals=signals, + widget_id=self._next_id) + if widget is None: + return None + self._next_id += 1 + self.widgets.append(widget) + # Seed label/text to the instance name (Rust seed_defaults). + if widget.archetype in ("Button", "Label", "Toggle", "Entry", + "Container", "Dialog", "Display"): + if "text" not in widget.props and "label" not in widget.props: + widget.set_prop("text", name) + self.select(widget.id) + return widget + + def find(self, widget_id): + for widget in self.widgets: + if widget.id == widget_id: + return widget + return None + + def find_by_name(self, name): + for widget in self.widgets: + if widget.name == name: + return widget + return None + + def remove_widget(self, widget_id): + widget = self.find(widget_id) + if widget is None: + return False + self.widgets.remove(widget) + if self.selected_id == widget_id: + self.selected_id = None + return True + + def move_widget(self, widget_id, x, y): + widget = self.find(widget_id) + if widget is None: + return False + widget.move_to(x, y) + return True + + def resize_widget(self, widget_id, width, height): + widget = self.find(widget_id) + if widget is None: + return False + widget.resize_to(width, height) + return True + + # --- selection ---------------------------------------------------------- + def select(self, widget_id): + if widget_id is None: + self.selected_id = None + for widget in self.widgets: + widget.selected = False + return True + widget = self.find(widget_id) + if widget is None: + return False + for other in self.widgets: + other.selected = other is widget + self.selected_id = widget_id + return True + + def clear_selection(self): + self.select(None) + + @property + def selected(self): + if self.selected_id is None: + return None + return self.find(self.selected_id) + + def hit_test(self, px, py): + """Topmost widget containing (px, py), or None.""" + for widget in reversed(self.widgets): + if widget.contains(px, py): + return widget + return None + + # --- .fdj serialisation ------------------------------------------------- + def to_dict(self): + return { + "format": FORMAT, + "version": FORMAT_VERSION, + "window": { + "title": self.title, + "class_name": self.class_name, + "width": self.win_width, + "height": self.win_height, + "background": self.background, + "menubar": self.menubar, + "border_style": self.border_style, + "icon": self.icon, + "position": self.position, + "window_state": self.window_state, + }, + "widgets": [ + { + "name": w.name, + "type": w.kind, + "x": w.x, + "y": w.y, + "width": w.width, + "height": w.height, + "props": dict(w.props), + "signals": list(w.signals), + } + for w in self.widgets + ], + } + + @classmethod + def from_dict(cls, data): + """Build a Project from parsed .fdj data. Raises ValueError on a + bad format tag, unsupported version, or non-object root.""" + if not isinstance(data, dict): + raise ValueError("project file root is not an object") + if data.get("format") != FORMAT: + raise ValueError("not a lightgui project file") + if data.get("version") != FORMAT_VERSION: + raise ValueError("unsupported format version: %r" + % (data.get("version"),)) + project = cls() + win = data.get("window") + if isinstance(win, dict): + project.title = win.get("title", project.title) or project.title + project.class_name = (win.get("class_name", project.class_name) + or project.class_name) + project.win_width = _clamp_window_size( + win.get("width", project.win_width), DEFAULT_WIDTH) + project.win_height = _clamp_window_size( + win.get("height", project.win_height), DEFAULT_HEIGHT) + project.background = win.get("background", "") or "" + project.menubar = win.get("menubar", "") or "" + project.border_style = _clamp_range( + win.get("border_style", 0), 0, 3, 0) + project.icon = win.get("icon", "") or "" + project.position = _clamp_range(win.get("position", 0), 0, 4, 0) + project.window_state = _clamp_range( + win.get("window_state", 0), 0, 3, 0) + widgets = data.get("widgets") + if isinstance(widgets, list): + for entry in widgets: + if not isinstance(entry, dict): + continue + name = entry.get("name") or "" + kind = entry.get("type") or "" + if not name or not kind: + continue + if not _core.is_known_kind(kind): + project.skipped.append(kind) + continue + try: + x = int(entry.get("x", 0)) + y = int(entry.get("y", 0)) + width = max(int(entry.get("width", 100)), _MIN_WIDGET) + height = max(int(entry.get("height", 30)), _MIN_WIDGET) + except (TypeError, ValueError): + continue + raw_props = entry.get("props") + props = ({str(k): str(v) for k, v in raw_props.items() + if isinstance(v, str)} + if isinstance(raw_props, dict) else {}) + raw_signals = entry.get("signals") + signals = ([str(s) for s in raw_signals + if isinstance(s, str)] + if isinstance(raw_signals, list) else []) + widget = _core.create(kind, name, x, y, width, height, + props=props, signals=signals, + widget_id=project._next_id) + if widget is None: + project.skipped.append(kind) + continue + project._next_id += 1 + project.widgets.append(widget) + # Keep the per-kind name counter past loaded names so a + # later add does not collide (e.g. GtkButton_001 loaded, + # next add is GtkButton_002). + suffix = name.rsplit("_", 1)[-1] + if (name.startswith(kind + "_") and suffix.isdigit() + and int(suffix) > project._counters.get(kind, 0)): + project._counters[kind] = int(suffix) + return project + + def save_text(self): + """Serialise to .fdj text, byte-identical in layout to the C + writer (same key order, indentation, and string escaping).""" + lines = [] + lines.append("{") + lines.append(' "format": "lightgui",') + lines.append(' "version": 1,') + lines.append(' "window": {') + lines.append(' "title": %s,' % _json_str(self.title)) + lines.append(' "class_name": %s,' % _json_str(self.class_name)) + lines.append(' "width": %d,' % self.win_width) + lines.append(' "height": %d,' % self.win_height) + lines.append(' "background": %s,' % _json_str(self.background)) + lines.append(' "menubar": %s,' % _json_str(self.menubar)) + lines.append(' "border_style": %d,' % self.border_style) + lines.append(' "icon": %s,' % _json_str(self.icon)) + lines.append(' "position": %d,' % self.position) + lines.append(' "window_state": %d' % self.window_state) + lines.append(' },') + lines.append(' "widgets": [') + for i, w in enumerate(self.widgets): + lines.append(" {") + lines.append(' "name": %s,' % _json_str(w.name)) + lines.append(' "type": %s,' % _json_str(w.kind)) + lines.append(' "x": %d, "y": %d, "width": %d, "height": %d,' + % (w.x, w.y, w.width, w.height)) + if w.props: + lines.append(' "props": {') + keys = sorted(w.props) + for j, key in enumerate(keys): + comma = "," if j < len(keys) - 1 else "" + lines.append(' %s: %s%s' + % (_json_str(key), _json_str(w.props[key]), + comma)) + lines.append(' },') + else: + lines.append(' "props": {},') + sigs = ", ".join(_json_str(s) for s in w.signals) + lines.append(' "signals": [%s]' % sigs) + lines.append(" }%s" % ("," if i < len(self.widgets) - 1 + else "")) + if self.widgets: + lines.append(" ]") + else: + lines[-1] = ' "widgets": []' + lines.append("}") + return "\n".join(lines) + "\n" + + @classmethod + def load_text(cls, text, path=""): + """Parse .fdj text. Raises ValueError with a C-style message.""" + try: + data = json.loads(text) + except json.JSONDecodeError as exc: + raise ValueError("invalid JSON in %s: %s" % (path, exc)) + try: + return cls.from_dict(data) + except ValueError as exc: + raise ValueError("%s: %s" % (path, exc)) + + def save_file(self, path): + with open(path, "w", encoding="utf-8") as handle: + handle.write(self.save_text()) + + @classmethod + def load_file(cls, path): + try: + with open(path, encoding="utf-8") as handle: + text = handle.read() + except OSError as exc: + raise ValueError("cannot open %s: %s" % (path, exc)) + return cls.load_text(text, path) + + +def _json_str(value): + """Escape one string the way the C writer does (json_escape): + raw UTF-8, \" \\\\ \\n \\r \\t, other control chars as \\u00xx.""" + out = ['"'] + for ch in str(value): + code = ord(ch) + if ch == '"': + out.append('\\"') + elif ch == "\\": + out.append("\\\\") + elif ch == "\n": + out.append("\\n") + elif ch == "\r": + out.append("\\r") + elif ch == "\t": + out.append("\\t") + elif code < 0x20: + out.append("\\u%04x" % code) + else: + out.append(ch) + out.append('"') + return "".join(out) diff --git a/lightgui/xframe/__init__.py b/lightgui/xframe/__init__.py new file mode 100644 index 0000000..b8cf1f0 --- /dev/null +++ b/lightgui/xframe/__init__.py @@ -0,0 +1,25 @@ +"""XFrame widgets: the home-brewed widget set the canvas draws with Cairo. + +GTK is IDE chrome only; the canvas itself is XFrame-native, like the +C and Rust designers. +""" + +from lightgui.xframe.core import ( # noqa: F401 + HANDLE_HIT_PAD, + HANDLE_SIZE, + DBLCLICK_MS, + DRAG_THRESHOLD, + MIN_WIDTH, + MIN_HEIGHT, + Widget, + create, + lookup, + is_known_kind, +) +from lightgui.xframe import palette # noqa: F401 + +__all__ = [ + "HANDLE_SIZE", "HANDLE_HIT_PAD", "DBLCLICK_MS", "DRAG_THRESHOLD", + "MIN_WIDTH", "MIN_HEIGHT", + "Widget", "create", "lookup", "is_known_kind", "palette", +] diff --git a/lightgui/xframe/canvas.py b/lightgui/xframe/canvas.py new file mode 100644 index 0000000..b88d3cc --- /dev/null +++ b/lightgui/xframe/canvas.py @@ -0,0 +1,358 @@ +"""Canvas: a Gtk.DrawingArea that draws all placed widgets with Cairo. + +Interaction ports the C core (src/xframe_canvas_core.cpp) and the Rust +canvas (crates/lightgui-designer/src/canvas.rs): + +- placement: pick a palette kind, click empty canvas to place it + (centred on the click, registry default size); the pending kind + persists across placements, so repeated clicks place many widgets +- selection: click selects; a single click selects and arms a drag, + handles off +- double-click: two presses within 450ms on the same widget show the + handles, regardless of a small jiggle between the presses +- drag: move the widget once the pointer moves more than the 8px + threshold from the press point; dragging a handle resizes it +- Delete/BackSpace deletes the selected widget; Escape clears the + selection (returns it to the window root) and hides the handles +- the canvas tracks its viewport size on resize; there is no fixed + 800x600 canvas — 800x600 is only the project's default window size + +The event state machine lives in :class:`CanvasState`, which is pure +Python over a :class:`lightgui.model.Project` so it can be unit-tested +without a display. :class:`Canvas` is the thin GTK shell around it. +""" + +import time + +import gi + +gi.require_version("Gtk", "3.0") +gi.require_version("Gdk", "3.0") + +from gi.repository import Gdk, Gtk # noqa: E402 + +from lightgui.model import Project # noqa: E402 +from lightgui.xframe import core as _core # noqa: E402 + +BACKGROUND_RGB = (1.0, 1.0, 1.0) +GRID_RGB = (0.88, 0.88, 0.90) + + +def _now_ms(): + return time.monotonic() * 1000.0 + + +class CanvasState: + """Canvas interaction state, display-free. + + Operates on a :class:`lightgui.model.Project`; selection lives on + the project (``selected_id``), handles state lives here (it is UI + state, not saved in .fdj). + """ + + def __init__(self, project=None): + self.project = project if project is not None else Project() + self.pending_kind = None # registry name to place on next click + self.handles_on = False + self.viewport_width = 0 + self.viewport_height = 0 + # Drag bookkeeping. + self.dragging = False # a move drag is armed + self.drag_active = False # past the 8px threshold + self.handle_drag = False + self.drag_handle = -1 + self.press_x = 0 + self.press_y = 0 + self.grab_dx = 0 + self.grab_dy = 0 + self.drag_start_x = 0 + self.drag_start_y = 0 + # Double-click bookkeeping. + self.last_press_id = -1 + self.last_press_ms = 0.0 + self.on_change = None # called after any state change + + # --- selection -------------------------------------------------------- + @property + def selected(self): + return self.project.selected + + def select(self, widget_id): + self.project.select(widget_id) + if widget_id is None: + self.handles_on = False + self._changed() + + def clear_selection(self): + self.project.clear_selection() + self.handles_on = False + self._changed() + + def show_handles(self, widget_id): + if self.project.select(widget_id): + self.handles_on = True + self._changed() + return True + return False + + def set_pending_kind(self, kind): + self.pending_kind = kind if _core.is_known_kind(kind) else None + self._changed() + + # --- placement / mutation ---------------------------------------------- + def place(self, kind, x, y, width=None, height=None): + widget = self.project.add_widget(kind, x, y, width, height) + if widget is not None: + self.handles_on = False + self._changed() + return widget + + def delete_selected(self): + selected = self.project.selected + if selected is None: + return False + self.project.remove_widget(selected.id) + self.handles_on = False + self._changed() + return True + + def resize_viewport(self, width, height): + self.viewport_width = max(int(width), 0) + self.viewport_height = max(int(height), 0) + + # --- input: direct ports of the Rust canvas_* functions ------------------ + def button_press(self, x, y, button=1, now_ms=None): + """Returns True when the press was consumed.""" + if button != 1: + return False + if now_ms is None: + now_ms = _now_ms() + x, y = int(x), int(y) + selected = self.project.selected + # Handle grab first. + if self.handles_on and selected is not None: + handle = selected.handle_at(x, y) + if handle >= 0: + self.handle_drag = True + self.drag_handle = handle + self.drag_start_x = x + self.drag_start_y = y + return True + hit = self.project.hit_test(x, y) + if hit is not None: + double_click = (hit.id == self.last_press_id + and now_ms - self.last_press_ms + < _core.DBLCLICK_MS) + self.last_press_ms = now_ms + self.last_press_id = hit.id + if double_click: + self.project.select(hit.id) + self.handles_on = True + else: + self.project.select(hit.id) + self.handles_on = False + self.dragging = True + self.drag_active = False + self.press_x = x + self.press_y = y + self.grab_dx = x - hit.x + self.grab_dy = y - hit.y + self._changed() + return True + # Empty click: clear selection/handles; place the pending + # palette widget centred on the click, if one is pending. + self.last_press_ms = now_ms + self.last_press_id = -1 + self.clear_selection() + if self.pending_kind is not None: + placed = self.project.add_widget( + self.pending_kind, + max(x - self._pending_default_w() // 2, 0), + max(y - self._pending_default_h() // 2, 0)) + if placed is not None: + self.handles_on = False + self._changed() + return True + + def _pending_default_w(self): + from lightgui.xframe import palette + entry = palette.find(self.pending_kind) + return entry.default_w if entry else 100 + + def _pending_default_h(self): + from lightgui.xframe import palette + entry = palette.find(self.pending_kind) + return entry.default_h if entry else 30 + + def button_release(self, x, y, button=1): + was_drag = self.handle_drag or self.dragging + self.dragging = False + self.handle_drag = False + self.drag_handle = -1 + if was_drag: + self._changed() + return was_drag + + def motion(self, x, y): + """Pointer motion. Returns True when the canvas must redraw.""" + x, y = int(x), int(y) + if self.handle_drag or self.dragging: + selected = self.project.selected + if selected is None: + return False + if self.handle_drag: + dx = x - self.drag_start_x + dy = y - self.drag_start_y + self.drag_start_x = x + self.drag_start_y = y + selected.apply_handle_drag(self.drag_handle, dx, dy) + self._changed() + return True + if not self.drag_active: + if (abs(x - self.press_x) <= _core.DRAG_THRESHOLD + and abs(y - self.press_y) <= _core.DRAG_THRESHOLD): + return False + self.drag_active = True + selected.move_to(x - self.grab_dx, y - self.grab_dy) + self._changed() + return True + return False + + def key(self, key_name): + """Delete/BackSpace/Escape only. Returns True when handled.""" + if key_name in ("Delete", "BackSpace"): + if self.project.selected is None: + return False + return self.delete_selected() + if key_name == "Escape": + had = self.handles_on or self.project.selected is not None + self.clear_selection() + return had + return False + + def _changed(self): + # Keep the per-widget handles flag in sync: Widget.handle_at() + # only answers when its own handles_on is set. + selected = self.project.selected + for widget in self.project.widgets: + widget.handles_on = (widget is selected and self.handles_on) + if self.on_change is not None: + self.on_change() + + +class Canvas(Gtk.DrawingArea): + """Gtk.DrawingArea shell around :class:`CanvasState`.""" + + def __init__(self, project=None, state=None): + super().__init__() + self.state = state if state is not None else CanvasState(project) + self.state.on_change = self._on_state_change + self.set_hexpand(True) + self.set_vexpand(True) + self.set_can_focus(True) + self.add_events( + Gdk.EventMask.BUTTON_PRESS_MASK + | Gdk.EventMask.BUTTON_RELEASE_MASK + | Gdk.EventMask.POINTER_MOTION_MASK + | Gdk.EventMask.KEY_PRESS_MASK + | Gdk.EventMask.STRUCTURE_MASK) + self.connect("draw", self._on_draw) + self.connect("button-press-event", self._on_button_press) + self.connect("button-release-event", self._on_button_release) + self.connect("motion-notify-event", self._on_motion) + self.connect("key-press-event", self._on_key_press) + self.connect("size-allocate", self._on_size_allocate) + + # --- public API --------------------------------------------------------- + @property + def project(self): + return self.state.project + + @property + def pending_kind(self): + return self.state.pending_kind + + def set_pending_kind(self, kind): + self.state.set_pending_kind(kind) + + def place(self, kind, x, y, width=None, height=None): + return self.state.place(kind, x, y, width, height) + + @property + def selected(self): + return self.state.selected + + @property + def viewport_size(self): + return (self.state.viewport_width, self.state.viewport_height) + + # --- GTK event plumbing --------------------------------------------------- + def _on_state_change(self): + self.queue_draw() + + def _on_size_allocate(self, _widget, allocation): + self.state.resize_viewport(allocation.width, allocation.height) + + def _on_button_press(self, _widget, event): + if self.state.button_press(event.x, event.y, event.button): + self.grab_focus() + return True + return False + + def _on_button_release(self, _widget, event): + self.state.button_release(event.x, event.y, event.button) + return True + + def _on_motion(self, _widget, event): + self.state.motion(event.x, event.y) + return True + + def _on_key_press(self, _widget, event): + key_name = Gdk.keyval_name(event.keyval) + return self.state.key(key_name) + + # --- drawing --------------------------------------------------------------- + def _on_draw(self, _widget, cr): + width = self.state.viewport_width + height = self.state.viewport_height + if width <= 0 or height <= 0: + alloc = self.get_allocation() + width, height = alloc.width, alloc.height + cr.save() + cr.set_source_rgb(*BACKGROUND_RGB) + cr.paint() + # Dotted grid, one dot every 24px (Rust redraw_canvas). + cr.set_source_rgb(*GRID_RGB) + gx = _core.GRID_STEP + while gx < width: + gy = _core.GRID_STEP + while gy < height: + cr.rectangle(gx, gy, 1, 1) + gy += _core.GRID_STEP + gx += _core.GRID_STEP + cr.fill() + cr.restore() + for widget in self.state.project.widgets: + widget.draw(cr) + selected = self.state.selected + if selected is not None: + cr.save() + cr.set_source_rgb(*_core.SELECT_RGB) + cr.set_line_width(1.5) + cr.set_dash([4.0, 3.0]) + cr.rectangle(selected.x - 2.5, selected.y - 2.5, + selected.width + 5, selected.height + 5) + cr.stroke() + cr.restore() + if self.state.handles_on: + for i in range(_core.HANDLE_COUNT): + hx, hy, hw, hh = selected.handle_rect(i) + cr.save() + cr.set_source_rgb(*_core.HANDLE_RGB) + cr.rectangle(hx, hy, hw, hh) + cr.fill_preserve() + cr.set_source_rgb(0, 0, 0) + cr.set_line_width(1) + cr.stroke() + cr.restore() + return False diff --git a/lightgui/xframe/core.py b/lightgui/xframe/core.py new file mode 100644 index 0000000..3f27716 --- /dev/null +++ b/lightgui/xframe/core.py @@ -0,0 +1,571 @@ +"""XFrame core: widget base class, registry, draw dispatch, hit-testing. + +Ports the interaction constants and geometry of the C designer +(src/xframe_canvas_core.cpp) and the Rust designer +(crates/lightgui-designer/src/canvas.rs): + +- handles are 13px, hit-tested with an 8px pad on every side +- double-click: two presses within 450ms on the same widget show the + handles, regardless of a small jiggle between the presses +- drag threshold: 8px — sub-8px motion must not move the widget +- resize handles clamp to a 24x16 minimum and to x/y >= 0 + +Setters are state-only: they update the widget's geometry/props and +never draw. The host (the canvas) redraws. Same convention as C/Rust. + +Draw dispatch is by archetype (the Rust port's model: a small set of +archetype classes parameterised by ``kind``, not 547 widget classes). +Each archetype draws itself with Cairo on the canvas context. The +Phase 1 drawings are deliberately simple but recognisable — faithful +per-widget rendering is Phase 2/6 work. +""" + +import math + +from lightgui.xframe import palette as _palette + +# --- interaction constants (C xframe_canvas_core.cpp / Rust canvas.rs) --- +HANDLE_SIZE = 13 +HANDLE_HIT_PAD = 8 +DRAG_THRESHOLD = 8 +DBLCLICK_MS = 450 +MIN_WIDTH = 24 +MIN_HEIGHT = 16 +HANDLE_COUNT = 8 + +# Handle order: NW, N, NE, E, SE, S, SW, W (same as C/Rust). +HANDLE_NAMES = ("NW", "N", "NE", "E", "SE", "S", "SW", "W") + +# Selection outline colour (Rust: 37, 99, 235) and handle fill +# (C/Rust: 255, 127, 0). +SELECT_RGB = (37 / 255, 99 / 255, 235 / 255) +HANDLE_RGB = (1.0, 127 / 255, 0.0) + +GRID_STEP = 24 + + +def _rgb(cr, rgb, alpha=1.0): + cr.set_source_rgba(rgb[0], rgb[1], rgb[2], alpha) + + +def _fit_text(cr, text, max_width): + """Truncate *text* with an ellipsis so it fits *max_width*.""" + if cr.text_extents(text)[2] <= max_width: + return text + while text and cr.text_extents(text + "...")[2] > max_width: + text = text[:-1] + return text + "..." if text else "" + + +def _text(cr, text, x, y, size=13, rgb=(0.12, 0.12, 0.12), align="left", + max_width=None, bold=False): + """Draw one line of text with the Cairo toy font API.""" + if not text: + return + cr.save() + cr.select_font_face("Sans", 0, 1 if bold else 0) + cr.set_font_size(size) + if max_width is not None: + text = _fit_text(cr, text, max_width) + _rgb(cr, rgb) + if align == "center": + w = cr.text_extents(text)[2] + x -= w / 2 + elif align == "right": + w = cr.text_extents(text)[2] + x -= w + cr.move_to(x, y) + cr.show_text(text) + cr.restore() + + +def _box(cr, x, y, w, h, fill, stroke=(0.5, 0.5, 0.5), line_width=1.0): + cr.save() + cr.set_line_width(line_width) + _rgb(cr, fill) + cr.rectangle(x + 0.5, y + 0.5, w - 1, h - 1) + cr.fill_preserve() + _rgb(cr, stroke) + cr.stroke() + cr.restore() + + +class Widget: + """One placed XFrame widget. + + ``kind`` is the registry name (e.g. ``"GtkButton"``); ``name`` is the + instance name (e.g. ``"GtkButton_001"``). Geometry and ``props`` are + plain state; ``set_*`` methods never draw. + """ + + ARCHETYPE = "Display" + + def __init__(self, kind, name, x=0, y=0, width=100, height=30, + props=None, signals=None, widget_id=-1): + self.kind = kind + self.name = name + self.x = int(x) + self.y = int(y) + # Model state only needs a positive size; the 24x16 floor is a + # canvas interaction minimum (see set_bounds), not a model one, + # so a .fdj file holding a 10x10 widget loads as 10x10, like + # the C loader (which clamps to 10). + self.width = max(int(width), 1) + self.height = max(int(height), 1) + self.props = dict(props) if props else {} + self.signals = list(signals) if signals else [] + self.id = widget_id + # Canvas-owned UI state (not saved in .fdj). + self.selected = False + self.handles_on = False + + # --- archetype ------------------------------------------------------ + @property + def archetype(self): + entry = _palette.find(self.kind) + if entry is not None: + return entry.archetype + return self.ARCHETYPE + + @property + def default_width(self): + entry = _palette.find(self.kind) + return entry.default_w if entry is not None else 100 + + @property + def default_height(self): + entry = _palette.find(self.kind) + return entry.default_h if entry is not None else 30 + + # --- state-only setters (the host redraws) ------------------------- + def set_bounds(self, x, y, width, height): + """Canvas-side bounds set (handle drag): 24x16 minimum and + x/y >= 0, mirroring C apply_handle_drag.""" + self.x = max(int(x), 0) + self.y = max(int(y), 0) + self.width = max(int(width), MIN_WIDTH) + self.height = max(int(height), MIN_HEIGHT) + + def move_to(self, x, y): + self.x = max(int(x), 0) + self.y = max(int(y), 0) + + def resize_to(self, width, height): + # Model resize: 10px floor, the same as the C .fdj loader. + self.width = max(int(width), 10) + self.height = max(int(height), 10) + + def set_prop(self, name, value): + """Store a property value (as a string). No live apply here.""" + self.props[str(name)] = "" if value is None else str(value) + + def get_prop(self, name, default=""): + return self.props.get(str(name), default) + + def set_text(self, value): + self.set_prop("text", value) + + @property + def text(self): + """Display text: the text/label prop, else the instance name.""" + return (self.props.get("text") or self.props.get("label") + or self.name) + + # --- hit-testing ---------------------------------------------------- + def contains(self, px, py): + return (self.x <= px <= self.x + self.width + and self.y <= py <= self.y + self.height) + + def handle_centre(self, index): + """Centre of handle *index* (0=NW .. 7=W); corners sit on the + widget corners, edge handles on the edge midpoints.""" + cx = self.x + self.width // 2 + cy = self.y + self.height // 2 + xs = [self.x, cx, self.x + self.width, self.x + self.width, + self.x + self.width, cx, self.x, self.x] + ys = [self.y, self.y, self.y, cy, + self.y + self.height, self.y + self.height, + self.y + self.height, cy] + return xs[index], ys[index] + + def handle_rect(self, index): + cx, cy = self.handle_centre(index) + return (cx - HANDLE_SIZE // 2, cy - HANDLE_SIZE // 2, + HANDLE_SIZE, HANDLE_SIZE) + + def handle_at(self, px, py): + """Handle index at (px, py), or -1. Only when handles are on.""" + if not self.handles_on: + return -1 + for i in range(HANDLE_COUNT): + hx, hy, hw, hh = self.handle_rect(i) + if (hx - HANDLE_HIT_PAD <= px <= hx + hw + HANDLE_HIT_PAD + and hy - HANDLE_HIT_PAD <= py <= hy + hh + HANDLE_HIT_PAD): + return i + return -1 + + def apply_handle_drag(self, index, dx, dy): + """Resize/move by dragging handle *index* by (dx, dy). + Mirrors C apply_handle_drag / Rust apply_handle_drag.""" + x, y, w, h = self.x, self.y, self.width, self.height + if index == 0: # NW + x += dx; y += dy; w -= dx; h -= dy + elif index == 1: # N + y += dy; h -= dy + elif index == 2: # NE + y += dy; w += dx; h -= dy + elif index == 3: # E + w += dx + elif index == 4: # SE + w += dx; h += dy + elif index == 5: # S + h += dy + elif index == 6: # SW + x += dx; w -= dx; h += dy + else: # W + x += dx; w -= dx + self.set_bounds(x, y, w, h) + + # --- drawing -------------------------------------------------------- + def draw(self, cr): + """Draw the widget at its bounds. Dispatches on archetype.""" + cr.save() + cr.translate(self.x, self.y) + cr.rectangle(0, 0, self.width, self.height) + cr.clip() + self._draw(cr) + cr.restore() + + def _draw(self, cr): + _draw_display(cr, self) + + +# --- archetype widgets --------------------------------------------------- +# One class per Rust Archetype enum value. Phase 1 drawings are simple +# but recognisable; faithful per-widget rendering is later-phase work. + +class ButtonWidget(Widget): + ARCHETYPE = "Button" + + def _draw(self, cr): + _box(cr, 0, 0, self.width, self.height, (0.92, 0.92, 0.92), + (0.45, 0.45, 0.45)) + cr.save() + _rgb(cr, (1.0, 1.0, 1.0), 0.6) + cr.rectangle(1, 1, self.width - 2, max(self.height / 2 - 1, 1)) + cr.fill() + cr.restore() + _text(cr, self.text, self.width / 2, self.height / 2 + 5, + align="center", max_width=self.width - 12) + + +class ToggleWidget(Widget): + ARCHETYPE = "Toggle" + + def _draw(self, cr): + if self.kind in ("GtkSwitch", "TSwitch"): + _draw_switch(cr, self) + return + box = 14 + y = (self.height - box) / 2 + _box(cr, 4, y, box, box, (1.0, 1.0, 1.0), (0.4, 0.4, 0.4)) + if "Radio" in self.kind or "TRadio" in self.kind: + cr.save() + _rgb(cr, (0.2, 0.2, 0.2)) + cr.arc(4 + box / 2, y + box / 2, 3.5, 0, 2 * math.pi) + cr.fill() + cr.restore() + elif self.get_prop("checked", "false") in ("true", "1"): + cr.save() + _rgb(cr, (0.2, 0.2, 0.2)) + cr.set_line_width(2) + cr.move_to(7, y + 7) + cr.line_to(10, y + 11) + cr.line_to(16, y + 4) + cr.stroke() + cr.restore() + _text(cr, self.text, 24, self.height / 2 + 5, + max_width=self.width - 28) + + +def _draw_switch(cr, widget): + w, h = widget.width, widget.height + track_h = min(20, h - 4) + y = (h - track_h) / 2 + cr.save() + _rgb(cr, (0.75, 0.75, 0.75)) + cr.rectangle(2, y, w - 4, track_h) + cr.fill() + _rgb(cr, (1.0, 1.0, 1.0)) + cr.arc(2 + track_h / 2, y + track_h / 2, track_h / 2 - 1, 0, + 2 * math.pi) + cr.fill() + cr.restore() + + +class LabelWidget(Widget): + ARCHETYPE = "Label" + + def _draw(self, cr): + _text(cr, self.text, 2, self.height / 2 + 5, + max_width=self.width - 4) + + +class EntryWidget(Widget): + ARCHETYPE = "Entry" + + def _draw(self, cr): + _box(cr, 0, 0, self.width, self.height, (1.0, 1.0, 1.0), + (0.55, 0.55, 0.55)) + _text(cr, self.text, 6, self.height / 2 + 5, + max_width=self.width - 12) + + +class RangeWidget(Widget): + ARCHETYPE = "Range" + + def _draw(self, cr): + mid = self.height / 2 + cr.save() + _rgb(cr, (0.65, 0.65, 0.65)) + cr.set_line_width(3) + cr.move_to(6, mid) + cr.line_to(self.width - 6, mid) + cr.stroke() + frac = 0.5 + try: + lo = float(self.get_prop("minimum", "0")) + hi = float(self.get_prop("maximum", "100")) + val = float(self.get_prop("value", "50")) + frac = 0.0 if hi <= lo else (val - lo) / (hi - lo) + except ValueError: + pass + thumb_x = 6 + frac * max(self.width - 12, 1) + _rgb(cr, (0.92, 0.92, 0.92)) + cr.rectangle(thumb_x - 6, mid - 9, 12, 18) + cr.fill_preserve() + _rgb(cr, (0.45, 0.45, 0.45)) + cr.stroke() + cr.restore() + + +class ListSelWidget(Widget): + ARCHETYPE = "ListSel" + + def _draw(self, cr): + _box(cr, 0, 0, self.width, self.height, (1.0, 1.0, 1.0), + (0.55, 0.55, 0.55)) + rows = [r for r in self.get_prop("items", "").split("|") if r] + if not rows: + rows = [self.text] + y = 18 + for i, row in enumerate(rows[: max((self.height - 8) // 20, 1)]): + if i == 0 and ("Combo" in self.kind or "DropDown" in self.kind): + _rgb(cr, (0.85, 0.88, 0.95)) + cr.rectangle(1, 1, self.width - 2, 20) + cr.fill() + _text(cr, row, 6, y, size=12, max_width=self.width - 12) + y += 20 + if "Combo" in self.kind or "DropDown" in self.kind: + cr.save() + _rgb(cr, (0.3, 0.3, 0.3)) + cx = self.width - 12 + cr.move_to(cx - 5, 8) + cr.line_to(cx + 5, 8) + cr.line_to(cx, 15) + cr.close_path() + cr.fill() + cr.restore() + + +class ContainerWidget(Widget): + ARCHETYPE = "Container" + + def _draw(self, cr): + _box(cr, 0, 0, self.width, self.height, (0.97, 0.97, 0.97), + (0.6, 0.6, 0.6)) + _text(cr, self.text, 8, 14, size=12, rgb=(0.35, 0.35, 0.35), + max_width=self.width - 16) + + +class ChartWidget(Widget): + ARCHETYPE = "Chart" + + def _draw(self, cr): + _box(cr, 0, 0, self.width, self.height, (1.0, 1.0, 1.0), + (0.55, 0.55, 0.55)) + cr.save() + _rgb(cr, (0.75, 0.75, 0.75)) + cr.set_line_width(1) + cr.move_to(24, 6) + cr.line_to(24, self.height - 18) + cr.line_to(self.width - 6, self.height - 18) + cr.stroke() + _rgb(cr, (0.15, 0.35, 0.75)) + cr.set_line_width(1.5) + pts = [(30, self.height - 40), (self.width * 0.35, self.height - 55), + (self.width * 0.6, self.height - 30), + (self.width - 12, self.height - 48)] + cr.move_to(*pts[0]) + for p in pts[1:]: + cr.line_to(*p) + cr.stroke() + cr.restore() + _text(cr, self.kind, 6, 14, size=11, rgb=(0.45, 0.45, 0.45), + max_width=self.width - 12) + + +class IndicatorWidget(Widget): + ARCHETYPE = "Indicator" + + def _draw(self, cr): + _draw_panel(cr, self) + + +class InstrumentWidget(Widget): + ARCHETYPE = "Instrument" + + def _draw(self, cr): + _draw_panel(cr, self) + # Simple gauge needle, centred. + cx, cy = self.width / 2, self.height * 0.62 + r = min(self.width, self.height) * 0.32 + cr.save() + _rgb(cr, (0.2, 0.2, 0.2)) + cr.set_line_width(1.5) + cr.arc(cx, cy, r, math.pi, 2 * math.pi) + cr.stroke() + cr.move_to(cx, cy) + cr.line_to(cx + r * 0.6, cy - r * 0.6) + cr.stroke() + cr.restore() + + +def _draw_panel(cr, widget): + _box(cr, 0, 0, widget.width, widget.height, (0.96, 0.97, 0.99), + (0.5, 0.55, 0.65)) + _text(cr, widget.kind, widget.width / 2, widget.height / 2 - 2, + size=12, align="center", max_width=widget.width - 12) + _text(cr, widget.text if widget.text != widget.name else "", + widget.width / 2, widget.height / 2 + 14, size=11, + rgb=(0.45, 0.45, 0.45), align="center", + max_width=widget.width - 12) + + +class DialogWidget(Widget): + ARCHETYPE = "Dialog" + + def _draw(self, cr): + _box(cr, 0, 0, self.width, self.height, (0.95, 0.95, 0.95), + (0.4, 0.4, 0.4)) + cr.save() + _rgb(cr, (0.25, 0.45, 0.75)) + cr.rectangle(1, 1, self.width - 2, 24) + cr.fill() + cr.restore() + _text(cr, self.text, 8, 18, size=12, rgb=(1.0, 1.0, 1.0), + bold=True, max_width=self.width - 16) + bw, bh = 64, 22 + bx = self.width - bw - 10 + by = self.height - bh - 10 + if self.width > 150 and self.height > 70: + _box(cr, bx, by, bw, bh, (0.92, 0.92, 0.92), + (0.45, 0.45, 0.45)) + _text(cr, "OK", bx + bw / 2, by + 16, size=12, + align="center") + + +def _draw_display(cr, widget): + _box(cr, 0, 0, widget.width, widget.height, (1.0, 1.0, 1.0), + (0.55, 0.55, 0.55)) + _text(cr, widget.kind, widget.width / 2, widget.height / 2 + 5, + size=12, rgb=(0.4, 0.4, 0.4), align="center", + max_width=widget.width - 12) + + +class DisplayWidget(Widget): + ARCHETYPE = "Display" + + +class GraphWidget(Widget): + ARCHETYPE = "Graph" + + def _draw(self, cr): + ChartWidget._draw(self, cr) + + +class SpreadsheetWidget(Widget): + ARCHETYPE = "Spreadsheet" + + def _draw(self, cr): + _box(cr, 0, 0, self.width, self.height, (1.0, 1.0, 1.0), + (0.55, 0.55, 0.55)) + cr.save() + _rgb(cr, (0.8, 0.8, 0.8)) + cr.set_line_width(1) + x = 48 + while x < self.width: + cr.move_to(x, 0) + cr.line_to(x, self.height) + x += 48 + y = 20 + while y < self.height: + cr.move_to(0, y) + cr.line_to(self.width, y) + y += 20 + cr.stroke() + cr.restore() + + +ARCHETYPE_CLASSES = { + "Button": ButtonWidget, + "Toggle": ToggleWidget, + "Label": LabelWidget, + "Entry": EntryWidget, + "Range": RangeWidget, + "ListSel": ListSelWidget, + "Container": ContainerWidget, + "Chart": ChartWidget, + "Indicator": IndicatorWidget, + "Instrument": InstrumentWidget, + "Dialog": DialogWidget, + "Display": DisplayWidget, + "Graph": GraphWidget, + "Spreadsheet": SpreadsheetWidget, +} + + +# --- registry ------------------------------------------------------------- +# kind (registry name) -> archetype class. Every one of the 547 palette +# kinds resolves through the palette table; unknown kinds fall back to +# the generic Display drawing so a hand-edited .fdj cannot break the +# canvas (the .fdj loader skips unknown kinds before this point). + +def lookup(kind): + """Archetype class for a registry *kind*, or None if unknown.""" + entry = _palette.find(kind) + if entry is None: + return None + return ARCHETYPE_CLASSES[entry.archetype] + + +def create(kind, name, x=0, y=0, width=None, height=None, props=None, + signals=None, widget_id=-1): + """Build a widget of registry *kind*. Returns None if unknown. + + ``width``/``height`` default to the registry default size. + """ + cls = lookup(kind) + if cls is None: + return None + entry = _palette.find(kind) + if width is None: + width = entry.default_w + if height is None: + height = entry.default_h + return cls(kind, name, x, y, width, height, props=props, + signals=signals, widget_id=widget_id) + + +def is_known_kind(kind): + return _palette.find(kind) is not None diff --git a/lightgui/xframe/palette.py b/lightgui/xframe/palette.py new file mode 100644 index 0000000..1cd8aa7 --- /dev/null +++ b/lightgui/xframe/palette.py @@ -0,0 +1,661 @@ +"""Palette data: all 547 XFrame widgets in their 11 section groups. + +GENERATED -- do not edit by hand. Derived on the server by parsing +/opt/lightgui_rust/crates/xframe-widgets/src/registry_gen.rs +(itself generated from the C registry, lightgui eb0b5fc). +Cross-checked against /opt/lightgui/src/xframe_palette.h: the +(name, section, registry index) triples are identical in both +sources, so this table is the C palette as well as the Rust one. + +NOTE on the count: the Phase 1 brief said "583 entries (547 widgets)". +That 583 is the total in /opt/lightgui_rust/data/palette.json: +547 XFrame widgets plus 36 legacy "lightgui" type keys (the old +C model.h kTypes table: Button, Label, Entry, ... Plot). The +legacy 36 are NOT XFrame widgets -- they are the pre-XFrame model +types, and the C/Rust .fdj loaders drop non-XFrame types on load. +The placeable palette itself is the 547 XFrame entries below +(the Rust designer main.rs calls it "the XFrame-only 547-entry +palette", and the C header says kXFramePaletteCount = 547). +The 36 legacy keys are recorded separately as LEGACY_TYPES at +the end of this module, for reference only. +""" + +from collections import namedtuple + +PaletteEntry = namedtuple( + "PaletteEntry", + "index name family section section_index default_w default_h archetype kind", +) + +SECTIONS = ( + 'Windows & Dialogs', + 'Containers & Layout', + 'Buttons', + 'Display', + 'Text & Entry', + 'Choosers', + 'Views & Lists', + 'Menus & Toolbars', + 'Misc / X', + 'Stock Market', + 'Instrumentation', +) + +PALETTE = ( + PaletteEntry(0, 'GtkAboutDialog', 'Gtk', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'AboutDialog'), + PaletteEntry(1, 'GtkAccelLabel', 'Gtk', 'Display', 3, 180, 30, 'Label', 'AccelLabel'), + PaletteEntry(2, 'GtkActionBar', 'Gtk', 'Menus & Toolbars', 7, 200, 90, 'Container', 'ActionBar'), + PaletteEntry(3, 'GtkAppChooserButton', 'Gtk', 'Choosers', 5, 150, 36, 'Button', 'AppChooserButton'), + PaletteEntry(4, 'GtkAppChooserDialog', 'Gtk', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'AppChooserDialog'), + PaletteEntry(5, 'GtkAppChooserWidget', 'Gtk', 'Choosers', 5, 200, 90, 'Container', 'AppChooserWidget'), + PaletteEntry(6, 'GtkApplicationWindow', 'Gtk', 'Windows & Dialogs', 0, 300, 220, 'Container', 'ApplicationWindow'), + PaletteEntry(7, 'GtkAspectFrame', 'Gtk', 'Containers & Layout', 1, 200, 90, 'Container', 'AspectFrame'), + PaletteEntry(8, 'GtkAssistant', 'Gtk', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'Assistant'), + PaletteEntry(9, 'GtkBox', 'Gtk', 'Containers & Layout', 1, 200, 90, 'Container', 'Box'), + PaletteEntry(10, 'GtkButton', 'Gtk', 'Buttons', 2, 150, 36, 'Button', 'Button'), + PaletteEntry(11, 'GtkButtonBox', 'Gtk', 'Containers & Layout', 1, 150, 36, 'Container', 'ButtonBox'), + PaletteEntry(12, 'GtkCalendar', 'Gtk', 'Display', 3, 200, 90, 'Container', 'Calendar'), + PaletteEntry(13, 'GtkCellView', 'Gtk', 'Display', 3, 200, 90, 'Display', 'CellView'), + PaletteEntry(14, 'GtkCenterBox', 'Gtk', 'Containers & Layout', 1, 200, 90, 'Container', 'CenterBox'), + PaletteEntry(15, 'GtkCheckButton', 'Gtk', 'Buttons', 2, 150, 36, 'Toggle', 'CheckButton'), + PaletteEntry(16, 'GtkCheckMenuItem', 'Gtk', 'Menus & Toolbars', 7, 150, 36, 'Toggle', 'CheckMenuItem'), + PaletteEntry(17, 'GtkColorButton', 'Gtk', 'Buttons', 2, 150, 36, 'Button', 'ColorButton'), + PaletteEntry(18, 'GtkColorChooserDialog', 'Gtk', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'ColorChooserDialog'), + PaletteEntry(19, 'GtkColorChooserWidget', 'Gtk', 'Choosers', 5, 200, 90, 'Container', 'ColorChooserWidget'), + PaletteEntry(20, 'GtkColorDialogButton', 'Gtk', 'Buttons', 2, 300, 220, 'Button', 'ColorDialogButton'), + PaletteEntry(21, 'GtkColumnView', 'Gtk', 'Views & Lists', 6, 260, 180, 'ListSel', 'ColumnView'), + PaletteEntry(22, 'GtkComboBox', 'Gtk', 'Text & Entry', 4, 180, 30, 'ListSel', 'ComboBox'), + PaletteEntry(23, 'GtkComboBoxText', 'Gtk', 'Text & Entry', 4, 180, 30, 'ListSel', 'ComboBoxText'), + PaletteEntry(24, 'GtkDialog', 'Gtk', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'Dialog'), + PaletteEntry(25, 'GtkDrawingArea', 'Gtk', 'Display', 3, 200, 90, 'Display', 'DrawingArea'), + PaletteEntry(26, 'GtkDropDown', 'Gtk', 'Text & Entry', 4, 200, 90, 'ListSel', 'DropDown'), + PaletteEntry(27, 'GtkEditableLabel', 'Gtk', 'Text & Entry', 4, 180, 30, 'Entry', 'EditableLabel'), + PaletteEntry(28, 'GtkEntry', 'Gtk', 'Text & Entry', 4, 180, 30, 'Entry', 'Entry'), + PaletteEntry(29, 'GtkEntryCompletion', 'Gtk', 'Text & Entry', 4, 180, 30, 'ListSel', 'EntryCompletion'), + PaletteEntry(30, 'GtkEventBox', 'Gtk', 'Misc / X', 8, 200, 90, 'Container', 'EventBox'), + PaletteEntry(31, 'GtkExpander', 'Gtk', 'Containers & Layout', 1, 200, 90, 'Container', 'Expander'), + PaletteEntry(32, 'GtkFileChooserButton', 'Gtk', 'Buttons', 2, 150, 36, 'Button', 'FileChooserButton'), + PaletteEntry(33, 'GtkFileChooserDialog', 'Gtk', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'FileChooserDialog'), + PaletteEntry(34, 'GtkFileChooserWidget', 'Gtk', 'Choosers', 5, 200, 90, 'Container', 'FileChooserWidget'), + PaletteEntry(35, 'GtkFixed', 'Gtk', 'Containers & Layout', 1, 200, 90, 'Container', 'Fixed'), + PaletteEntry(36, 'GtkFlowBox', 'Gtk', 'Containers & Layout', 1, 200, 90, 'ListSel', 'FlowBox'), + PaletteEntry(37, 'GtkFontButton', 'Gtk', 'Buttons', 2, 150, 36, 'Button', 'FontButton'), + PaletteEntry(38, 'GtkFontChooserDialog', 'Gtk', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'FontChooserDialog'), + PaletteEntry(39, 'GtkFontChooserWidget', 'Gtk', 'Choosers', 5, 200, 90, 'Container', 'FontChooserWidget'), + PaletteEntry(40, 'GtkFrame', 'Gtk', 'Containers & Layout', 1, 200, 90, 'Container', 'Frame'), + PaletteEntry(41, 'GtkGLArea', 'Gtk', 'Display', 3, 200, 90, 'Display', 'GLArea'), + PaletteEntry(42, 'GtkGrid', 'Gtk', 'Containers & Layout', 1, 260, 180, 'Container', 'Grid'), + PaletteEntry(43, 'GtkGridView', 'Gtk', 'Views & Lists', 6, 260, 180, 'ListSel', 'GridView'), + PaletteEntry(44, 'GtkHeaderBar', 'Gtk', 'Menus & Toolbars', 7, 200, 90, 'Container', 'HeaderBar'), + PaletteEntry(45, 'GtkIconView', 'Gtk', 'Views & Lists', 6, 200, 90, 'ListSel', 'IconView'), + PaletteEntry(46, 'GtkImage', 'Gtk', 'Display', 3, 200, 90, 'Display', 'Image'), + PaletteEntry(47, 'GtkInfoBar', 'Gtk', 'Display', 3, 200, 90, 'Container', 'InfoBar'), + PaletteEntry(48, 'GtkInscription', 'Gtk', 'Display', 3, 200, 90, 'Label', 'Inscription'), + PaletteEntry(49, 'GtkInvisible', 'Gtk', 'Display', 3, 200, 90, 'Display', 'Invisible'), + PaletteEntry(50, 'GtkLabel', 'Gtk', 'Display', 3, 180, 30, 'Label', 'Label'), + PaletteEntry(51, 'GtkLayout', 'Gtk', 'Containers & Layout', 1, 200, 90, 'Container', 'Layout'), + PaletteEntry(52, 'GtkLevelBar', 'Gtk', 'Display', 3, 180, 30, 'Range', 'LevelBar'), + PaletteEntry(53, 'GtkLinkButton', 'Gtk', 'Buttons', 2, 150, 36, 'Button', 'LinkButton'), + PaletteEntry(54, 'GtkListBox', 'Gtk', 'Views & Lists', 6, 200, 90, 'ListSel', 'ListBox'), + PaletteEntry(55, 'GtkListView', 'Gtk', 'Views & Lists', 6, 260, 180, 'ListSel', 'ListView'), + PaletteEntry(56, 'GtkLockButton', 'Gtk', 'Buttons', 2, 150, 36, 'Button', 'LockButton'), + PaletteEntry(57, 'GtkMediaControls', 'Gtk', 'Display', 3, 200, 90, 'Display', 'MediaControls'), + PaletteEntry(58, 'GtkMenu', 'Gtk', 'Menus & Toolbars', 7, 200, 90, 'ListSel', 'Menu'), + PaletteEntry(59, 'GtkMenuBar', 'Gtk', 'Menus & Toolbars', 7, 200, 90, 'ListSel', 'MenuBar'), + PaletteEntry(60, 'GtkMenuButton', 'Gtk', 'Menus & Toolbars', 7, 150, 36, 'Button', 'MenuButton'), + PaletteEntry(61, 'GtkMenuItem', 'Gtk', 'Menus & Toolbars', 7, 200, 90, 'ListSel', 'MenuItem'), + PaletteEntry(62, 'GtkMessageDialog', 'Gtk', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'MessageDialog'), + PaletteEntry(63, 'GtkModelButton', 'Gtk', 'Buttons', 2, 150, 36, 'Button', 'ModelButton'), + PaletteEntry(64, 'GtkNotebook', 'Gtk', 'Containers & Layout', 1, 260, 180, 'Container', 'Notebook'), + PaletteEntry(65, 'GtkOverlay', 'Gtk', 'Containers & Layout', 1, 200, 90, 'Container', 'Overlay'), + PaletteEntry(66, 'GtkPaned', 'Gtk', 'Containers & Layout', 1, 200, 90, 'Container', 'Paned'), + PaletteEntry(67, 'GtkPasswordEntry', 'Gtk', 'Text & Entry', 4, 180, 30, 'Entry', 'PasswordEntry'), + PaletteEntry(68, 'GtkPicture', 'Gtk', 'Display', 3, 200, 90, 'Display', 'Picture'), + PaletteEntry(69, 'GtkPlacesSidebar', 'Gtk', 'Choosers', 5, 200, 90, 'Container', 'PlacesSidebar'), + PaletteEntry(70, 'GtkPopover', 'Gtk', 'Menus & Toolbars', 7, 200, 90, 'Container', 'Popover'), + PaletteEntry(71, 'GtkPrintUnixDialog', 'Gtk', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'PrintUnixDialog'), + PaletteEntry(72, 'GtkProgressBar', 'Gtk', 'Display', 3, 180, 30, 'Range', 'ProgressBar'), + PaletteEntry(73, 'GtkRadioButton', 'Gtk', 'Buttons', 2, 150, 36, 'Toggle', 'RadioButton'), + PaletteEntry(74, 'GtkRadioMenuItem', 'Gtk', 'Menus & Toolbars', 7, 150, 36, 'Toggle', 'RadioMenuItem'), + PaletteEntry(75, 'GtkRevealer', 'Gtk', 'Containers & Layout', 1, 200, 90, 'Container', 'Revealer'), + PaletteEntry(76, 'GtkScale', 'Gtk', 'Text & Entry', 4, 180, 30, 'Range', 'Scale'), + PaletteEntry(77, 'GtkScaleButton', 'Gtk', 'Text & Entry', 4, 150, 36, 'Range', 'ScaleButton'), + PaletteEntry(78, 'GtkScrollbar', 'Gtk', 'Containers & Layout', 1, 180, 30, 'Range', 'Scrollbar'), + PaletteEntry(79, 'GtkScrolledWindow', 'Gtk', 'Containers & Layout', 1, 300, 220, 'Container', 'ScrolledWindow'), + PaletteEntry(80, 'GtkSearchBar', 'Gtk', 'Text & Entry', 4, 180, 30, 'Container', 'SearchBar'), + PaletteEntry(81, 'GtkSearchEntry', 'Gtk', 'Text & Entry', 4, 180, 30, 'Entry', 'SearchEntry'), + PaletteEntry(82, 'GtkSeparator', 'Gtk', 'Containers & Layout', 1, 180, 30, 'Display', 'Separator'), + PaletteEntry(83, 'GtkSeparatorMenuItem', 'Gtk', 'Menus & Toolbars', 7, 180, 30, 'Display', 'SeparatorMenuItem'), + PaletteEntry(84, 'GtkShortcutsWindow', 'Gtk', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'ShortcutsWindow'), + PaletteEntry(85, 'GtkSpinButton', 'Gtk', 'Text & Entry', 4, 150, 36, 'Range', 'SpinButton'), + PaletteEntry(86, 'GtkSpinner', 'Gtk', 'Display', 3, 150, 36, 'Display', 'Spinner'), + PaletteEntry(87, 'GtkStack', 'Gtk', 'Containers & Layout', 1, 260, 180, 'Container', 'Stack'), + PaletteEntry(88, 'GtkStackSidebar', 'Gtk', 'Containers & Layout', 1, 260, 180, 'ListSel', 'StackSidebar'), + PaletteEntry(89, 'GtkStackSwitcher', 'Gtk', 'Containers & Layout', 1, 260, 180, 'ListSel', 'StackSwitcher'), + PaletteEntry(90, 'GtkStatusbar', 'Gtk', 'Display', 3, 180, 30, 'Container', 'Statusbar'), + PaletteEntry(91, 'GtkSwitch', 'Gtk', 'Buttons', 2, 150, 36, 'Toggle', 'Switch'), + PaletteEntry(92, 'GtkTextView', 'Gtk', 'Text & Entry', 4, 260, 180, 'Entry', 'TextView'), + PaletteEntry(93, 'GtkToggleButton', 'Gtk', 'Buttons', 2, 150, 36, 'Toggle', 'ToggleButton'), + PaletteEntry(94, 'GtkToggleToolButton', 'Gtk', 'Buttons', 2, 150, 36, 'Button', 'ToggleToolButton'), + PaletteEntry(95, 'GtkToolButton', 'Gtk', 'Buttons', 2, 150, 36, 'Button', 'ToolButton'), + PaletteEntry(96, 'GtkToolbar', 'Gtk', 'Menus & Toolbars', 7, 200, 90, 'ListSel', 'Toolbar'), + PaletteEntry(97, 'GtkTreeView', 'Gtk', 'Views & Lists', 6, 260, 180, 'ListSel', 'TreeView'), + PaletteEntry(98, 'GtkVideo', 'Gtk', 'Display', 3, 200, 90, 'Display', 'Video'), + PaletteEntry(99, 'GtkViewport', 'Gtk', 'Containers & Layout', 1, 200, 90, 'Container', 'Viewport'), + PaletteEntry(100, 'GtkVolumeButton', 'Gtk', 'Buttons', 2, 150, 36, 'Button', 'VolumeButton'), + PaletteEntry(101, 'GtkWindow', 'Gtk', 'Windows & Dialogs', 0, 300, 220, 'Container', 'Window'), + PaletteEntry(102, 'IndADX', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'ADX'), + PaletteEntry(103, 'IndADXR', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'ADXR'), + PaletteEntry(104, 'IndALMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'ALMA'), + PaletteEntry(105, 'IndAPO', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'APO'), + PaletteEntry(106, 'IndATR', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'ATR'), + PaletteEntry(107, 'IndAcceleratorOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Accelerator Oscillator'), + PaletteEntry(108, 'IndAccumulationDistributionLine', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'A/D Line'), + PaletteEntry(109, 'IndAccumulativeSwingIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Accumulative Swing Index'), + PaletteEntry(110, 'IndAdaptiveCyberCycle', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Cyber Cycle'), + PaletteEntry(111, 'IndAdaptiveRSI', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'RSI'), + PaletteEntry(112, 'IndAlligatorJaw', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Alligator'), + PaletteEntry(113, 'IndAlligatorLips', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Alligator'), + PaletteEntry(114, 'IndAlligatorTeeth', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Alligator'), + PaletteEntry(115, 'IndAnchoredVWAP', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'VWAP'), + PaletteEntry(116, 'IndAroonDown', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Aroon'), + PaletteEntry(117, 'IndAroonOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Aroon Oscillator'), + PaletteEntry(118, 'IndAroonUp', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Aroon'), + PaletteEntry(119, 'IndAutocorrelation', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'autocorrelation'), + PaletteEntry(120, 'IndAwesomeOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Awesome Oscillator'), + PaletteEntry(121, 'IndBalanceOfPower', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Balance of Power'), + PaletteEntry(122, 'IndBearPower', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Bear Power'), + PaletteEntry(123, 'IndBollingerBands', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Bollinger Bands'), + PaletteEntry(124, 'IndBollingerBandwidth', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Bollinger Bandwidth'), + PaletteEntry(125, 'IndBollingerPercentB', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Bollinger %B'), + PaletteEntry(126, 'IndBullPower', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Bull Power'), + PaletteEntry(127, 'IndCCI', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'CCI'), + PaletteEntry(128, 'IndCamarillaPivotPoints', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Pivot Points Camarilla'), + PaletteEntry(129, 'IndCenterOfGravity', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'CG Oscillator'), + PaletteEntry(130, 'IndChaikinMoneyFlow', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Chaikin Money Flow'), + PaletteEntry(131, 'IndChaikinOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Chaikin Oscillator'), + PaletteEntry(132, 'IndChaikinVolatility', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Chaikin Volatility'), + PaletteEntry(133, 'IndChandeForecastOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Forecast Oscillator'), + PaletteEntry(134, 'IndChandeKrollStop', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'chande_kroll_stop'), + PaletteEntry(135, 'IndChandeMomentumOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'CMO'), + PaletteEntry(136, 'IndChandelierExit', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Chandelier Exit'), + PaletteEntry(137, 'IndChandelierExitLong', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Chandelier Exit'), + PaletteEntry(138, 'IndChandelierExitShort', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Chandelier Exit'), + PaletteEntry(139, 'IndChikouSpan', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Ichimoku'), + PaletteEntry(140, 'IndChoppinessIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Choppiness Index'), + PaletteEntry(141, 'IndCloseVolatility', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'close_volatility'), + PaletteEntry(142, 'IndConnorsRSI', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Connors RSI'), + PaletteEntry(143, 'IndCoppockCurve', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Coppock Curve'), + PaletteEntry(144, 'IndCorrelation', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'correlation'), + PaletteEntry(145, 'IndCorrelationCoefficient', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'correlation_coefficient'), + PaletteEntry(146, 'IndCovariance', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'covariance'), + PaletteEntry(147, 'IndCumulativeVolumeDelta', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'cumulative_volume_delta'), + PaletteEntry(148, 'IndCutlerRSI', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'RSI'), + PaletteEntry(149, 'IndCyberCycle', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Cyber Cycle'), + PaletteEntry(150, 'IndDEMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'DEMA'), + PaletteEntry(151, 'IndDPO', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'DPO'), + PaletteEntry(152, 'IndDSS', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'd_s_s'), + PaletteEntry(153, 'IndDX', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'DX'), + PaletteEntry(154, 'IndDeMarker', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'DeMarker'), + PaletteEntry(155, 'IndDecycler', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Decycler'), + PaletteEntry(156, 'IndDemandIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Demand Index'), + PaletteEntry(157, 'IndDetrendedPriceOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'DPO'), + PaletteEntry(158, 'IndDisparityIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Disparity Index'), + PaletteEntry(159, 'IndDominantCycle', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Cyber Cycle'), + PaletteEntry(160, 'IndDominantCyclePeriod', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'HT DC Period'), + PaletteEntry(161, 'IndDonchianChannels', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Donchian Channels'), + PaletteEntry(162, 'IndDonchianLower', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Donchian Channels'), + PaletteEntry(163, 'IndDonchianMiddle', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Donchian Channels'), + PaletteEntry(164, 'IndDonchianUpper', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Donchian Channels'), + PaletteEntry(165, 'IndDoubleStochastic', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'double_stochastic'), + PaletteEntry(166, 'IndDynamicMomentumIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Momentum'), + PaletteEntry(167, 'IndEMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'EMA'), + PaletteEntry(168, 'IndEaseOfMovement', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Ease of Movement'), + PaletteEntry(169, 'IndEfficiencyRatio', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Efficiency Ratio'), + PaletteEntry(170, 'IndEhlersDecycler', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Decycler'), + PaletteEntry(171, 'IndEhlersSmoothedRSI', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'RSI'), + PaletteEntry(172, 'IndEhlersSuperSmoother', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Super Smoother'), + PaletteEntry(173, 'IndEhlersTrendline', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'HT Trendline'), + PaletteEntry(174, 'IndElderForceIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Force Index'), + PaletteEntry(175, 'IndElderImpulse', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Elder Impulse'), + PaletteEntry(176, 'IndElderRayBear', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Bear Power'), + PaletteEntry(177, 'IndElderRayBull', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Bull Power'), + PaletteEntry(178, 'IndElderSafeZone', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'elder_safe_zone'), + PaletteEntry(179, 'IndErgodicOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'TSI'), + PaletteEntry(180, 'IndEvenBetterSineWave', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'even_better_sine_wave'), + PaletteEntry(181, 'IndFAMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'FAMA'), + PaletteEntry(182, 'IndFRAMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'FRAMA'), + PaletteEntry(183, 'IndFibonacciPivotPoints', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Pivot Points Fibonacci'), + PaletteEntry(184, 'IndFisherTransform', 'Ind', 'Stock Market', 9, 300, 220, 'Indicator', 'Fisher Transform'), + PaletteEntry(185, 'IndFractalDimension', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'fractal_dimension'), + PaletteEntry(186, 'IndFractalDimensionIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Polarized Fractal Efficiency'), + PaletteEntry(187, 'IndFractalDown', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Williams Fractals'), + PaletteEntry(188, 'IndFractalUp', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Williams Fractals'), + PaletteEntry(189, 'IndGannHiLoActivator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'gann_hi_lo_activator'), + PaletteEntry(190, 'IndGannSwingOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'gann_swing_oscillator'), + PaletteEntry(191, 'IndGarmanKlassVolatility', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Garman-Klass Volatility'), + PaletteEntry(192, 'IndGatorOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Gator Oscillator'), + PaletteEntry(193, 'IndGaussianMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Gaussian Filter'), + PaletteEntry(194, 'IndGopalakrishnanRangeIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'gopalakrishnan_range_index'), + PaletteEntry(195, 'IndGuppyMMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Guppy MMA'), + PaletteEntry(196, 'IndHMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'HMA'), + PaletteEntry(197, 'IndHalfTrend', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'half_trend'), + PaletteEntry(198, 'IndHighLowRange', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'high_low_range'), + PaletteEntry(199, 'IndHistoricalVolatility', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Historical Volatility'), + PaletteEntry(200, 'IndHurstExponent', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'hurst_exponent'), + PaletteEntry(201, 'IndInertia', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'inertia'), + PaletteEntry(202, 'IndIntradayIntensityIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Intraday Intensity'), + PaletteEntry(203, 'IndIntradayMomentumIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Momentum'), + PaletteEntry(204, 'IndInverseFisherTransform', 'Ind', 'Stock Market', 9, 300, 220, 'Indicator', 'Fisher Transform'), + PaletteEntry(205, 'IndJurikMovingAverage', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Jurik MA'), + PaletteEntry(206, 'IndJurikVelocity', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'jurik_velocity'), + PaletteEntry(207, 'IndKAMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'KAMA'), + PaletteEntry(208, 'IndKDJ', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'k_d_j'), + PaletteEntry(209, 'IndKST', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'KST'), + PaletteEntry(210, 'IndKairi', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'kairi'), + PaletteEntry(211, 'IndKeltnerBandwidth', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'keltner_bandwidth'), + PaletteEntry(212, 'IndKeltnerChannels', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Keltner Channels'), + PaletteEntry(213, 'IndKijunSen', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Ichimoku'), + PaletteEntry(214, 'IndKlingerVolumeOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Klinger Oscillator'), + PaletteEntry(215, 'IndKurtosis', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Kurtosis'), + PaletteEntry(216, 'IndLSMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'LSMA'), + PaletteEntry(217, 'IndLaguerreFilter', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Laguerre Filter'), + PaletteEntry(218, 'IndLaguerreRSI', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Laguerre RSI'), + PaletteEntry(219, 'IndLinReg', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'TSF'), + PaletteEntry(220, 'IndLinRegAngle', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Linear Regression Angle'), + PaletteEntry(221, 'IndLinRegIntercept', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Linear Regression Intercept'), + PaletteEntry(222, 'IndLinRegSlope', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Linear Regression Slope'), + PaletteEntry(223, 'IndLinearRegressionForecast', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'TSF'), + PaletteEntry(224, 'IndLinearRegressionIntercept', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Linear Regression Intercept'), + PaletteEntry(225, 'IndLinearRegressionOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Forecast Oscillator'), + PaletteEntry(226, 'IndLinearRegressionSlope', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Linear Regression Slope'), + PaletteEntry(227, 'IndMACD', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'MACD'), + PaletteEntry(228, 'IndMACDHistogram', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'MACD Histogram'), + PaletteEntry(229, 'IndMACDofRSI', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'RSI'), + PaletteEntry(230, 'IndMAEnvelopeLower', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'MA Envelope'), + PaletteEntry(231, 'IndMAEnvelopeUpper', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'MA Envelope'), + PaletteEntry(232, 'IndMAMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'MAMA'), + PaletteEntry(233, 'IndMassIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Mass Index'), + PaletteEntry(234, 'IndMcGinley', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'McGinley Dynamic'), + PaletteEntry(235, 'IndMedianMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'median_m_a'), + PaletteEntry(236, 'IndMedianPrice', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Median Price'), + PaletteEntry(237, 'IndMinusDI', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Minus DI'), + PaletteEntry(238, 'IndMomentum', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Momentum'), + PaletteEntry(239, 'IndMoneyFlowIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'MFI'), + PaletteEntry(240, 'IndMoneyFlowVolume', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'money_flow_volume'), + PaletteEntry(241, 'IndMovingAverageRibbon', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'moving_average_ribbon'), + PaletteEntry(242, 'IndNATR', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'NATR'), + PaletteEntry(243, 'IndNegativeVolumeIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'NVI'), + PaletteEntry(244, 'IndNormalizedROC', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'ROC'), + PaletteEntry(245, 'IndOBV', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'OBV'), + PaletteEntry(246, 'IndPPO', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'PPO'), + PaletteEntry(247, 'IndPSAR', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Parabolic SAR'), + PaletteEntry(248, 'IndParkinsonVolatility', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Parkinson Volatility'), + PaletteEntry(249, 'IndPercentRank', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'percent_rank'), + PaletteEntry(250, 'IndPercentageVolumeOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Volume'), + PaletteEntry(251, 'IndPercentileRank', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'percentile_rank'), + PaletteEntry(252, 'IndPivotPoint', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Pivot Points Standard'), + PaletteEntry(253, 'IndPlusDI', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Plus DI'), + PaletteEntry(254, 'IndPositiveVolumeIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'PVI'), + PaletteEntry(255, 'IndPrettyGoodOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'pretty_good_oscillator'), + PaletteEntry(256, 'IndPriceMomentumOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Momentum'), + PaletteEntry(257, 'IndQStick', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Qstick'), + PaletteEntry(258, 'IndRMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'SMMA'), + PaletteEntry(259, 'IndROC', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'ROC'), + PaletteEntry(260, 'IndROCR', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'ROC'), + PaletteEntry(261, 'IndRSI', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'RSI'), + PaletteEntry(262, 'IndRSX', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'RSI'), + PaletteEntry(263, 'IndRSquared', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'R-Squared'), + PaletteEntry(264, 'IndRWIHigh', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Random Walk Index'), + PaletteEntry(265, 'IndRWILow', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Random Walk Index'), + PaletteEntry(266, 'IndRainbowOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'rainbow_oscillator'), + PaletteEntry(267, 'IndRangeExpansionIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'range_expansion_index'), + PaletteEntry(268, 'IndReflex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'reflex'), + PaletteEntry(269, 'IndRegressionChannel', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Linear Regression Channel'), + PaletteEntry(270, 'IndRelativeMomentumIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'RMI'), + PaletteEntry(271, 'IndRelativeVigorIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Relative Vigor Index'), + PaletteEntry(272, 'IndRelativeVolatilityIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Relative Volatility Index'), + PaletteEntry(273, 'IndRelativeVolume', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Volume'), + PaletteEntry(274, 'IndRogersSatchellVolatility', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Rogers-Satchell Volatility'), + PaletteEntry(275, 'IndRoofingFilter', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Roofing Filter'), + PaletteEntry(276, 'IndSMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'SMA'), + PaletteEntry(277, 'IndSMI', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'SMI'), + PaletteEntry(278, 'IndSMMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'SMMA'), + PaletteEntry(279, 'IndSSLChannel', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 's_s_l_channel'), + PaletteEntry(280, 'IndSchaffTrendCycle', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Schaff Trend Cycle'), + PaletteEntry(281, 'IndSenkouSpanA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Ichimoku'), + PaletteEntry(282, 'IndSenkouSpanB', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Ichimoku'), + PaletteEntry(283, 'IndShannonEntropy', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'shannon_entropy'), + PaletteEntry(284, 'IndSineWMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'WMA'), + PaletteEntry(285, 'IndSineWave', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'HT Sine'), + PaletteEntry(286, 'IndSkewness', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Skewness'), + PaletteEntry(287, 'IndSmoothedROC', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'ROC'), + PaletteEntry(288, 'IndSpearmanRank', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'spearman_rank'), + PaletteEntry(289, 'IndSpecialK', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'special_k'), + PaletteEntry(290, 'IndStandardError', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Standard Error'), + PaletteEntry(291, 'IndStandardPivotPoints', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Pivot Points Standard'), + PaletteEntry(292, 'IndStdDev', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Standard Deviation'), + PaletteEntry(293, 'IndStochRSI', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Stochastic RSI'), + PaletteEntry(294, 'IndStochasticFast', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Stochastic Fast'), + PaletteEntry(295, 'IndStochasticFull', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Stochastic Full'), + PaletteEntry(296, 'IndStochasticPop', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'stochastic_pop'), + PaletteEntry(297, 'IndStochasticSlow', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Stochastic Slow'), + PaletteEntry(298, 'IndSuperSmoother', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Super Smoother'), + PaletteEntry(299, 'IndSupertrend', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Supertrend'), + PaletteEntry(300, 'IndSwenlinTradingOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'swenlin_trading_oscillator'), + PaletteEntry(301, 'IndSwingIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Swing Index'), + PaletteEntry(302, 'IndT3', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'T3'), + PaletteEntry(303, 'IndTDSequential', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 't_d_sequential'), + PaletteEntry(304, 'IndTEMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'TEMA'), + PaletteEntry(305, 'IndTRIMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'TRIMA'), + PaletteEntry(306, 'IndTRIX', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'TRIX'), + PaletteEntry(307, 'IndTSF', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'TSF'), + PaletteEntry(308, 'IndTSI', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'TSI'), + PaletteEntry(309, 'IndTSMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 't_s_m_a'), + PaletteEntry(310, 'IndTTMSqueeze', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Squeeze Momentum'), + PaletteEntry(311, 'IndTenkanSen', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Ichimoku'), + PaletteEntry(312, 'IndTrendFlex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'trend_flex'), + PaletteEntry(313, 'IndTrendIntensityIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Trend Intensity Index'), + PaletteEntry(314, 'IndTrueRange', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'True Range'), + PaletteEntry(315, 'IndTwiggsMoneyFlow', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Twiggs Money Flow'), + PaletteEntry(316, 'IndTypicalPrice', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Typical Price'), + PaletteEntry(317, 'IndUTBot', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'u_t_bot'), + PaletteEntry(318, 'IndUlcerIndex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Ulcer Index'), + PaletteEntry(319, 'IndUltimateOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Ultimate Oscillator'), + PaletteEntry(320, 'IndUpDownRatio', 'Ind', 'Stock Market', 9, 150, 36, 'Indicator', 'up_down_ratio'), + PaletteEntry(321, 'IndUpDownVolumeRatio', 'Ind', 'Stock Market', 9, 150, 36, 'Indicator', 'up_down_volume_ratio'), + PaletteEntry(322, 'IndVHF', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'VHF'), + PaletteEntry(323, 'IndVIDYA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'VIDYA'), + PaletteEntry(324, 'IndVWAP', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'VWAP'), + PaletteEntry(325, 'IndVWAPBands', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'VWAP Bands'), + PaletteEntry(326, 'IndVWEMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'v_w_e_m_a'), + PaletteEntry(327, 'IndVWMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'VWMA'), + PaletteEntry(328, 'IndVariance', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Variance'), + PaletteEntry(329, 'IndVolatilityRatio', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'volatility_ratio'), + PaletteEntry(330, 'IndVolatilityStop', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'volatility_stop'), + PaletteEntry(331, 'IndVolumeAverage', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Volume MA'), + PaletteEntry(332, 'IndVolumeDelta', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'volume_delta'), + PaletteEntry(333, 'IndVolumeOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Volume Oscillator'), + PaletteEntry(334, 'IndVolumePriceTrend', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Price Volume Trend'), + PaletteEntry(335, 'IndVolumeRateOfChange', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Volume ROC'), + PaletteEntry(336, 'IndVolumeWeightedMovingAverage', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'VWMA'), + PaletteEntry(337, 'IndVolumeZoneOscillator', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'volume_zone_oscillator'), + PaletteEntry(338, 'IndVortex', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Vortex Indicator'), + PaletteEntry(339, 'IndWMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'WMA'), + PaletteEntry(340, 'IndWaveTrend', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'WaveTrend'), + PaletteEntry(341, 'IndWeightedClose', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Weighted Close'), + PaletteEntry(342, 'IndWilderVolatilitySystem', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'wilder_volatility_system'), + PaletteEntry(343, 'IndWildersMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'SMMA'), + PaletteEntry(344, 'IndWilliamsAccumulationDistribution', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Williams A/D'), + PaletteEntry(345, 'IndWilliamsR', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Williams %R'), + PaletteEntry(346, 'IndWoodiePivotPoints', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Pivot Points Woodie'), + PaletteEntry(347, 'IndYangZhangVolatility', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Yang-Zhang Volatility'), + PaletteEntry(348, 'IndZLEMA', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'ZLEMA'), + PaletteEntry(349, 'IndZScore', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'Z-Score'), + PaletteEntry(350, 'IndZeroLagMACD', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'MACD'), + PaletteEntry(351, 'IndZigZag', 'Ind', 'Stock Market', 9, 200, 90, 'Indicator', 'ZigZag'), + PaletteEntry(352, 'InstAnalogGauge', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'AnalogGauge'), + PaletteEntry(353, 'InstBarMeter', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'BarMeter'), + PaletteEntry(354, 'InstBeacon', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'Beacon'), + PaletteEntry(355, 'InstBezel', 'Inst', 'Instrumentation', 10, 200, 90, 'Container', 'Bezel'), + PaletteEntry(356, 'InstCircuitBreaker', 'Inst', 'Instrumentation', 10, 200, 90, 'Toggle', 'CircuitBreaker'), + PaletteEntry(357, 'InstControlPanel', 'Inst', 'Instrumentation', 10, 200, 90, 'Container', 'ControlPanel'), + PaletteEntry(358, 'InstDigitalReadout', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'DigitalReadout'), + PaletteEntry(359, 'InstEmergencyStop', 'Inst', 'Instrumentation', 10, 200, 90, 'Button', 'EmergencyStop'), + PaletteEntry(360, 'InstFlowMeter', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'FlowMeter'), + PaletteEntry(361, 'InstHorizontalTankLevel', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'HorizontalTankLevel'), + PaletteEntry(362, 'InstKeySwitch', 'Inst', 'Instrumentation', 10, 150, 36, 'Toggle', 'KeySwitch'), + PaletteEntry(363, 'InstLampTestButton', 'Inst', 'Instrumentation', 10, 150, 36, 'Button', 'LampTestButton'), + PaletteEntry(364, 'InstLedBlue', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'LedBlue'), + PaletteEntry(365, 'InstLedDigits1', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'LedDigits1'), + PaletteEntry(366, 'InstLedDigits2', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'LedDigits2'), + PaletteEntry(367, 'InstLedDigits3', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'LedDigits3'), + PaletteEntry(368, 'InstLedDigits4', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'LedDigits4'), + PaletteEntry(369, 'InstLedDigits5', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'LedDigits5'), + PaletteEntry(370, 'InstLedDigits6', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'LedDigits6'), + PaletteEntry(371, 'InstLedGreen', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'LedGreen'), + PaletteEntry(372, 'InstLedRed', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'LedRed'), + PaletteEntry(373, 'InstLevelColumnGauge', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'LevelColumnGauge'), + PaletteEntry(374, 'InstLevelTransmitter', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'LevelTransmitter'), + PaletteEntry(375, 'InstManometer', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'Manometer'), + PaletteEntry(376, 'InstNameplate', 'Inst', 'Instrumentation', 10, 200, 90, 'Label', 'Nameplate'), + PaletteEntry(377, 'InstNeedleEdgewise', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'NeedleEdgewise'), + PaletteEntry(378, 'InstNeedleKnifeEdge', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'NeedleKnifeEdge'), + PaletteEntry(379, 'InstNeedleTapered', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'NeedleTapered'), + PaletteEntry(380, 'InstNeedleVu', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'NeedleVu'), + PaletteEntry(381, 'InstOpenChannelLevel', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'OpenChannelLevel'), + PaletteEntry(382, 'InstPanelLampAmber', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'PanelLampAmber'), + PaletteEntry(383, 'InstPanelLampBlue', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'PanelLampBlue'), + PaletteEntry(384, 'InstPanelLampGreen', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'PanelLampGreen'), + PaletteEntry(385, 'InstPanelLampRed', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'PanelLampRed'), + PaletteEntry(386, 'InstPanelLampWhite', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'PanelLampWhite'), + PaletteEntry(387, 'InstPanelPlate', 'Inst', 'Instrumentation', 10, 200, 90, 'Container', 'PanelPlate'), + PaletteEntry(388, 'InstPressureGauge', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'PressureGauge'), + PaletteEntry(389, 'InstPushButton', 'Inst', 'Instrumentation', 10, 150, 36, 'Button', 'PushButton'), + PaletteEntry(390, 'InstPushButtonLatching', 'Inst', 'Instrumentation', 10, 150, 36, 'Toggle', 'PushButtonLatching'), + PaletteEntry(391, 'InstRgbStatusLed', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'RgbStatusLed'), + PaletteEntry(392, 'InstRockerSwitch', 'Inst', 'Instrumentation', 10, 150, 36, 'Toggle', 'RockerSwitch'), + PaletteEntry(393, 'InstRockerSwitchDouble', 'Inst', 'Instrumentation', 10, 150, 36, 'Toggle', 'RockerSwitchDouble'), + PaletteEntry(394, 'InstRockerSwitchIlluminated', 'Inst', 'Instrumentation', 10, 150, 36, 'Toggle', 'RockerSwitchIlluminated'), + PaletteEntry(395, 'InstRotarySelector', 'Inst', 'Instrumentation', 10, 200, 90, 'Range', 'Rotary'), + PaletteEntry(396, 'InstSeg14Display1', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'Seg14Display1'), + PaletteEntry(397, 'InstSeg14Display2', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'Seg14Display2'), + PaletteEntry(398, 'InstSeg14Display3', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'Seg14Display3'), + PaletteEntry(399, 'InstSeg14Display4', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'Seg14Display4'), + PaletteEntry(400, 'InstSeg14Display5', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'Seg14Display5'), + PaletteEntry(401, 'InstSeg14Display6', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'Seg14Display6'), + PaletteEntry(402, 'InstSeg16Display1', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'Seg16Display1'), + PaletteEntry(403, 'InstSeg16Display2', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'Seg16Display2'), + PaletteEntry(404, 'InstSeg16Display3', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'Seg16Display3'), + PaletteEntry(405, 'InstSeg16Display4', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'Seg16Display4'), + PaletteEntry(406, 'InstSeg16Display5', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'Seg16Display5'), + PaletteEntry(407, 'InstSeg16Display6', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'Seg16Display6'), + PaletteEntry(408, 'InstSightGlassLevel', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'SightGlassLevel'), + PaletteEntry(409, 'InstSlideSwitch', 'Inst', 'Instrumentation', 10, 150, 36, 'Toggle', 'SlideSwitch'), + PaletteEntry(410, 'InstSphericalTankLevel', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'SphericalTankLevel'), + PaletteEntry(411, 'InstStackLight', 'Inst', 'Instrumentation', 10, 260, 180, 'Instrument', 'StackLight'), + PaletteEntry(412, 'InstTankLevelAlarms', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'TankLevelAlarms'), + PaletteEntry(413, 'InstTemperatureGauge', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'TemperatureGauge'), + PaletteEntry(414, 'InstToggleSwitch', 'Inst', 'Instrumentation', 10, 150, 36, 'Toggle', 'ToggleSwitch'), + PaletteEntry(415, 'InstToggleSwitchIlluminated', 'Inst', 'Instrumentation', 10, 150, 36, 'Toggle', 'ToggleSwitchIlluminated'), + PaletteEntry(416, 'InstVerticalTankLevel', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'VerticalTankLevel'), + PaletteEntry(417, 'InstVuMeter', 'Inst', 'Instrumentation', 10, 200, 90, 'Instrument', 'VuMeter'), + PaletteEntry(418, 'StockAccumulationDistribution', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'AccumulationDistribution'), + PaletteEntry(419, 'StockAreaChart', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'AreaChart'), + PaletteEntry(420, 'StockArrow', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'Arrow'), + PaletteEntry(421, 'StockBaselineChart', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'BaselineChart'), + PaletteEntry(422, 'StockBrush', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'Brush'), + PaletteEntry(423, 'StockCandlestickChart', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'CandlestickChart'), + PaletteEntry(424, 'StockCorrelationView', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'CorrelationView'), + PaletteEntry(425, 'StockEllipse', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'Ellipse'), + PaletteEntry(426, 'StockFibExtension', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'FibExtension'), + PaletteEntry(427, 'StockFibRetracement', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'FibRetracement'), + PaletteEntry(428, 'StockHeikinAshi', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'HeikinAshi'), + PaletteEntry(429, 'StockHollowCandles', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'HollowCandles'), + PaletteEntry(430, 'StockHorizontalLine', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'HorizontalLine'), + PaletteEntry(431, 'StockIndexedComparison', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'IndexedComparison'), + PaletteEntry(432, 'StockLineChart', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'LineChart'), + PaletteEntry(433, 'StockMeasureTool', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'MeasureTool'), + PaletteEntry(434, 'StockMoneyFlowChart', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'MoneyFlowChart'), + PaletteEntry(435, 'StockMultiSymbolChart', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'MultiSymbolChart'), + PaletteEntry(436, 'StockOBVChart', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'OBVChart'), + PaletteEntry(437, 'StockOHLCBarChart', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'OHLCBarChart'), + PaletteEntry(438, 'StockOverlayChart', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'OverlayChart'), + PaletteEntry(439, 'StockParallelChannel', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'ParallelChannel'), + PaletteEntry(440, 'StockPitchfork', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'Pitchfork'), + PaletteEntry(441, 'StockPriceLabel', 'Stock', 'Stock Market', 9, 180, 30, 'Label', 'Price'), + PaletteEntry(442, 'StockRatioChart', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'RatioChart'), + PaletteEntry(443, 'StockRectangle', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'Rectangle'), + PaletteEntry(444, 'StockRelativePerformance', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'RelativePerformance'), + PaletteEntry(445, 'StockRenko', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'Renko'), + PaletteEntry(446, 'StockSectorComparison', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'SectorComparison'), + PaletteEntry(447, 'StockSpreadChart', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'SpreadChart'), + PaletteEntry(448, 'StockTextAnnotation', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'TextAnnotation'), + PaletteEntry(449, 'StockTrendline', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'Trendline'), + PaletteEntry(450, 'StockVWAP', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'VWAP'), + PaletteEntry(451, 'StockVerticalLine', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'VerticalLine'), + PaletteEntry(452, 'StockVolumeBars', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'VolumeBars'), + PaletteEntry(453, 'StockVolumeCandles', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'VolumeCandles'), + PaletteEntry(454, 'StockVolumeProfile', 'Stock', 'Stock Market', 9, 200, 90, 'Chart', 'VolumeProfile'), + PaletteEntry(455, 'TActionList', 'T', 'Menus & Toolbars', 7, 200, 90, 'Display', 'ActionList'), + PaletteEntry(456, 'TApplicationProperties', 'T', 'Misc / X', 8, 200, 90, 'Display', 'ApplicationProperties'), + PaletteEntry(457, 'TArrow', 'T', 'Display', 3, 200, 90, 'Display', 'Arrow'), + PaletteEntry(458, 'TBevel', 'T', 'Display', 3, 200, 90, 'Display', 'Bevel'), + PaletteEntry(459, 'TBitBtn', 'T', 'Buttons', 2, 200, 90, 'Button', 'BitBtn'), + PaletteEntry(460, 'TButton', 'T', 'Buttons', 2, 150, 36, 'Button', 'Button'), + PaletteEntry(461, 'TButtonPanel', 'T', 'Buttons', 2, 150, 36, 'Container', 'ButtonPanel'), + PaletteEntry(462, 'TCalcEdit', 'T', 'Text & Entry', 4, 180, 30, 'Entry', 'CalcEdit'), + PaletteEntry(463, 'TCalculatorDialog', 'T', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'CalculatorDialog'), + PaletteEntry(464, 'TCalendar', 'T', 'Display', 3, 200, 90, 'Container', 'Calendar'), + PaletteEntry(465, 'TCalendarDialog', 'T', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'CalendarDialog'), + PaletteEntry(466, 'TCheckBox', 'T', 'Buttons', 2, 150, 36, 'Toggle', 'CheckBox'), + PaletteEntry(467, 'TCheckComboBox', 'T', 'Buttons', 2, 150, 36, 'ListSel', 'CheckComboBox'), + PaletteEntry(468, 'TCheckGroup', 'T', 'Views & Lists', 6, 150, 36, 'ListSel', 'CheckGroup'), + PaletteEntry(469, 'TCheckListBox', 'T', 'Views & Lists', 6, 150, 36, 'ListSel', 'CheckListBox'), + PaletteEntry(470, 'TColorBox', 'T', 'Choosers', 5, 200, 90, 'ListSel', 'ColorBox'), + PaletteEntry(471, 'TColorButton', 'T', 'Choosers', 5, 150, 36, 'Button', 'ColorButton'), + PaletteEntry(472, 'TColorDialog', 'T', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'ColorDialog'), + PaletteEntry(473, 'TColorListBox', 'T', 'Choosers', 5, 200, 90, 'ListSel', 'ColorListBox'), + PaletteEntry(474, 'TComboBox', 'T', 'Text & Entry', 4, 180, 30, 'ListSel', 'ComboBox'), + PaletteEntry(475, 'TComboBoxEx', 'T', 'Text & Entry', 4, 180, 30, 'ListSel', 'ComboBoxEx'), + PaletteEntry(476, 'TControlBar', 'T', 'Containers & Layout', 1, 200, 90, 'Container', 'ControlBar'), + PaletteEntry(477, 'TCoolBar', 'T', 'Containers & Layout', 1, 200, 90, 'Container', 'CoolBar'), + PaletteEntry(478, 'TDateEdit', 'T', 'Text & Entry', 4, 180, 30, 'Entry', 'DateEdit'), + PaletteEntry(479, 'TDateTimePicker', 'T', 'Display', 3, 200, 90, 'Container', 'DateTimePicker'), + PaletteEntry(480, 'TDirectoryEdit', 'T', 'Text & Entry', 4, 180, 30, 'Entry', 'DirectoryEdit'), + PaletteEntry(481, 'TDrawGrid', 'T', 'Views & Lists', 6, 260, 180, 'Container', 'DrawGrid'), + PaletteEntry(482, 'TEdit', 'T', 'Text & Entry', 4, 180, 30, 'Entry', 'Edit'), + PaletteEntry(483, 'TEditButton', 'T', 'Text & Entry', 4, 150, 36, 'Button', 'EditButton'), + PaletteEntry(484, 'TFileListBox', 'T', 'Choosers', 5, 200, 90, 'ListSel', 'FileListBox'), + PaletteEntry(485, 'TFileNameEdit', 'T', 'Text & Entry', 4, 180, 30, 'Entry', 'FileNameEdit'), + PaletteEntry(486, 'TFilterComboBox', 'T', 'Text & Entry', 4, 180, 30, 'ListSel', 'FilterComboBox'), + PaletteEntry(487, 'TFindDialog', 'T', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'FindDialog'), + PaletteEntry(488, 'TFloatSpinEdit', 'T', 'Text & Entry', 4, 150, 36, 'Range', 'FloatSpinEdit'), + PaletteEntry(489, 'TFlowPanel', 'T', 'Containers & Layout', 1, 200, 90, 'Container', 'FlowPanel'), + PaletteEntry(490, 'TFontDialog', 'T', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'FontDialog'), + PaletteEntry(491, 'TForm', 'T', 'Windows & Dialogs', 0, 300, 220, 'Container', 'Form'), + PaletteEntry(492, 'TFrame', 'T', 'Containers & Layout', 1, 200, 90, 'Container', 'Frame'), + PaletteEntry(493, 'TGroupBox', 'T', 'Containers & Layout', 1, 200, 90, 'Container', 'GroupBox'), + PaletteEntry(494, 'THeaderControl', 'T', 'Views & Lists', 6, 200, 90, 'ListSel', 'HeaderControl'), + PaletteEntry(495, 'TImage', 'T', 'Display', 3, 200, 90, 'Display', 'Image'), + PaletteEntry(496, 'TImageList', 'T', 'Display', 3, 200, 90, 'Display', 'ImageList'), + PaletteEntry(497, 'TLabel', 'T', 'Display', 3, 180, 30, 'Label', 'Label'), + PaletteEntry(498, 'TLabeledEdit', 'T', 'Text & Entry', 4, 180, 30, 'Entry', 'LabeledEdit'), + PaletteEntry(499, 'TListBox', 'T', 'Views & Lists', 6, 200, 90, 'ListSel', 'ListBox'), + PaletteEntry(500, 'TListView', 'T', 'Views & Lists', 6, 260, 180, 'ListSel', 'ListView'), + PaletteEntry(501, 'TMainMenu', 'T', 'Menus & Toolbars', 7, 200, 90, 'ListSel', 'MainMenu'), + PaletteEntry(502, 'TMaskEdit', 'T', 'Text & Entry', 4, 180, 30, 'Entry', 'MaskEdit'), + PaletteEntry(503, 'TMemo', 'T', 'Text & Entry', 4, 260, 180, 'Entry', 'Memo'), + PaletteEntry(504, 'TNotebook', 'T', 'Containers & Layout', 1, 260, 180, 'Container', 'Notebook'), + PaletteEntry(505, 'TOpenDialog', 'T', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'OpenDialog'), + PaletteEntry(506, 'TOpenPictureDialog', 'T', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'OpenPictureDialog'), + PaletteEntry(507, 'TPageControl', 'T', 'Containers & Layout', 1, 260, 180, 'Container', 'PageControl'), + PaletteEntry(508, 'TPageSetupDialog', 'T', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'PageSetupDialog'), + PaletteEntry(509, 'TPaintBox', 'T', 'Display', 3, 200, 90, 'Display', 'PaintBox'), + PaletteEntry(510, 'TPairSplitter', 'T', 'Containers & Layout', 1, 200, 90, 'Container', 'PairSplitter'), + PaletteEntry(511, 'TPanel', 'T', 'Containers & Layout', 1, 200, 90, 'Container', 'Panel'), + PaletteEntry(512, 'TPopupMenu', 'T', 'Menus & Toolbars', 7, 200, 90, 'ListSel', 'PopupMenu'), + PaletteEntry(513, 'TPopupNotifier', 'T', 'Menus & Toolbars', 7, 200, 90, 'Display', 'PopupNotifier'), + PaletteEntry(514, 'TPrintDialog', 'T', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'PrintDialog'), + PaletteEntry(515, 'TPrinterSetupDialog', 'T', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'PrinterSetupDialog'), + PaletteEntry(516, 'TProgressBar', 'T', 'Display', 3, 180, 30, 'Range', 'ProgressBar'), + PaletteEntry(517, 'TRadioButton', 'T', 'Buttons', 2, 150, 36, 'Toggle', 'RadioButton'), + PaletteEntry(518, 'TRadioGroup', 'T', 'Views & Lists', 6, 150, 36, 'ListSel', 'RadioGroup'), + PaletteEntry(519, 'TReplaceDialog', 'T', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'ReplaceDialog'), + PaletteEntry(520, 'TSaveDialog', 'T', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'SaveDialog'), + PaletteEntry(521, 'TSavePictureDialog', 'T', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'SavePictureDialog'), + PaletteEntry(522, 'TScrollBar', 'T', 'Containers & Layout', 1, 180, 30, 'Range', 'ScrollBar'), + PaletteEntry(523, 'TScrollBox', 'T', 'Containers & Layout', 1, 200, 90, 'Container', 'ScrollBox'), + PaletteEntry(524, 'TSelectDirectoryDialog', 'T', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'SelectDirectoryDialog'), + PaletteEntry(525, 'TShape', 'T', 'Display', 3, 200, 90, 'Display', 'Shape'), + PaletteEntry(526, 'TShellListView', 'T', 'Views & Lists', 6, 260, 180, 'ListSel', 'ShellListView'), + PaletteEntry(527, 'TShellTreeView', 'T', 'Views & Lists', 6, 260, 180, 'ListSel', 'ShellTreeView'), + PaletteEntry(528, 'TSpeedButton', 'T', 'Buttons', 2, 150, 36, 'Button', 'SpeedButton'), + PaletteEntry(529, 'TSpinEdit', 'T', 'Text & Entry', 4, 150, 36, 'Range', 'SpinEdit'), + PaletteEntry(530, 'TSplitter', 'T', 'Containers & Layout', 1, 200, 90, 'Container', 'Splitter'), + PaletteEntry(531, 'TStaticText', 'T', 'Display', 3, 200, 90, 'Label', 'StaticText'), + PaletteEntry(532, 'TStatusBar', 'T', 'Display', 3, 180, 30, 'Container', 'StatusBar'), + PaletteEntry(533, 'TStringGrid', 'T', 'Views & Lists', 6, 260, 180, 'Container', 'StringGrid'), + PaletteEntry(534, 'TTabControl', 'T', 'Containers & Layout', 1, 260, 180, 'ListSel', 'TabControl'), + PaletteEntry(535, 'TTaskDialog', 'T', 'Windows & Dialogs', 0, 300, 220, 'Dialog', 'TaskDialog'), + PaletteEntry(536, 'TTimeEdit', 'T', 'Display', 3, 180, 30, 'Entry', 'TimeEdit'), + PaletteEntry(537, 'TTimer', 'T', 'Display', 3, 200, 90, 'Display', 'Timer'), + PaletteEntry(538, 'TToggleBox', 'T', 'Buttons', 2, 150, 36, 'Toggle', 'ToggleBox'), + PaletteEntry(539, 'TToolBar', 'T', 'Menus & Toolbars', 7, 200, 90, 'Container', 'ToolBar'), + PaletteEntry(540, 'TTrackBar', 'T', 'Display', 3, 200, 90, 'Range', 'TrackBar'), + PaletteEntry(541, 'TTrayIcon', 'T', 'Display', 3, 200, 90, 'Display', 'TrayIcon'), + PaletteEntry(542, 'TTreeView', 'T', 'Views & Lists', 6, 260, 180, 'ListSel', 'TreeView'), + PaletteEntry(543, 'TUpDown', 'T', 'Buttons', 2, 150, 36, 'Range', 'UpDown'), + PaletteEntry(544, 'TValueListEditor', 'T', 'Text & Entry', 4, 180, 30, 'ListSel', 'ValueListEditor'), + PaletteEntry(545, 'XGraph', 'X', 'Misc / X', 8, 320, 200, 'Graph', 'XGraph'), + PaletteEntry(546, 'XSpreadsheet', 'X', 'Misc / X', 8, 320, 200, 'Spreadsheet', 'XSpreadsheet'), +) + +BY_NAME = {e.name: e for e in PALETTE} +BY_INDEX = {e.index: e for e in PALETTE} + + +def find(name): + """Return the PaletteEntry for a registry name, or None.""" + return BY_NAME.get(name) + + +def by_index(index): + """Return the PaletteEntry for a registry index, or None.""" + return BY_INDEX.get(index) + + +def by_section(section): + """Return the PaletteEntries of one section, in palette order.""" + return [e for e in PALETTE if e.section == section] + + +def by_archetype(archetype): + """Return the PaletteEntries of one archetype, in registry order.""" + return [e for e in PALETTE if e.archetype == archetype] + + +# Legacy LightGUI type keys (C src/model.h kTypes, 36 entries). +# Recorded for reference only: these are NOT XFrame registry +# kinds, are NOT in PALETTE/BY_NAME, and cannot be placed -- +# the .fdj loader skips any widget whose type is not a known +# XFrame kind. Derived from /opt/lightgui_rust/data/palette.json +# ("lightgui" list, itself extracted from C src/model.h). +LEGACY_TYPES = ( + ('Button', 'pal_button', 100, 30), + ('Label', 'pal_label', 100, 24), + ('Entry', 'pal_entry', 160, 28), + ('Checkbutton', 'pal_checkbutton', 120, 26), + ('Radiobutton', 'pal_radiobutton', 120, 26), + ('Frame', 'pal_frame', 200, 120), + ('Combobox', 'pal_combobox', 160, 28), + ('Listbox', 'pal_listbox', 180, 110), + ('Menubutton', 'pal_menubutton', 110, 30), + ('Canvas', 'pal_canvas', 200, 140), + ('Scale', 'pal_scale', 160, 28), + ('Scrollbar', 'pal_scrollbar', 160, 18), + ('Text', 'pal_text', 220, 120), + ('Toplevel', 'pal_toplevel', 300, 200), + ('Spreadsheet', 'pal_spreadsheet', 320, 180), + ('StockChart', 'pal_stockchart', 320, 200), + ('Memo', 'pal_memo', 220, 120), + ('GroupBox', 'pal_groupbox', 200, 120), + ('Panel', 'pal_panel', 200, 120), + ('Image', 'pal_image', 160, 120), + ('Shape', 'pal_shape', 160, 120), + ('Notebook', 'pal_notebook', 320, 200), + ('ScrollBox', 'pal_scrollbox', 240, 160), + ('Splitter', 'pal_splitter', 280, 160), + ('StatusBar', 'pal_statusbar', 320, 24), + ('ToolBar', 'pal_toolbar', 320, 36), + ('MenuBar', 'pal_menubar', 320, 28), + ('SpinEdit', 'pal_spinedit', 120, 28), + ('TrackBar', 'pal_trackbar', 160, 28), + ('ProgressBar', 'pal_progressbar', 200, 24), + ('DateTimePicker', 'pal_datetimepicker', 240, 200), + ('ColorBox', 'pal_colorbox', 120, 28), + ('ListView', 'pal_listview', 240, 140), + ('TreeView', 'pal_treeview', 240, 140), + ('StringGrid', 'pal_stringgrid', 280, 160), + ('Plot', 'pal_plot', 280, 180), +) diff --git a/tests/test_canvas.py b/tests/test_canvas.py new file mode 100644 index 0000000..7708654 --- /dev/null +++ b/tests/test_canvas.py @@ -0,0 +1,165 @@ +"""Tests for lightgui.xframe.canvas.CanvasState (no display needed).""" + +import unittest + +from lightgui.model import Project +from lightgui.xframe import core +from lightgui.xframe.canvas import CanvasState + + +class CanvasPlacementTests(unittest.TestCase): + def setUp(self): + self.state = CanvasState(Project()) + + def test_empty_click_without_pending_kind_selects_nothing(self): + self.assertTrue(self.state.button_press(100, 100, now_ms=1000.0)) + self.assertEqual(self.state.project.widgets, []) + self.assertIsNone(self.state.selected) + + def test_pending_kind_places_centred_on_click(self): + self.state.set_pending_kind("GtkButton") + self.state.button_press(200, 150, now_ms=1000.0) + widgets = self.state.project.widgets + self.assertEqual(len(widgets), 1) + # GtkButton default 150x36, centred on (200, 150). + self.assertEqual((widgets[0].x, widgets[0].y), (125, 132)) + self.assertEqual((widgets[0].width, widgets[0].height), (150, 36)) + self.assertIs(self.state.selected, widgets[0]) + + def test_pending_kind_persists_across_placements(self): + self.state.set_pending_kind("GtkButton") + self.state.button_press(200, 150, now_ms=1000.0) + self.state.button_press(400, 300, now_ms=2000.0) + self.assertEqual(len(self.state.project.widgets), 2) + self.assertEqual(self.state.pending_kind, "GtkButton") + + def test_unknown_pending_kind_is_ignored(self): + self.state.set_pending_kind("GtkNoSuchWidget") + self.assertIsNone(self.state.pending_kind) + + def test_place_clamps_to_canvas_origin(self): + self.state.set_pending_kind("GtkButton") + self.state.button_press(10, 10, now_ms=1000.0) + widget = self.state.project.widgets[0] + self.assertEqual((widget.x, widget.y), (0, 0)) + + +class CanvasSelectionTests(unittest.TestCase): + def setUp(self): + self.state = CanvasState(Project()) + self.widget = self.state.place("GtkButton", 100, 80, 150, 36) + + def test_single_click_selects_without_handles(self): + self.state.button_press(150, 100, now_ms=1000.0) + self.assertIs(self.state.selected, self.widget) + self.assertFalse(self.state.handles_on) + + def test_double_click_within_450ms_shows_handles(self): + self.state.button_press(150, 100, now_ms=1000.0) + self.state.button_release(150, 100) + self.state.button_press(152, 101, now_ms=1200.0) + self.assertIs(self.state.selected, self.widget) + self.assertTrue(self.state.handles_on) + + def test_double_click_jiggle_does_not_break_it(self): + # First press drags the widget a few px (under the threshold it + # does not move, but the press point jiggles); second press on + # the shifted widget still counts as a double-click. + self.state.button_press(150, 100, now_ms=1000.0) + self.state.motion(154, 103) + self.state.button_release(154, 103) + self.state.button_press(154, 103, now_ms=1300.0) + self.assertTrue(self.state.handles_on) + + def test_second_press_after_450ms_is_not_a_double_click(self): + self.state.button_press(150, 100, now_ms=1000.0) + self.state.button_release(150, 100) + self.state.button_press(150, 100, now_ms=1500.0) + self.assertFalse(self.state.handles_on) + + def test_second_press_on_another_widget_is_not_a_double_click(self): + other = self.state.place("GtkLabel", 300, 80, 180, 30) + self.state.button_press(150, 100, now_ms=1000.0) + self.state.button_release(150, 100) + self.state.button_press(350, 95, now_ms=1200.0) + self.assertIs(self.state.selected, other) + self.assertFalse(self.state.handles_on) + + def test_empty_click_clears_selection_and_handles(self): + self.state.button_press(150, 100, now_ms=1000.0) + self.state.button_release(150, 100) + self.state.button_press(152, 101, now_ms=1200.0) + self.assertTrue(self.state.handles_on) + self.state.button_press(500, 400, now_ms=2000.0) + self.assertIsNone(self.state.selected) + self.assertFalse(self.state.handles_on) + + def test_escape_clears_selection(self): + self.state.button_press(150, 100, now_ms=1000.0) + self.assertTrue(self.state.key("Escape")) + self.assertIsNone(self.state.selected) + self.assertFalse(self.state.key("Escape")) + + def test_delete_removes_selected(self): + self.state.button_press(150, 100, now_ms=1000.0) + self.assertTrue(self.state.key("Delete")) + self.assertEqual(self.state.project.widgets, []) + self.assertFalse(self.state.key("Delete")) + + def test_other_keys_not_handled(self): + self.assertFalse(self.state.key("a")) + self.assertFalse(self.state.key("Return")) + + def test_non_button_1_ignored(self): + # place() in setUp selects the widget; clear it first. + self.state.clear_selection() + self.assertFalse(self.state.button_press(150, 100, button=3, + now_ms=1000.0)) + self.assertIsNone(self.state.selected) + + +class CanvasDragTests(unittest.TestCase): + def setUp(self): + self.state = CanvasState(Project()) + self.widget = self.state.place("GtkButton", 100, 80, 150, 36) + + def test_sub_threshold_motion_does_not_move(self): + self.state.button_press(150, 100, now_ms=1000.0) + self.state.motion(155, 104) + self.assertEqual((self.widget.x, self.widget.y), (100, 80)) + + def test_drag_moves_widget_by_grab_offset(self): + self.state.button_press(150, 100, now_ms=1000.0) + self.state.motion(200, 150) + # Grab offset was (50, 20); widget follows the pointer. + self.assertEqual((self.widget.x, self.widget.y), (150, 130)) + self.state.button_release(200, 150) + self.assertEqual((self.widget.x, self.widget.y), (150, 130)) + + def test_drag_clamps_at_origin(self): + self.state.button_press(110, 90, now_ms=1000.0) + self.state.motion(0, 0) + self.assertEqual((self.widget.x, self.widget.y), (0, 0)) + + def test_handle_drag_resizes(self): + self.state.button_press(150, 100, now_ms=1000.0) + self.state.button_release(150, 100) + self.state.button_press(152, 101, now_ms=1200.0) + self.assertTrue(self.state.handles_on) + # SE handle centre is (250, 116); grab it and drag +20/+10. + self.state.button_press(250, 116, now_ms=1300.0) + self.assertTrue(self.state.handle_drag) + self.state.motion(270, 126) + self.assertEqual((self.widget.width, self.widget.height), + (170, 46)) + self.state.button_release(270, 126) + self.assertFalse(self.state.handle_drag) + + def test_viewport_tracks_resize(self): + self.state.resize_viewport(1280, 720) + self.assertEqual((self.state.viewport_width, + self.state.viewport_height), (1280, 720)) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_core.py b/tests/test_core.py new file mode 100644 index 0000000..1f9adb6 --- /dev/null +++ b/tests/test_core.py @@ -0,0 +1,125 @@ +"""Tests for lightgui.xframe.core: registry, hit-testing, handles.""" + +import unittest + +from lightgui.xframe import core +from lightgui.xframe import palette + + +class RegistryTests(unittest.TestCase): + def test_all_palette_kinds_resolve(self): + for entry in palette.PALETTE: + cls = core.lookup(entry.name) + self.assertIsNotNone(cls, entry.name) + self.assertEqual(cls.ARCHETYPE, entry.archetype) + + def test_unknown_kind_is_none(self): + self.assertIsNone(core.lookup("GtkNoSuchWidget")) + self.assertIsNone(core.create("GtkNoSuchWidget", "X_001")) + self.assertFalse(core.is_known_kind("GtkNoSuchWidget")) + + def test_create_uses_registry_default_size(self): + widget = core.create("GtkButton", "GtkButton_001", 10, 20) + self.assertEqual((widget.width, widget.height), (150, 36)) + self.assertEqual(widget.archetype, "Button") + widget = core.create("GtkAboutDialog", "GtkAboutDialog_001") + self.assertEqual((widget.width, widget.height), (300, 220)) + + def test_create_explicit_size(self): + widget = core.create("GtkButton", "B", 0, 0, 200, 50) + self.assertEqual((widget.width, widget.height), (200, 50)) + + def test_archetype_classes_cover_all_archetypes(self): + archetypes = {e.archetype for e in palette.PALETTE} + self.assertEqual(archetypes, set(core.ARCHETYPE_CLASSES)) + + +class WidgetStateTests(unittest.TestCase): + def setUp(self): + self.widget = core.create("GtkButton", "GtkButton_001", 100, 80, + 150, 36) + + def test_setters_are_state_only(self): + self.widget.set_bounds(5, 6, 200, 40) + self.assertEqual((self.widget.x, self.widget.y, + self.widget.width, self.widget.height), + (5, 6, 200, 40)) + self.widget.set_prop("text", "Hello") + self.assertEqual(self.widget.text, "Hello") + self.assertEqual(self.widget.get_prop("text"), "Hello") + + def test_set_bounds_clamps(self): + self.widget.set_bounds(-10, -5, 5, 3) + self.assertEqual((self.widget.x, self.widget.y), (0, 0)) + self.assertEqual((self.widget.width, self.widget.height), + (core.MIN_WIDTH, core.MIN_HEIGHT)) + + def test_text_defaults_to_instance_name(self): + widget = core.create("GtkButton", "GtkButton_001") + self.assertEqual(widget.text, "GtkButton_001") + + def test_contains(self): + self.assertTrue(self.widget.contains(100, 80)) + self.assertTrue(self.widget.contains(250, 116)) + self.assertFalse(self.widget.contains(99, 80)) + self.assertFalse(self.widget.contains(251, 80)) + self.assertFalse(self.widget.contains(100, 117)) + + +class HandleGeometryTests(unittest.TestCase): + def setUp(self): + self.widget = core.create("GtkButton", "GtkButton_001", 100, 80, + 150, 36) + self.widget.handles_on = True + + def test_handle_size_is_13(self): + self.assertEqual(core.HANDLE_SIZE, 13) + self.assertEqual(core.HANDLE_HIT_PAD, 8) + + def test_handle_centres(self): + # Corners on the widget corners, edges on the midpoints. + self.assertEqual(self.widget.handle_centre(0), (100, 80)) # NW + self.assertEqual(self.widget.handle_centre(2), (250, 80)) # NE + self.assertEqual(self.widget.handle_centre(4), (250, 116)) # SE + self.assertEqual(self.widget.handle_centre(6), (100, 116)) # SW + self.assertEqual(self.widget.handle_centre(1), (175, 80)) # N + self.assertEqual(self.widget.handle_centre(3), (250, 98)) # E + self.assertEqual(self.widget.handle_centre(5), (175, 116)) # S + self.assertEqual(self.widget.handle_centre(7), (100, 98)) # W + + def test_handle_rect_is_13x13_centred(self): + x, y, w, h = self.widget.handle_rect(0) + self.assertEqual((w, h), (13, 13)) + self.assertEqual((x, y), (100 - 6, 80 - 6)) + + def test_handle_at_with_pad(self): + # 8px pad: a point 8px outside the 13px square still grabs. + self.assertEqual(self.widget.handle_at(100 - 6 - 8, 80), 0) + self.assertEqual(self.widget.handle_at(100 - 6 - 9, 80), -1) + self.assertEqual(self.widget.handle_at(250, 98), 3) + self.assertEqual(self.widget.handle_at(175, 116), 5) + self.assertEqual(self.widget.handle_at(175, 100), -1) + + def test_handle_at_off_when_handles_off(self): + self.widget.handles_on = False + self.assertEqual(self.widget.handle_at(100, 80), -1) + + def test_apply_handle_drag_se(self): + self.widget.apply_handle_drag(4, 10, 5) + self.assertEqual((self.widget.width, self.widget.height), + (160, 41)) + + def test_apply_handle_drag_nw_moves_origin(self): + self.widget.apply_handle_drag(0, 10, 5) + self.assertEqual((self.widget.x, self.widget.y, + self.widget.width, self.widget.height), + (110, 85, 140, 31)) + + def test_apply_handle_drag_clamps_minimum(self): + self.widget.apply_handle_drag(4, -500, -500) + self.assertEqual((self.widget.width, self.widget.height), + (core.MIN_WIDTH, core.MIN_HEIGHT)) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_model.py b/tests/test_model.py new file mode 100644 index 0000000..27cedb0 --- /dev/null +++ b/tests/test_model.py @@ -0,0 +1,151 @@ +"""Tests for lightgui.model: project model and .fdj round-trip.""" + +import json +import os +import tempfile +import unittest + +from lightgui.model import Project + + +class ProjectModelTests(unittest.TestCase): + def test_add_assigns_unique_names(self): + project = Project() + first = project.add_widget("GtkButton", 10, 10) + second = project.add_widget("GtkButton", 20, 20) + label = project.add_widget("GtkLabel", 30, 30) + self.assertEqual(first.name, "GtkButton_001") + self.assertEqual(second.name, "GtkButton_002") + self.assertEqual(label.name, "GtkLabel_001") + self.assertEqual(len(project.widgets), 3) + + def test_add_unknown_kind_returns_none(self): + project = Project() + self.assertIsNone(project.add_widget("GtkNoSuchWidget", 0, 0)) + self.assertEqual(project.widgets, []) + + def test_add_selects_and_seeds_text(self): + project = Project() + widget = project.add_widget("GtkButton", 10, 10) + self.assertIs(project.selected, widget) + self.assertEqual(widget.get_prop("text"), "GtkButton_001") + + def test_remove_clears_selection(self): + project = Project() + widget = project.add_widget("GtkButton", 10, 10) + self.assertTrue(project.remove_widget(widget.id)) + self.assertEqual(project.widgets, []) + self.assertIsNone(project.selected) + self.assertFalse(project.remove_widget(widget.id)) + + def test_move_and_resize(self): + project = Project() + widget = project.add_widget("GtkButton", 10, 10) + self.assertTrue(project.move_widget(widget.id, 50, 60)) + self.assertEqual((widget.x, widget.y), (50, 60)) + self.assertTrue(project.resize_widget(widget.id, 200, 40)) + self.assertEqual((widget.width, widget.height), (200, 40)) + self.assertFalse(project.move_widget(999, 0, 0)) + + def test_hit_test_topmost(self): + project = Project() + bottom = project.add_widget("GtkButton", 10, 10, 100, 100) + top = project.add_widget("GtkLabel", 50, 50, 100, 100) + self.assertIs(project.hit_test(60, 60), top) + self.assertIs(project.hit_test(15, 15), bottom) + self.assertIsNone(project.hit_test(500, 500)) + + +class FdjTests(unittest.TestCase): + def test_round_trip(self): + project = Project() + project.title = "My App" + project.add_widget("GtkButton", 10, 20) + project.add_widget("GtkLabel", 200, 30, 180, 30) + project.widgets[1].set_prop("text", "Hello") + project.widgets[1].signals.append("clicked") + loaded = Project.load_text(project.save_text()) + self.assertEqual(loaded.title, "My App") + self.assertEqual(loaded.class_name, "MyWindow") + self.assertEqual((loaded.win_width, loaded.win_height), (800, 600)) + self.assertEqual(len(loaded.widgets), 2) + self.assertEqual(loaded.widgets[0].name, "GtkButton_001") + self.assertEqual(loaded.widgets[1].get_prop("text"), "Hello") + self.assertEqual(loaded.widgets[1].signals, ["clicked"]) + self.assertEqual(loaded.save_text(), project.save_text()) + + def test_empty_project_bytes(self): + text = Project().save_text() + self.assertEqual(text, '{\n "format": "lightgui",\n "version": 1,\n' + ' "window": {\n "title": "Main Window",\n' + ' "class_name": "MyWindow",\n "width": 800,\n' + ' "height": 600,\n "background": "",\n' + ' "menubar": "",\n "border_style": 0,\n' + ' "icon": "",\n "position": 0,\n' + ' "window_state": 0\n },\n "widgets": []\n}\n') + self.assertEqual(Project.load_text(text).save_text(), text) + + def test_load_is_valid_json_with_sorted_props(self): + project = Project() + widget = project.add_widget("GtkButton", 0, 0) + widget.set_prop("zeta", "1") + widget.set_prop("alpha", "2") + data = json.loads(project.save_text()) + self.assertEqual(list(data["widgets"][0]["props"]), ["alpha", "text", "zeta"]) + + def test_load_rejects_bad_format_and_version(self): + with self.assertRaises(ValueError): + Project.load_text('{"format": "other", "version": 1}') + with self.assertRaises(ValueError): + Project.load_text('{"format": "lightgui", "version": 2}') + with self.assertRaises(ValueError): + Project.load_text("not json") + + def test_load_clamps_and_skips(self): + text = ('{"format": "lightgui", "version": 1, "window": ' + '{"width": 5, "height": 99999, "border_style": 9}, ' + '"widgets": [{"name": "W1", "type": "GtkButton", ' + '"x": 0, "y": 0, "width": 3, "height": 2}, ' + '{"name": "W2", "type": "LegacyButton", ' + '"x": 0, "y": 0, "width": 100, "height": 30}, ' + '{"name": "", "type": "GtkButton"}]}') + loaded = Project.load_text(text) + self.assertEqual((loaded.win_width, loaded.win_height), (800, 600)) + self.assertEqual(loaded.border_style, 0) + self.assertEqual(len(loaded.widgets), 1) + self.assertEqual((loaded.widgets[0].width, + loaded.widgets[0].height), (10, 10)) + self.assertEqual(loaded.skipped, ["LegacyButton"]) + + def test_name_counter_survives_load(self): + project = Project() + project.add_widget("GtkButton", 0, 0) + loaded = Project.load_text(project.save_text()) + widget = loaded.add_widget("GtkButton", 0, 0) + self.assertEqual(widget.name, "GtkButton_002") + + def test_save_and_load_file(self): + project = Project() + project.add_widget("GtkButton", 10, 10) + with tempfile.TemporaryDirectory() as tmp: + path = os.path.join(tmp, "test.fdj") + project.save_file(path) + loaded = Project.load_file(path) + self.assertEqual(len(loaded.widgets), 1) + self.assertEqual(loaded.widgets[0].name, "GtkButton_001") + + def test_load_missing_file(self): + with self.assertRaises(ValueError): + Project.load_file("/nonexistent/dir/test.fdj") + + def test_string_escaping_round_trip(self): + project = Project() + widget = project.add_widget("GtkLabel", 0, 0) + widget.set_prop("text", 'quote " backslash \\ newline\n tab\t') + loaded = Project.load_text(project.save_text()) + self.assertEqual(loaded.widgets[0].get_prop("text"), + 'quote " backslash \\ newline\n tab\t') + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_palette.py b/tests/test_palette.py new file mode 100644 index 0000000..f714c0a --- /dev/null +++ b/tests/test_palette.py @@ -0,0 +1,78 @@ +"""Tests for lightgui.xframe.palette: 547 widgets, 11 sections, 36 legacy.""" + +import unittest + +from lightgui.xframe import palette + +EXPECTED_SECTIONS = { + "Windows & Dialogs": 28, + "Containers & Layout": 34, + "Buttons": 24, + "Display": 33, + "Text & Entry": 28, + "Choosers": 10, + "Views & Lists": 17, + "Menus & Toolbars": 16, + "Misc / X": 4, + "Stock Market": 287, + "Instrumentation": 66, +} + + +class PaletteTests(unittest.TestCase): + def test_547_entries(self): + self.assertEqual(len(palette.PALETTE), 547) + + def test_11_sections_in_c_palette_order(self): + self.assertEqual(list(palette.SECTIONS), + list(EXPECTED_SECTIONS)) + self.assertEqual(len(palette.SECTIONS), 11) + + def test_section_counts_match_c_palette_header(self): + for section, count in EXPECTED_SECTIONS.items(): + self.assertEqual(len(palette.by_section(section)), count, + section) + + def test_indices_are_0_to_546(self): + self.assertEqual(sorted(e.index for e in palette.PALETTE), + list(range(547))) + + def test_names_unique(self): + names = [e.name for e in palette.PALETTE] + self.assertEqual(len(set(names)), 547) + + def test_default_sizes_positive(self): + for entry in palette.PALETTE: + self.assertGreater(entry.default_w, 0, entry.name) + self.assertGreater(entry.default_h, 0, entry.name) + + def test_find_and_by_index(self): + entry = palette.find("GtkButton") + self.assertEqual(entry.index, 10) + self.assertEqual(entry.section, "Buttons") + self.assertEqual(entry.archetype, "Button") + self.assertEqual(palette.by_index(10), entry) + self.assertIsNone(palette.find("GtkNoSuchWidget")) + self.assertIsNone(palette.by_index(999)) + + def test_archetypes_are_known(self): + from lightgui.xframe import core + for entry in palette.PALETTE: + self.assertIn(entry.archetype, core.ARCHETYPE_CLASSES, + entry.name) + + def test_legacy_types_36_and_not_placeable(self): + self.assertEqual(len(palette.LEGACY_TYPES), 36) + self.assertEqual(palette.LEGACY_TYPES[0][0], "Button") + self.assertEqual(palette.LEGACY_TYPES[-1][0], "Plot") + for key, _pal_id, _w, _h in palette.LEGACY_TYPES: + self.assertIsNone(palette.find(key), + "legacy key must not be a registry kind") + + def test_total_entries_583(self): + self.assertEqual(len(palette.PALETTE) + len(palette.LEGACY_TYPES), + 583) + + +if __name__ == "__main__": + unittest.main()