Skip to content

Commit

Permalink
Merge pull request #62 from evalott100/new_pvi_group_for_counters
Browse files Browse the repository at this point in the history
Make counter records have new capture pvi group
  • Loading branch information
evalott100 authored Nov 13, 2023
2 parents 0d6e38a + a795e2e commit 6194bb3
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 94 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies = [
"h5py",
"softioc>=4.4.0",
"pandablocks>=0.5.3",
"pvi==0.5",
"pvi>=0.6",
] # Add project dependencies here, e.g. ["click", "numpy"]
dynamic = ["version"]
license.file = "LICENSE"
Expand Down
52 changes: 36 additions & 16 deletions src/pandablocks_ioc/_pvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
SignalR,
SignalRW,
SignalX,
TextFormat,
TextRead,
TextWrite,
Tree,
Expand All @@ -37,6 +38,7 @@ class PviGroup(Enum):
PARAMETERS = "Parameters"
READBACKS = "Readbacks"
OUTPUTS = "Outputs"
CAPTURE = "Capture"
TABLE = "Table" # TODO: May not need this anymore


Expand Down Expand Up @@ -79,7 +81,11 @@ def add_pvi_info(
if useComboBox:
widget = ComboBox()
else:
widget = TextWrite()
if record_creation_func in (builder.longStringOut, builder.stringOut):
widget = TextWrite(format=TextFormat.string)
else:
widget = TextWrite(format=None)

component = SignalRW(record_name, record_name, widget)
access = "rw"
else:
Expand All @@ -103,21 +109,13 @@ def add_pvi_info(


_positions_table_group = Group("POSITIONS_TABLE", Grid(labelled=True), children=[])
_positions_columns_defs = [
# TODO: To exactly copy the PandA Table web GUI, we'll need a new widget
# type that displays a static string in the same space as a PV
# ("NAME", record_name),
("VALUE", SignalR),
("UNITS", SignalRW),
("SCALE", SignalRW),
("OFFSET", SignalRW),
("CAPTURE", SignalRW),
]
_positions_table_headers = ["VALUE", "UNITS", "SCALE", "OFFSET", "CAPTURE"]


# TODO: Replicate this for the BITS table
def add_positions_table_row(
record_name: str,
value_record_name: str,
units_record_name: str,
scale_record_name: str,
offset_record_name: str,
Expand All @@ -128,7 +126,7 @@ def add_positions_table_row(
# create the children, which will make it more obvious which
# component is for which column
children = [
SignalR(record_name, record_name, TextRead()),
SignalR(value_record_name, value_record_name, TextWrite()),
SignalRW(units_record_name, units_record_name, TextWrite()),
SignalRW(scale_record_name, scale_record_name, TextWrite()),
SignalRW(offset_record_name, offset_record_name, TextWrite()),
Expand All @@ -137,10 +135,10 @@ def add_positions_table_row(

row = Row()
if len(_positions_table_group.children) == 0:
row.header = [k[0] for k in _positions_columns_defs]
row.header = _positions_table_headers

row_group = Group(
record_name + "_row",
record_name,
row,
children,
)
Expand All @@ -153,6 +151,17 @@ class Pvi:

_screens_dir: Optional[Path] = None
_clear_bobfiles: bool = False

# We may want general device refs, e.g every CAPTURE group having a reference
# to the positions table
_general_device_refs = {
"CAPTURE": DeviceRef(
"AllPostionCaptureParameters",
"CAPTURE",
"PandA_POSITIONS_TABLE",
)
}

pvi_info_dict: Dict[str, Dict[PviGroup, List[Component]]] = {}

@staticmethod
Expand All @@ -177,6 +186,12 @@ def add_pvi_info(record_name: EpicsName, group: PviGroup, component: Component):
else:
Pvi.pvi_info_dict[record_base] = {group: [component]}

@staticmethod
def add_general_device_refs_to_groups(device: Device):
for group in device.children:
if group.name in Pvi._general_device_refs:
group.children.append(Pvi._general_device_refs[group.name])

@staticmethod
def create_pvi_records(record_prefix: str):
"""Create the :PVI records, one for each block and one at the top level"""
Expand Down Expand Up @@ -227,10 +242,12 @@ def create_pvi_records(record_prefix: str):
devices.append(top_device)

# Create top level Device, with references to all child Devices
device_refs = [DeviceRef(x, x) for x in pvi_records]
index_device_refs = [
DeviceRef(x, x, x.replace(":PVI", "")) for x in pvi_records
]

# # TODO: What should the label be?
device = Device("TOP", children=device_refs)
device = Device("index", children=index_device_refs)
devices.append(device)

# TODO: label widths need some tweaking - some are pretty long right now
Expand All @@ -256,4 +273,7 @@ def create_pvi_records(record_prefix: str):

for device in devices:
bobfile_path = Pvi._screens_dir / Path(f"{device.label}.bob")

Pvi.add_general_device_refs_to_groups(device)

formatter.format(device, record_prefix + ":", bobfile_path)
17 changes: 8 additions & 9 deletions src/pandablocks_ioc/ioc.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,6 @@ def _create_record_info(
updating the record.
"""
extra_kwargs: Dict[str, Any] = {}

assert (
record_creation_func in self._builder_methods
), "Unrecognised record creation function passed to _create_record_info"
Expand Down Expand Up @@ -824,7 +823,6 @@ def _make_pos_out(
record_dict: Dict[EpicsName, RecordInfo] = {}

units_record_name = EpicsName(record_name + ":UNITS")

record_dict[record_name] = self._create_record_info(
record_name,
field_info.description,
Expand All @@ -844,7 +842,7 @@ def _make_pos_out(
"Capture options",
builder.mbbOut,
int,
PviGroup.PARAMETERS,
PviGroup.CAPTURE,
labels=labels,
initial_value=capture_index,
)
Expand All @@ -855,7 +853,7 @@ def _make_pos_out(
"Offset",
builder.aOut,
float,
PviGroup.PARAMETERS,
PviGroup.CAPTURE,
initial_value=values[offset_record_name],
)

Expand All @@ -865,7 +863,7 @@ def _make_pos_out(
"Scale factor",
builder.aOut,
float,
PviGroup.PARAMETERS,
PviGroup.CAPTURE,
initial_value=values[scale_record_name],
)

Expand All @@ -874,7 +872,7 @@ def _make_pos_out(
"Units string",
builder.stringOut,
str,
PviGroup.PARAMETERS,
PviGroup.CAPTURE,
initial_value=values[units_record_name],
)

Expand All @@ -899,9 +897,8 @@ def _make_pos_out(
DESC="Table of configured positional outputs",
)

scaled_calc_record.add_alias(
self._record_prefix + ":" + positions_record_name + ":VAL"
)
value_record_name = EpicsName(positions_record_name + ":VAL")
scaled_calc_record.add_alias(self._record_prefix + ":" + value_record_name)

record_dict[capture_record_name].record.add_alias(
self._record_prefix
Expand Down Expand Up @@ -935,6 +932,7 @@ def _make_pos_out(
self._pos_out_row_counter += 1
add_positions_table_row(
record_name,
value_record_name,
units_record_name,
scale_record_name,
offset_record_name,
Expand Down Expand Up @@ -1809,6 +1807,7 @@ async def create_records(
# unrelated fields. e.g. for record_name "INENC1:CLK",
# values for keys "INENC1:CLK" "INENC1:CLK:DELAY" should match
# but "INENC1:CLK_PERIOD" should not

field_values = {
field: value
for field, value in values.items()
Expand Down
2 changes: 2 additions & 0 deletions tests/test-bobfiles/HDF5.bob
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<width>60</width>
<height>20</height>
<horizontal_alignment>1</horizontal_alignment>
<format>6</format>
</widget>
<widget type="label" version="2.0.0">
<name>Label</name>
Expand All @@ -65,6 +66,7 @@
<width>60</width>
<height>20</height>
<horizontal_alignment>1</horizontal_alignment>
<format>6</format>
</widget>
<widget type="label" version="2.0.0">
<name>Label</name>
Expand Down
10 changes: 6 additions & 4 deletions tests/test-bobfiles/PCAP.bob
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<width>60</width>
<height>20</height>
<horizontal_alignment>1</horizontal_alignment>
<format>6</format>
</widget>
<widget type="label" version="2.0.0">
<name>Label</name>
Expand All @@ -58,13 +59,13 @@
<height>20</height>
</widget>
<widget type="action_button" version="3.0.0">
<name>ActionButton</name>
<name>WritePV</name>
<pv_name>TEST_PREFIX:PCAP:ARM</pv_name>
<actions>
<action type="write_pv">
<pv_name>$(pv_name)</pv_name>
<value>1</value>
<description>WritePV</description>
<description>$(name)</description>
</action>
</actions>
<text>Arm</text>
Expand All @@ -75,13 +76,13 @@
<tooltip>$(actions)</tooltip>
</widget>
<widget type="action_button" version="3.0.0">
<name>ActionButton</name>
<name>WritePV</name>
<pv_name>TEST_PREFIX:PCAP:ARM</pv_name>
<actions>
<action type="write_pv">
<pv_name>$(pv_name)</pv_name>
<value>0</value>
<description>WritePV</description>
<description>$(name)</description>
</action>
</actions>
<text>Disarm</text>
Expand Down Expand Up @@ -115,6 +116,7 @@
<width>60</width>
<height>20</height>
<horizontal_alignment>1</horizontal_alignment>
<format>6</format>
</widget>
<widget type="label" version="2.0.0">
<name>Label</name>
Expand Down
14 changes: 11 additions & 3 deletions tests/test-bobfiles/PandA.bob
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<name>Display</name>
<x>0</x>
<y>0</y>
<width>10</width>
<height>35</height>
<width>46</width>
<height>71</height>
<grid_step_x>4</grid_step_x>
<grid_step_y>4</grid_step_y>
<widget type="label" version="2.0.0">
Expand All @@ -12,7 +12,7 @@
<text>PandA - TEST_PREFIX:</text>
<x use_class="true">0</x>
<y use_class="true">0</y>
<width>10</width>
<width>46</width>
<height>25</height>
<font use_class="true">
<font name="Header 1" family="Liberation Sans" style="BOLD" size="22.0">
Expand All @@ -25,4 +25,12 @@
<transparent use_class="true">true</transparent>
<horizontal_alignment>1</horizontal_alignment>
</widget>
<widget type="group" version="2.0.0">
<name>POSITIONS_ TABLE</name>
<x>5</x>
<y>30</y>
<width>36</width>
<height>36</height>
<transparent>true</transparent>
</widget>
</display>
60 changes: 0 additions & 60 deletions tests/test-bobfiles/TOP.bob

This file was deleted.

Loading

0 comments on commit 6194bb3

Please sign in to comment.