Skip to content

Commit 0a0e873

Browse files
committed
WIP
1 parent a4550a3 commit 0a0e873

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

example-synoptic/b23-services/synoptic/techui-support/bob/pmac/motor_embed.bob

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@
7676
<name>OpenDisplay</name>
7777
<actions>
7878
<action type="open_display">
79-
<file>./MOTOR.bob</file>
79+
<file>$(IOC)/pmacAxis.pvi.bob</file>
80+
<macros>
81+
<M>:$(M)</M>
82+
<P>$(P)</P>
83+
</macros>
8084
<target>tab</target>
8185
<description>Open Display</description>
8286
</action>

src/techui_builder/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def setup(self):
6262

6363
self.clean_files()
6464

65-
self.generator = Generator(synoptic_dir)
65+
self.generator = Generator(synoptic_dir, self.conf.beamline.url)
6666

6767
def clean_files(self):
6868
exclude = {"index.bob"}

src/techui_builder/generate.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
@dataclass
2121
class Generator:
2222
synoptic_dir: Path = field(repr=False)
23+
beamline_url: str = field(repr=False)
2324

2425
# These are global params for the class (not accessible by user)
2526
support_path: Path = field(init=False, repr=False)
@@ -220,6 +221,9 @@ def _allocate_widget(
220221
new_widget.macro(
221222
f"{suffix_label}", suffix.removeprefix(":").removesuffix(":")
222223
)
224+
# TODO: Change this to pvi_button
225+
if True:
226+
new_widget.macro("IOC", f"{self.beamline_url}/{component.P.lower()}")
223227

224228
# The only other option is for related displays
225229
else:

src/techui_builder/validator.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
from collections import defaultdict
33
from dataclasses import dataclass, field
44
from pathlib import Path
5+
from xml.etree.ElementTree import Element, tostring
56

67
from lxml import etree
8+
from lxml.objectify import ObjectifiedElement, fromstring
79
from phoebusgen.widget.widgets import ActionButton, EmbeddedDisplay
810

911
from techui_builder.utils import read_bob
@@ -74,4 +76,41 @@ def validate_bob(
7476
f"{pwidget.get_element_value('file')} != {file_widget.file}"
7577
)
7678

79+
self._validate_macros(pwidget, file_widget)
80+
7781
LOGGER.info(f"{screen_name}.bob has been validated successfully")
82+
83+
def _validate_macros(
84+
self, pwidget: EmbeddedDisplay | ActionButton, file_widget: ObjectifiedElement
85+
):
86+
pmacros_element = pwidget.find_element("macros")
87+
# Annoyingly iterating over this also includes the element tag\
88+
# so it needs ignoring, hence the '!= "macros"'
89+
pmacros = {
90+
macro.tag: macro.text for macro in pmacros_element if macro.tag != "macros"
91+
}
92+
pmacros_keys = set(pmacros.keys())
93+
94+
fmacros = file_widget.macros.getchildren()
95+
fmacros_keys = {str(macro.tag) for macro in fmacros}
96+
97+
# Checks if there is any difference in expected macros
98+
diff_expected_macros = pmacros_keys - fmacros_keys
99+
if diff_expected_macros:
100+
LOGGER.debug(
101+
f"Expected macros {diff_expected_macros} missing from \
102+
{file_widget.name}, creating..."
103+
)
104+
for expected_macro in diff_expected_macros:
105+
macro_element = Element(expected_macro)
106+
# Get the macro value from generated pwidget macros
107+
macro_element.text = pmacros[expected_macro]
108+
109+
# Convert xml.etree.Element to ObjectifiedElement
110+
new_macro = fromstring(tostring(macro_element))
111+
112+
file_widget.macros.append(new_macro)
113+
114+
# write_bob("")
115+
116+
# pwidget.remove_element("macros")

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def example_json_map():
6060
def generator():
6161
synoptic_dir = Path(__file__).parent.joinpath(Path("t01-services/synoptic"))
6262

63-
g = Generator(synoptic_dir)
63+
g = Generator(synoptic_dir, "test_url")
6464

6565
return g
6666

0 commit comments

Comments
 (0)