Skip to content

Commit 1c5aaf5

Browse files
Added functionality to fetch files in action buttons in embedded screens to add to the JsonMap
1 parent 7f6b5c0 commit 1c5aaf5

File tree

3 files changed

+68
-13
lines changed

3 files changed

+68
-13
lines changed

src/techui_builder/builder.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,29 @@ def _get_macros(element: ObjectifiedElement):
256256
}
257257
return {}
258258

259+
def _extract_action_button_file_from_embedded(
260+
file_elem: ObjectifiedElement,
261+
) -> ObjectifiedElement:
262+
file_path = Path(file_elem.text.strip() if file_elem.text else "")
263+
file_path = dest_path.joinpath(file_path)
264+
tree = objectify.parse(file_path.absolute())
265+
root: ObjectifiedElement = tree.getroot()
266+
267+
# Find all <widget> elements
268+
widgets = [
269+
w
270+
for w in root.findall(".//widget")
271+
if w.get("type", default=None) == "action_button"
272+
]
273+
274+
for widget_elem in widgets:
275+
open_display = _get_action_group(widget_elem)
276+
if open_display is None:
277+
continue
278+
file_elem = open_display.file
279+
return file_elem
280+
return file_elem
281+
259282
if visited is None:
260283
visited = set()
261284

@@ -279,7 +302,7 @@ def _get_macros(element: ObjectifiedElement):
279302
for w in root.findall(".//widget")
280303
if w.get("type", default=None)
281304
# in ["symbol", "embedded", "action_button"]
282-
in ["symbol", "action_button"]
305+
in ["symbol", "action_button", "embedded"]
283306
]
284307

285308
for widget_elem in widgets:
@@ -295,9 +318,12 @@ def _get_macros(element: ObjectifiedElement):
295318
file_elem = open_display.file
296319

297320
macro_dict = _get_macros(open_display)
298-
# case "embedded":
299-
# file_elem = widget_elem.file
300-
# macro_dict = _get_macros(widget_elem)
321+
case "embedded":
322+
file_elem = _extract_action_button_file_from_embedded(
323+
widget_elem.file
324+
)
325+
macro_dict = _get_macros(widget_elem)
326+
301327
case _:
302328
continue
303329

tests/test_builder.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,16 +300,14 @@ def test_generate_json_map(builder_with_test_files, example_json_map, test_files
300300

301301

302302
# TODO: write this test
303-
# def test_generate_json_map_embedded_screen(builder, example_json_map):
304-
# screen_path = Path("tests/test_files/test_bob.bob")
305-
# dest_path = Path("tests/test_files/")
303+
def test_generate_json_map_embedded_screen(builder_with_test_files, example_json_map):
304+
screen_path = Path("tests/test_files/test_bob_embedded.bob").absolute()
305+
dest_path = Path("tests/test_files/")
306306

307-
# # Set widget type to embedded
308-
# ...
309-
310-
# test_json_map = builder._generate_json_map(screen_path, dest_path)
311-
312-
# assert test_json_map == example_json_map
307+
test_json_map = builder_with_test_files._generate_json_map(screen_path, dest_path)
308+
example_json_map.file = "test_bob_embedded.bob"
309+
example_json_map.children.append(JsonMap("$(IOC)/pmacAxis.pvi.bob", exists=False))
310+
assert test_json_map == example_json_map
313311

314312

315313
def test_generate_json_map_get_macros(
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--Saved on 2026-01-12 10:15:49 by uns32131-->
3+
<display version="2.0.0">
4+
<name>Display</name>
5+
<widget type="symbol" version="2.0.0">
6+
<name>Detector</name>
7+
<pv_name>test_device</pv_name>
8+
<x>60</x>
9+
<y>150</y>
10+
<width>50</width>
11+
<height>50</height>
12+
<actions>
13+
<action type="open_display">
14+
<description>Open Display</description>
15+
<file>test_child_bob.bob</file>
16+
<target>replace</target>
17+
</action>
18+
</actions>
19+
<tooltip>$(pv_name)
20+
$(pv_value)
21+
$(actions)</tooltip>
22+
</widget>
23+
<widget type="embedded" version="2.0.0">
24+
<name>Embedded Display</name>
25+
<file>motor_embed.bob</file>
26+
<x>150</x>
27+
<y>120</y>
28+
<width>160</width>
29+
<height>80</height>
30+
</widget>
31+
</display>

0 commit comments

Comments
 (0)