def _make_child_controller(self, parts, mri):
     # Add some extra parts to determine the dataset name and type for
     # any CAPTURE field part
     new_parts = []
     for existing_part in parts:
         new_parts.append(existing_part)
         if existing_part.name.endswith(".CAPTURE"):
             # Add capture dataset name and type
             part_name = existing_part.name.replace(".CAPTURE",
                                                    ".DATASET_NAME")
             attr_name = snake_to_camel(part_name.replace(".", "_"))
             new_parts.append(
                 call_with_params(
                     StringPart,
                     name=attr_name,
                     widget="textinput",
                     description="Name of the captured dataset in HDF file",
                     writeable=True,
                     config=True))
             # Make a choice part to hold the type of the dataset
             part_name = existing_part.name.replace(".CAPTURE",
                                                    ".DATASET_TYPE")
             attr_name = snake_to_camel(part_name.replace(".", "_"))
             if "INENC" in mri:
                 initial = "position"
             else:
                 initial = "monitor"
             new_parts.append(
                 call_with_params(
                     ChoicePart,
                     name=attr_name,
                     widget="combo",
                     description="Type of the captured dataset in HDF file",
                     writeable=True,
                     choices=attribute_dataset_types,
                     initialValue=initial))
     if mri.endswith("PCAP"):
         new_parts += call_with_params(
             adbase_parts,
             self.process,
             prefix=self.params.areaDetectorPrefix)
         controller = call_with_params(StatefulController,
                                       self.process,
                                       new_parts,
                                       mri=mri)
     else:
         controller = super(PandABlocksRunnableController, self).\
             _make_child_controller(new_parts, mri)
     return controller
예제 #2
0
 def __init__(self, client, meta, block_name, field_name, writeable):
     super(PandABlocksTablePart, self).__init__(client, meta, block_name,
                                                field_name, writeable)
     # Fill in the meta object with the correct headers
     columns = OrderedDict()
     self.fields = OrderedDict()
     fields = client.get_table_fields(block_name, field_name)
     for field_name, (bits_hi, bits_lo) in fields.items():
         nbits = bits_hi - bits_lo + 1
         if nbits < 1:
             raise ValueError("Bad bits %s:%s" % (bits_hi, bits_lo))
         if nbits == 1:
             column_meta = BooleanArrayMeta(field_name)
             widget_tag = widget("checkbox")
         else:
             if nbits <= 8:
                 dtype = "uint8"
             elif nbits <= 16:
                 dtype = "uint16"
             elif nbits <= 32:
                 dtype = "uint32"
             elif nbits <= 64:
                 dtype = "uint64"
             else:
                 raise ValueError("Bad bits %s:%s" % (bits_hi, bits_lo))
             column_meta = NumberArrayMeta(dtype, field_name)
             widget_tag = widget("textinput")
         column_name = snake_to_camel(field_name)
         column_meta.set_label(camel_to_title(column_name))
         column_meta.set_tags([widget_tag])
         columns[column_name] = column_meta
         self.fields[column_name] = (bits_hi, bits_lo)
     meta.set_elements(columns)
예제 #3
0
 def setup(self, registrar):
     # type: (PartRegistrar) -> None
     attr_name = snake_to_camel(self.field_name.replace(".", "_"))
     if self.meta.writeable:
         writeable_func = self.set_field
     else:
         writeable_func = None
     registrar.add_attribute_model(attr_name, self.attr, writeable_func)
예제 #4
0
 def create_attribute_models(self):
     attr_name = snake_to_camel(self.field_name.replace(".", "_"))
     self.attr = self.meta.create_attribute_model(self.initial_value)
     if self.writeable:
         writeable_func = self.set_field
     else:
         writeable_func = None
     yield attr_name, self.attr, writeable_func
예제 #5
0
 def setup(self, registrar: PartRegistrar) -> None:
     super().setup(registrar)
     attr_name = snake_to_camel(self.field_name.replace(".", "_"))
     writeable_func: Optional[Callable]
     if self.meta.writeable:
         writeable_func = self.set_field
     else:
         writeable_func = None
     registrar.add_attribute_model(attr_name, self.attr, writeable_func)
 def _make_child_controller(self, parts, mri):
     # Add some extra parts to determine the dataset name and type for
     # any CAPTURE field part
     new_parts = []
     for existing_part in parts:
         new_parts.append(existing_part)
         if hasattr(existing_part, "field_name") and \
                 existing_part.field_name.endswith(".CAPTURE"):
             # Add capture dataset name and type
             part_name = existing_part.field_name.replace(
                 ".CAPTURE", ".DATASET_NAME")
             attr_name = snake_to_camel(part_name.replace(".", "_"))
             new_parts.append(
                 StringPart(
                     name=attr_name,
                     description="Name of the captured dataset in HDF file",
                     writeable=True))
             # Make a choice part to hold the type of the dataset
             part_name = existing_part.field_name.replace(
                 ".CAPTURE", ".DATASET_TYPE")
             attr_name = snake_to_camel(part_name.replace(".", "_"))
             if "INENC" in mri:
                 initial = "position"
             else:
                 initial = "monitor"
             new_parts.append(
                 ChoicePart(
                     name=attr_name,
                     description="Type of the captured dataset in HDF file",
                     writeable=True,
                     choices=list(AttributeDatasetType),
                     value=initial))
     if mri.endswith("PCAP"):
         cs, ps = adbase_parts(prefix=self.prefix)
         controller = StatefulController(mri=mri)
         for p in new_parts + ps:
             controller.add_part(p)
         for c in cs:
             self.process.add_controller(c)
     else:
         controller = super(PandABlocksRunnableController, self).\
             _make_child_controller(new_parts, mri)
     return controller
예제 #7
0
 def _handle_mux_update(self, mux_meta, v):
     # Mux changed its value, update its link to a different
     # Attribute
     tags = without_linked_value_tags(mux_meta.tags)
     split = v.split(".")
     if len(split) == 2:
         block_name, field_name = split
         attr_name = snake_to_camel(field_name.replace(".", "_"))
         block_mri = "%s:%s" % (self.mri_prefix, block_name)
         tags.append(linked_value_tag(block_mri, attr_name))
     mux_meta.set_tags(tags)
예제 #8
0
 def _make_mux(
     self, field_name: str, field_data: FieldData, port_type: Port
 ) -> None:
     group = self._make_group("inputs")
     labels = [x for x in field_data.labels if x in ("ZERO", "ONE")] + sorted(
         x for x in field_data.labels if x not in ("ZERO", "ONE")
     )
     tags = [group, port_type.sink_port_tag("ZERO"), Widget.COMBO.tag()]
     if port_type == Port.BOOL:
         # Bits have a delay, use it as a badge
         delay_name = snake_to_camel(field_name) + "Delay"
         tags.append(badge_value_tag(self.mri, delay_name))
     meta = ChoiceMeta(field_data.description, labels, tags=tags)
     self._make_field_part(field_name, meta, writeable=True)
     self.mux_metas[field_name] = meta
예제 #9
0
    def create_method_models(self):
        method_name = snake_to_camel(self.field_name)
        if self.arg_meta:
            self.arg_name = method_name

            # Decorate set_field with a Method
            @method_takes(self.arg_name, self.arg_meta, REQUIRED)
            def set_field(params):
                self.set_field(params)

            self.method = set_field.MethodModel
            writeable_func = set_field
        else:
            self.method = MethodModel()
            writeable_func = None
        self.method.set_description(self.description)
        self.method.set_tags(self.tags)
        yield method_name, self.method, writeable_func
예제 #10
0
 def __init__(self, client, meta, block_name, field_name):
     # type: (AClient, AMeta, ABlockName, AFieldName) -> None
     # Fill in the meta object with the correct headers
     columns = OrderedDict()
     self.field_data = OrderedDict()
     fields = client.get_table_fields(block_name, field_name)
     if not fields:
         # Didn't put any metadata in, make some up
         fields["VALUE"] = TableFieldData(31, 0, "The Value", None)
     for column_name, field_data in fields.items():
         nbits = field_data.bits_hi - field_data.bits_lo + 1
         if nbits < 1:
             raise ValueError("Bad bits in %s" % (field_data, ))
         if field_data.labels:
             column_meta = ChoiceArrayMeta(choices=field_data.labels)
             widget = Widget.COMBO
         elif nbits == 1:
             column_meta = BooleanArrayMeta()
             widget = Widget.CHECKBOX
         else:
             if nbits <= 8:
                 dtype = "uint8"
             elif nbits <= 16:
                 dtype = "uint16"
             elif nbits <= 32:
                 dtype = "uint32"
             elif nbits <= 64:
                 dtype = "uint64"
             else:
                 raise ValueError("Bad bits in %s" % (field_data, ))
             column_meta = NumberArrayMeta(dtype)
             widget = Widget.TEXTINPUT
         column_name = snake_to_camel(column_name)
         column_meta.set_label(camel_to_title(column_name))
         column_meta.set_tags([widget.tag()])
         column_meta.set_description(field_data.description)
         column_meta.set_writeable(True)
         columns[column_name] = column_meta
         self.field_data[column_name] = field_data
     meta.set_elements(columns)
     # Superclass will make the attribute for us
     super(PandABlocksTablePart, self).__init__(client, meta, block_name,
                                                field_name)
예제 #11
0
 def __init__(
     self,
     client: AClient,
     meta: AMeta,
     block_name: ABlockName,
     field_name: AFieldName,
 ) -> None:
     # Fill in the meta object with the correct headers
     columns = OrderedDict()
     self.field_data = OrderedDict()
     fields = client.get_table_fields(block_name, field_name)
     if not fields:
         # Didn't put any metadata in, make some up
         fields["VALUE"] = TableFieldData(31, 0, "The Value", None, True)
     for column_name, field_data in fields.items():
         nbits = field_data.bits_hi - field_data.bits_lo + 1
         if nbits < 1:
             raise ValueError("Bad bits in %s" % (field_data, ))
         if field_data.labels:
             column_meta = ChoiceArrayMeta(choices=field_data.labels)
             widget = Widget.COMBO
         elif nbits == 1:
             column_meta = BooleanArrayMeta()
             widget = Widget.CHECKBOX
         else:
             dtype = get_dtype(nbits, field_data.signed)
             column_meta = NumberArrayMeta(dtype)
             widget = Widget.TEXTINPUT
         column_name = snake_to_camel(column_name)
         column_meta.set_label(camel_to_title(column_name))
         column_meta.set_tags([widget.tag()])
         column_meta.set_description(field_data.description)
         column_meta.set_writeable(True)
         columns[column_name] = column_meta
         self.field_data[column_name] = field_data
     meta.set_elements(columns)
     # Work out how many ints per row
     # TODO: this should be in the block data
     max_bits_hi = max(f.bits_hi for f in self.field_data.values())
     self.ints_per_row = int((max_bits_hi + 31) / 32)
     # Superclass will make the attribute for us
     super().__init__(client, meta, block_name, field_name)
예제 #12
0
 def setup(self, registrar):
     # type: (PartRegistrar) -> None
     method_name = snake_to_camel(self.field_name)
     self.method = registrar.add_method_model(self.set_field, method_name,
                                              self.description)
     self.method.set_tags(self.tags)
예제 #13
0
 def setup(self, registrar: PartRegistrar) -> None:
     super().setup(registrar)
     method_name = snake_to_camel(self.field_name)
     self.method = registrar.add_method_model(self.set_field, method_name,
                                              self.description)
     self.method.meta.set_tags(self.tags)