tft: text (plain) and touch cap; 55 Editor samples reproduced byte for byte

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Fable 5.2 committed 2026-11-16 18:29:12 +01:00
1 parent 0532a59120
commit b5eaa68298
7 files changed
+102 -16

No files matched your search

+31
View File
@@ -62,6 +62,30 @@ class Build(unittest.TestCase):
self.assertEqual(obj[:2], bytes([109, 1]))
self.assertEqual(struct.unpack_from("<6H", obj, 0x28), (10, 20, 30, 40, 39, 59))
def test_text_timer_touch_cap_and_script(self):
from nxhmi import fonts
h = project.new_project("NX4832T035_011", program="int n=0\r\nbaud=115200\r\npage 0\r\n")
project.add_font(h, fonts.from_ttf(None, 16)) if HAVE_PIL else None
p = Page.parse(h.read("0.pa"))
if HAVE_PIL:
C.add(p, "text", x=5, y=5, w=100, h=30, txt="hi")
C.add(p, "timer")
C.add(p, "touch_cap")
tm = [c for c in p.components if c.get("objname") == "tm0"][0]
tm.set_event("codestimer", ["if(n<1000)", "{", " n++", "}else", "{", " tm0.en=0", "}"])
h.write("0.pa", p.pack())
out = tft_build.build_tft(h, self.tmp)
self.assertTrue(tft.verify_header(out) and tft.verify_trailer(out))
lay = tft.layout_table(out)
self.assertEqual(lay[2], 1) # one global variable
self.assertEqual(lay[3], lay[0] + 12) # its 12-byte descriptor
blob = out[lay[5]:lay[5] + lay[0]]
self.assertIn(b"\x05\x00\x00\x00\x00++", blob) # n++
self.assertIn(b"timer", blob)
self.assertIn(b"\x09\x16\x041", blob) # touch cap init line
if HAVE_PIL:
self.assertIn(b"\x09\x1c\x085,5,100,30,", blob) # text draw line
def test_name_hash(self):
self.assertEqual(tft.name_hash("page0"), 0xAC967926) # measured in Editor output
@@ -72,6 +96,13 @@ class Build(unittest.TestCase):
h.write("0.pa", p.pack())
with self.assertRaises(tft_build.Unsupported):
tft_build.build_tft(h, self.tmp)
# a text component without any font in the project (the Editor refuses to compile that too)
h = self.project()
p = Page.parse(h.read("0.pa"))
C.add(p, "text", x=1, y=1, w=50, h=20)
h.write("0.pa", p.pack())
with self.assertRaises(tft_build.Unsupported):
tft_build.build_tft(h, self.tmp)
def test_cli(self):
hmi, out = os.path.join(self.tmp, "p.HMI"), os.path.join(self.tmp, "p.tft")