diff --git a/src/techui_builder/generate.py b/src/techui_builder/generate.py index 7ea36f1..80c986d 100644 --- a/src/techui_builder/generate.py +++ b/src/techui_builder/generate.py @@ -193,12 +193,24 @@ def _allocate_widget( self, scrn_mapping: Mapping, component: Entity ) -> EmbeddedDisplay | ActionButton | None | list[EmbeddedDisplay | ActionButton]: name, suffix, suffix_label = self._initialise_name_suffix(component) + # Get relative path to screen - scrn_path = self.support_path.joinpath(f"bob/{scrn_mapping['file']}") - logger_.debug(f"Screen path: {scrn_path}") + file = scrn_mapping["file"] + if file.startswith("$(IOC)"): + scrn_path = data_scrn_path = file.replace( + "$(IOC)", f"{self.beamline_url}/{component.service_name}" + ) # Only works with related displays as + # embedded displays need to access the file to get dimensions + + assert scrn_mapping["type"] == "related", ( + "Only related displays can have remote screens" + ) + else: + scrn_path = self.support_path.joinpath(f"bob/{file}") + logger_.debug(f"Screen path: {scrn_path}") - # Path of screen relative to data/ so it knows where to open the file from - data_scrn_path = scrn_path.relative_to(self.synoptic_dir, walk_up=True) + # Path of screen relative to data/ so it knows where to open the file from + data_scrn_path = scrn_path.relative_to(self.synoptic_dir, walk_up=True) # For Gui Components with multiple components embedded, we add a suffix field # to the components, and adjust the name and suffix accordingly diff --git a/tests/test_builder.py b/tests/test_builder.py index 24375b0..ee59a32 100644 --- a/tests/test_builder.py +++ b/tests/test_builder.py @@ -337,7 +337,9 @@ def test_generate_json_map_embedded_screen( test_json_map = builder_with_test_files._generate_json_map( screen_path, dest_path, components ) - + print(test_json_map) + print("--------------") + print(example_json_map) assert test_json_map == example_json_map diff --git a/tests/test_generate.py b/tests/test_generate.py index 18f742a..7a4bc8f 100644 --- a/tests/test_generate.py +++ b/tests/test_generate.py @@ -265,6 +265,31 @@ def test_generator_allocate_widget(generator): assert str(widget) == xml_content +def test_generator_allocate_widget_with_remote_screens(generator): + generator._initilise_name_suffix = Mock(return_value=("CAM:", "CAM:", "R")) + + scrn_mapping = { + "file": "$(IOC)/ADAravis_summary.bob", + "prefix": "$(P)$(R)", + "type": "related", + } + component = Entity( + service_name="bl01t-di-ioc-01", + type="ADAravis.aravisCamera", + P="BL01T-DI-IOC-01", + desc=None, + M=None, + R=":CAM:", + ) + widget = generator._allocate_widget(scrn_mapping, component) + control_widget = Path("tests/test_files/widget_url_screen.xml") + + with open(control_widget) as f: + xml_content = f.read() + print(str(widget)) + assert str(widget) == xml_content + + def test_generator_allocate_widget_with_suffix(generator): generator._initialise_name_suffix = Mock(return_value=(":CAM:", ":CAM:", "R"))