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)
    def _make_export_field(self, mri, attr_name, export_name):
        controller = self.process.get_controller(mri)
        path = [mri, attr_name]
        label = camel_to_title(export_name)
        ret = {}

        def update_field(response):
            if not isinstance(response, Delta):
                # Return or Error is the end of our subscription, log and ignore
                self.log.debug("Export got response %r", response)
                return
            if not ret:
                # First call, create the initial object
                export = deserialize_object(response.changes[0][1])
                if isinstance(export, AttributeModel):

                    def setter(v):
                        context = Context(self.process)
                        context.put(path, v)

                    # Strip out tags that we shouldn't export
                    # TODO: need to strip out port tags too...
                    export.meta.set_tags(
                        without_config_tags(
                            without_group_tags(export.meta.tags)))

                    ret["setter"] = setter
                else:

                    def setter_star_args(*args):
                        context = Context(self.process)
                        context.post(path, *args)

                    ret["setter"] = setter_star_args

                # Regenerate label
                export.meta.set_label(label)
                ret["export"] = export
            else:
                # Subsequent calls, update it
                with self.changes_squashed:
                    for change in response.changes:
                        ret["export"].apply_change(*change)

        subscription = Subscribe(path=path, delta=True)
        subscription.set_callback(update_field)
        self._subscriptions.append(subscription)
        # When we have waited for the subscription, the first update_field
        # will have been called
        controller.handle_request(subscription).wait()
        return ret["export"], ret["setter"]
Exemple #3
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)
Exemple #4
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)