예제 #1
0
def make_meta(subtyp, description, tags, writeable=True, labels=None):
    if subtyp == "enum":
        if writeable:
            widget_type = "combo"
        else:
            widget_type = "textupdate"
        tags.append(widget(widget_type))
        meta = ChoiceMeta(description, labels, tags)
    elif subtyp == "bit":
        if writeable:
            widget_type = "checkbox"
        else:
            widget_type = "led"
        tags.append(widget(widget_type))
        meta = BooleanMeta(description, tags)
    else:
        if writeable:
            widget_type = "textinput"
        else:
            widget_type = "textupdate"
        tags.append(widget(widget_type))
        if subtyp == "uint":
            meta = NumberMeta("uint32", description, tags)
        elif subtyp == "int":
            meta = NumberMeta("int32", description, tags)
        elif subtyp == "scalar":
            meta = NumberMeta("float64", description, tags)
        elif subtyp == "lut":
            meta = StringMeta(description, tags)
        elif subtyp in ("pos", "relative_pos"):
            meta = NumberMeta("float64", description, tags)
        else:
            raise ValueError("Unknown subtype %r" % subtyp)
    return meta
예제 #2
0
 def test_init(self):
     self.choice_meta = ChoiceMeta("test description", ["a", "b"])
     self.assertEqual("test description", self.choice_meta.description)
     self.assertEqual(self.choice_meta.typeid,
                      "malcolm:core/ChoiceMeta:1.0")
     self.assertEqual(self.choice_meta.label, "")
     self.assertEqual(self.choice_meta.choices, ("a", "b"))
예제 #3
0
 def create_attributes(self):
     tags = ["widget:group"]
     meta = ChoiceMeta("All %s attributes" % self.attr_name,
                       choices=["expanded", "collapsed"],
                       tags=tags,
                       label=self.attr_name.title())
     self.attr = meta.make_attribute("expanded")
     yield self.attr_name, self.attr, self.attr.set_value
예제 #4
0
 def __init__(self, process, attr_name):
     params = Part.MethodMeta.prepare_input_map(name=attr_name)
     super(PandABoxGroupPart, self).__init__(process, params)
     self.attr_name = attr_name
     tags = [widget("group"), config()]
     self.meta = ChoiceMeta("All %s attributes" % self.attr_name,
                            choices=["expanded", "collapsed"],
                            tags=tags,
                            label=self.attr_name.title())
예제 #5
0
 def create_attributes(self):
     for data in super(DetectorDriverPart, self).create_attributes():
         yield data
     meta = NumberMeta("float64", "Time taken to readout detector")
     self.readout_time = meta.make_attribute(self.params.readoutTime)
     yield "readoutTime", self.readout_time, self.readout_time.set_value
     meta = ChoiceMeta("Whether detector is software or hardware triggered",
                       ["Software", "Hardware"])
     self.trigger_mode = meta.make_attribute("Hardware")
     yield "triggerMode", self.trigger_mode, None
 def _create_default_attributes(self):
     # Add the state, status and busy attributes
     self.state = ChoiceMeta("State of Block",
                             self.stateMachine.possible_states,
                             label="State").make_attribute()
     yield "state", self.state, None
     self.status = StringMeta("Status of Block",
                              label="Status").make_attribute()
     yield "status", self.status, None
     self.busy = BooleanMeta("Whether Block busy or not",
                             label="Busy").make_attribute()
     yield "busy", self.busy, None
예제 #7
0
 def _make_time_parts(self, field_name, field_data, writeable):
     description = field_data.description
     if writeable:
         widget_tag = widget("textupdate")
         group_tag = self._make_group("parameters")
     else:
         widget_tag = widget("textinput")
         group_tag = self._make_group("readbacks")
     meta = NumberMeta("float64", description, [group_tag, widget_tag])
     self._make_field_part(field_name, meta, writeable)
     meta = ChoiceMeta(description + " time units", ["s", "ms", "us"],
                       tags=[group_tag, widget("combo")])
     self._make_field_part(field_name + ".UNITS", meta, writeable=True)
예제 #8
0
    def create_attributes(self):
        """Method that should provide Attribute instances for Block

        Yields:
            tuple: (string name, Attribute, callable put_function).
        """
        # Add the state, status and busy attributes
        self.state = ChoiceMeta("State of Block",
                                self.stateMachine.possible_states,
                                label="State").make_attribute()
        yield "state", self.state, None
        self.status = StringMeta("Status of Block",
                                 label="Status").make_attribute()
        yield "status", self.status, None
        self.busy = BooleanMeta("Whether Block busy or not",
                                label="Busy").make_attribute()
        yield "busy", self.busy, None
예제 #9
0
 def _make_mux(self, field_name, field_data, typ):
     group_tag = self._make_group("inputs")
     if typ == "bit":
         inport_type = "bool"
     else:
         inport_type = "int32"
     meta = ChoiceMeta(
         field_data.description,
         field_data.labels,
         tags=[group_tag,
               inport(inport_type, "ZERO"),
               widget("combo")])
     self._make_field_part(field_name, meta, writeable=True)
     meta = make_meta(typ,
                      "%s current value" % field_name,
                      tags=[group_tag],
                      writeable=False)
     self._make_field_part(field_name + ".VAL", meta, writeable=False)
예제 #10
0
 def create_attributes(self):
     for data in super(ManagerController, self).create_attributes():
         yield data
     # Make a table for the layout info we need
     columns = OrderedDict()
     columns["name"] = StringArrayMeta("Name of layout part")
     columns["mri"] = StringArrayMeta("Malcolm full name of child block")
     columns["x"] = NumberArrayMeta("float64", "X Coordinate of child block")
     columns["y"] = NumberArrayMeta("float64", "Y Coordinate of child block")
     columns["visible"] = BooleanArrayMeta("Whether child block is visible")
     layout_table_meta = TableMeta("Layout of child blocks", columns=columns)
     layout_table_meta.set_writeable_in(sm.EDITABLE)
     self.layout = layout_table_meta.make_attribute()
     yield "layout", self.layout, self.set_layout
     self.layout_name = ChoiceMeta(
         "Saved layout name to load", []).make_attribute()
     self.layout_name.meta.set_writeable_in(
         self.stateMachine.AFTER_RESETTING)
     yield "layoutName", self.layout_name, self.load_layout
     assert os.path.isdir(self.params.configDir), \
         "%s is not a directory" % self.params.configDir
예제 #11
0
 def _make_out_capture(self, field_name, field_data):
     group_tag = self._make_group("outputs")
     meta = ChoiceMeta("Capture %s in PCAP?" % field_name,
                       field_data.labels,
                       tags=[group_tag, widget("combo")])
     self._make_field_part(field_name + ".CAPTURE", meta, writeable=True)
     if self.area_detector:
         from malcolm.parts.ADCore.hdfwriterpart import \
             attribute_dataset_types
         # Make a string part to hold the name of the dataset
         part_name = field_name + ".DATASET_NAME"
         label, attr_name = make_label_attr_name(part_name)
         params = StringPart.MethodMeta.prepare_input_map(
             name=attr_name,
             widget="textinput",
             description="Name of the captured dataset in HDF file",
             writeable=True,
             config=True)
         part = StringPart(self.process, params)
         self._add_part(part_name, part)
         # Make a choice part to hold the type of the dataset
         part_name = field_name + ".DATASET_TYPE"
         label, attr_name = make_label_attr_name(part_name)
         if "INENC" in self.block_name:
             initial = "position"
         else:
             initial = "monitor"
         params = ChoicePart.MethodMeta.prepare_input_map(
             name=attr_name,
             widget="textinput",
             description="Type of the captured dataset in HDF file",
             writeable=True,
             choices=attribute_dataset_types,
             initialValue=initial)
         part = StringPart(self.process, params)
         self._add_part(part_name, part)
 def test_to_dict(self):
     bm = ChoiceMeta("desc", ["a", "b"], label="name")
     self.assertEqual(bm.to_dict(), self.serialized)
 def setUp(self):
     self.choice_meta = ChoiceMeta(
         "test description", ["a", "b"])
예제 #14
0
from malcolm.core import Part, method_takes, REQUIRED
from malcolm.core.vmetas import StringMeta, BooleanMeta, ChoiceMeta
from malcolm.tags import widget_types, widget, config


@method_takes(
    "name", StringMeta("Name of the created attribute"), REQUIRED,
    "description", StringMeta("Desc of created attribute"), REQUIRED,
    "widget", ChoiceMeta("Widget type", [""] + widget_types), "",
    "writeable", BooleanMeta("Is the attribute writeable?"), False,
    "config", BooleanMeta("Should this field be loaded/saved?"), False)
class AttributePart(Part):
    # Attribute instance
    attr = None

    def create_attributes(self):
        # Find the tags
        tags = self.create_tags()
        # Make a meta object for our attribute
        meta = self.create_meta(self.params.description, tags)
        # The attribute we will be publishing
        initial_value = self.get_initial_value()
        self.attr = meta.make_attribute(initial_value)
        writeable_func = self.get_writeable_func()
        yield self.params.name, self.attr, writeable_func

    def create_meta(self, description, tags):
        raise NotImplementedError()

    def get_writeable_func(self):
        if self.params.writeable:
예제 #15
0
 def create_meta(self, description, tags):
     return ChoiceMeta(choices=self.params.choices,
                       description=description,
                       tags=tags)
 def create_meta(self, description):
     return ChoiceMeta(description)
예제 #17
0
from malcolm.core import method_takes, REQUIRED
from malcolm.parts.builtin.attributepart import AttributePart
from malcolm.core.vmetas import StringMeta, ChoiceMeta, BooleanMeta
from malcolm.controllers.defaultcontroller import DefaultController
from malcolm.parts.ca.cothreadimporter import CothreadImporter
from malcolm.tags import widget_types, inport, port_types


@method_takes(
    "name", StringMeta("Name of the created attribute"), REQUIRED,
    "description", StringMeta("Desc of created attribute"), REQUIRED,
    "pv", StringMeta("Full pv of demand and default for rbv"), "",
    "rbv", StringMeta("Override for rbv"), "",
    "rbvSuff", StringMeta("Set rbv ro pv + rbv_suff"), "",
    "widget", ChoiceMeta("Widget type", [""] + widget_types), "",
    "inport", ChoiceMeta("Inport type", [""] + port_types), "",
    "config", BooleanMeta("Should this field be loaded/saved?"), False)
class CAPart(AttributePart):
    # Camonitor subscription
    monitor = None

    def __init__(self, process, params):
        self.cothread, self.catools = CothreadImporter.get_cothread(process)
        # Format for all caputs
        self.ca_format = self.catools.FORMAT_TIME
        super(CAPart, self).__init__(process, params)

    def store_params(self, params):
        if not params.rbv and not params.pv:
            raise ValueError('Must pass pv or rbv')
        if not params.rbv:
예제 #18
0
from malcolm.parts.ca.castringpart import CAStringPart
from malcolm.controllers.defaultcontroller import DefaultController
from malcolm.core import method_takes, REQUIRED
from malcolm.core.vmetas import StringMeta, ChoiceMeta
from malcolm.tags import port_types, outport, widget


@method_takes("name", StringMeta("Name of the created attribute"), REQUIRED,
              "description", StringMeta("Desc of created attribute"),
              REQUIRED, "rbv",
              StringMeta("Full pv of demand and default for rbv"), REQUIRED,
              "outport", ChoiceMeta("Outport type", port_types), REQUIRED)
class AsynOutportPart(CAStringPart):
    def __init__(self, process, params):
        self.outport_type = params.outport
        params = CAStringPart.MethodMeta.prepare_input_map(
            name=params.name, description=params.description, rbv=params.rbv)
        super(AsynOutportPart, self).__init__(process, params)

    def create_tags(self):
        tags = super(AsynOutportPart, self).create_tags()
        tags.append(widget("textupdate"))
        return tags

    @DefaultController.Reset
    def reset(self, task=None):
        super(AsynOutportPart, self).reset(task)
        # Add the outport tags
        tags = [t for t in self.attr.meta.tags if not t.startswith("outport:")]
        tags.append(outport(self.outport_type, self.attr.value))
예제 #19
0
 def create_meta(self, description, tags):
     return ChoiceMeta(description=description, tags=tags)