diff --git a/README.md b/README.md index 9aa1f4d..d6f618b 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Every percentage is a count with a stated basis, so it can be checked (details i | Display series | **40 %** (2/5) | Basic (T) and Intelligent (P) confirmed; Discovery, Enhanced, Edge not sampled | | Picture formats | **100 %** (2/2) | raw RGB565 (Basic) and run-length + alpha (Intelligent), byte-identical to the Editor, every display direction | | Font modes | **50 %** (1/2) | black/white done (incl. TrueType import); anti-aliased not yet | -| Readable attribute names in JSON | **65 %** (20/31 types) | value lists taken from the Editor for all Basic types; Intelligent-only types still raw numbers | +| Readable attribute names in JSON | **100 %** (31/31 types) | every value list the Editor documents, incl. the Intelligent-only types and load effects | | Rendering, Basic components | **100 %** (20/20 pixel-exact) | incl. gauges and QR codes (own encoder, no dependencies) | | Rendering, all components | **94 %** (29/31 pixel-exact) | Intelligent ComboBox and Switch are drawn, but their anti-aliased edges are approximate (~99 % / ~92 % of pixels exact) | | `.tft` compilation | **31 %** (2.5/8 milestones) | layout mapped, layout table decoded, trailer checksum (same-length edits only); not usable yet | diff --git a/docs/COVERAGE.md b/docs/COVERAGE.md index 183ddba..0839e76 100644 --- a/docs/COVERAGE.md +++ b/docs/COVERAGE.md @@ -59,6 +59,11 @@ byte for byte, or a file written by nxhmi was opened in the Editor and showed th - Value names for `vscope`, `sta` (per component type), `style`, `xcen`, `ycen`, `isbr`, `pw`, `format`, `dir`, `en`, `mode`, `psta`, `dez`, variable type, QR logo -- taken from the Editor's own attribute notes. Colours as `#rrggbb`. Still round-trips byte for byte. +- Intelligent: `drag`, load `effect` (pages have two more), transparency background, and the + value lists of all 11 Intelligent-only types (switch direction, ComboBox arrow / expansion, + TextSelect lines, SLText / DataRecord / FileBrowser scroll bar, DataRecord options, + media source / state / looping). Note: the Editor lists 3D_Down for TextSelect but refuses to + compile it (only 0-1 compile). ### Pictures - `N.i` format 0 (Basic, raw RGB565) and format 4 (Intelligent, run-length + 7-bit alpha), stored diff --git a/src/nxhmi/enums.py b/src/nxhmi/enums.py index c0301be..2b69aa8 100644 --- a/src/nxhmi/enums.py +++ b/src/nxhmi/enums.py @@ -18,8 +18,18 @@ GENERAL = { "ycen": {0: "up", 1: "center", 2: "down"}, "isbr": {0: "false", 1: "true"}, "pw": {0: "character", 1: "password"}, + # Intelligent series (every visible component has these) + "drag": {0: "no", 1: "yes"}, + "effect": {0: "load", 1: "top fly into", 2: "bottom fly into", 3: "left fly into", 4: "right fly into", + 5: "top left fly into", 6: "top right fly into", 7: "bottom left fly into", + 8: "bottom right fly into"}, } +_STA4 = {0: "crop image", 1: "solid color", 2: "image", 3: "transparency"} # Intelligent widgets +_SCROLLBAR = {0: "no display", 1: "operation time display", 2: "continuous display"} +_MEDIA = {"from": {0: "internal file", 1: "external file"}, "en": {0: "stop", 1: "play", 2: "pause"}, + "loop": {0: "no", 1: "yes"}} + # component type -> attribute -> {value: label} BY_TYPE = { 121: {"sta": {0: "no background", 1: "solid color", 2: "image"}}, # page @@ -35,8 +45,27 @@ BY_TYPE = { 106: {"sta": {0: "solid color", 1: "image"}, "dez": {0: "horizontal", 1: "vertical"}}, # progress bar 0: {"dir": {0: "left to right", 1: "right to left", 2: "right align"}}, # waveform 58: {"sta": {0: "none", 1: "has"}}, # qrcode (logo) + # Intelligent-only types (notes read from the Editor with an Intelligent model) + 67: {"dez": {0: "horizontal", 1: "vertical"}}, # switch + 61: {"sta": _STA4, "up": {0: "not display", 1: "display"}, # combobox + "dir": {0: "up", 1: "down", 2: "left", 3: "right"}, "down": {0: "contraction", 1: "expansion"}, + "mode": {0: "no display", 1: "only display triangle", 2: "display background + triangle"}}, + 68: {"sta": _STA4, "style": {0: "flat", 1: "border", 2: "3D_Down"}, # text select + "dis": {0: "no", 1: "yes"}}, + 62: {"sta": _STA4, "left": _SCROLLBAR}, # SLText + 66: {"sta": _STA4, "left": _SCROLLBAR, "mode": {0: "not allowed", 1: "allowed"}, # data record + "dis": {0: "not allowed", 1: "allowed"}, "order": {0: "new data before", 1: "new data after"}}, + 65: {"sta": _STA4, "left": _SCROLLBAR, "psta": {0: "no", 1: "yes"}, # file browser + "fwarning": {0: "not prompt", 1: "prompt"}}, + 2: {"en": _MEDIA["en"], "loop": _MEDIA["loop"]}, # Gmov + 3: dict(_MEDIA), # video + 4: dict(_MEDIA), # audio } +# page "load effect" has two more entries than components +BY_TYPE[121] = dict(BY_TYPE[121], effect={**GENERAL["effect"], 9: "fade into the gradual change", + 10: "middle zoom in"}) + COLOR_ATTRS = {"bco", "bco1", "bco2", "pco", "pco0", "pco1", "pco2", "pco3", "borderc", "gdc"} diff --git a/src/nxhmi/render.py b/src/nxhmi/render.py index ffd7aaf..2b09bcd 100644 --- a/src/nxhmi/render.py +++ b/src/nxhmi/render.py @@ -559,10 +559,11 @@ class Renderer: hig = c.get("hig") or 1 x, y, w, h = self._inner(c, x, y, w, h) # items, lines and fade inside the border top = y + (h - hig) // 2 - lc = self.rgb(c.get("pco1") or 0) - img.paste(lc, (x, top, x + w, top + 1)) - bot = y + h - 1 - (h - hig) // 2 # mirrors the top line - img.paste(lc, (x, bot, x + w, bot + 1)) + if c.get("dis") != 0: # dis: selected item with horizontal lines + lc = self.rgb(c.get("pco1") or 0) + img.paste(lc, (x, top, x + w, top + 1)) + bot = y + h - 1 - (h - hig) // 2 # mirrors the top line + img.paste(lc, (x, bot, x + w, bot + 1)) bg = self.rgb(c.get("bco") or 0) val = c.get("val") or 0 if val >= len(items): diff --git a/tests/test_enums.py b/tests/test_enums.py index a633b96..7827b44 100644 --- a/tests/test_enums.py +++ b/tests/test_enums.py @@ -27,6 +27,27 @@ class Enums(unittest.TestCase): with self.assertRaises(ValueError): enums.from_label(116, "xcen", "u8", "sideways") + def test_intelligent_types(self): + # value lists from the Editor's attribute notes (Intelligent model) + self.assertEqual(enums.to_label(67, "dez", "u8", 1), "vertical") # switch + self.assertEqual(enums.to_label(61, "dir", "u8", 1), "down") # combobox + self.assertEqual(enums.to_label(68, "sta", "u8", 3), "transparency") # text select + self.assertEqual(enums.to_label(66, "order", "u8", 0), "new data before") # data record + self.assertEqual(enums.to_label(3, "en", "u8", 2), "pause") # video + self.assertEqual(enums.to_label(121, "effect", "u8", 10), "middle zoom in") # page only + self.assertEqual(enums.to_label(116, "effect", "u8", 10), 10) + self.assertEqual(enums.from_label(65, "psta", "u8", "yes"), 1) # file browser + + def test_every_type_has_names(self): + import json, os + from nxhmi import components + here = os.path.dirname(components.__file__) + types = json.load(open(os.path.join(here, "templates_intelligent.json"), encoding="utf-8"))["types"] + for t, spec in types.items(): + names = {a[0] for a in spec["att"]} + labelled = [a for a in names if enums.table(int(t), a)] + self.assertTrue(labelled, spec["kind"]) # vscope at least + def test_strings_untouched(self): self.assertEqual(enums.to_label(116, "txt", "str", "#abc"), "#abc")