Пример #1
0
 def create_tags(self):
     tags = []
     if self.params.widget:
         tags.append(widget(self.params.widget))
     if self.params.config:
         tags.append(config())
     return tags
Пример #2
0
 def create_attribute_models(self):
     for data in super(RunnableController, self).create_attribute_models():
         yield data
     # Create sometimes writeable attribute for the current completed scan
     # step
     completed_steps_meta = NumberMeta(
         "int32", "Readback of number of scan steps",
         tags=[widget("textinput")])
     completed_steps_meta.set_writeable_in(ss.PAUSED, ss.ARMED)
     self.completed_steps = completed_steps_meta.create_attribute_model(0)
     yield "completedSteps", self.completed_steps, self.set_completed_steps
     # Create read-only attribute for the number of configured scan steps
     configured_steps_meta = NumberMeta(
         "int32", "Number of steps currently configured",
         tags=[widget("textupdate")])
     self.configured_steps = configured_steps_meta.create_attribute_model(0)
     yield "configuredSteps", self.configured_steps, None
     # Create read-only attribute for the total number scan steps
     total_steps_meta = NumberMeta(
         "int32", "Readback of number of scan steps",
         tags=[widget("textupdate")])
     self.total_steps = total_steps_meta.create_attribute_model(0)
     yield "totalSteps", self.total_steps, None
     # Create sometimes writeable attribute for the default axis names
     axes_to_move_meta = StringArrayMeta(
         "Default axis names to scan for configure()",
         tags=[widget("table"), config()])
     axes_to_move_meta.set_writeable_in(ss.READY)
     self.axes_to_move = axes_to_move_meta.create_attribute_model(
         self.params.axesToMove)
     yield "axesToMove", self.axes_to_move, self.set_axes_to_move
Пример #3
0
    def update_part_exportable(self, response):
        # Get a child context to check if we have a config field
        child = self.child_controller.block_view()
        spawned = []
        if response.value:
            new_fields = response.value
        else:
            new_fields = []

        # Remove any existing subscription that is not in the new fields
        for subscribe in self.config_subscriptions.values():
            attr_name = subscribe.path[-2]
            if attr_name not in new_fields:
                unsubscribe = Unsubscribe(subscribe.id, subscribe.callback)
                spawned.append(
                    self.child_controller.handle_request(unsubscribe))
                self.port_infos.pop(attr_name, None)

        # Add a subscription to any new field
        existing_fields = set(s.path[-2]
                              for s in self.config_subscriptions.values())
        for field in set(new_fields) - existing_fields:
            attr = getattr(child, field)
            if isinstance(attr, Attribute):
                for tag in attr.meta.tags:
                    match = port_tag_re.match(tag)
                    if match:
                        d, type, extra = match.groups()
                        self.port_infos[field] = PortInfo(name=field,
                                                          value=attr.value,
                                                          direction=d,
                                                          type=type,
                                                          extra=extra)
            if isinstance(attr, Attribute) and config() in attr.meta.tags:
                if self.config_subscriptions:
                    new_id = max(self.config_subscriptions) + 1
                else:
                    new_id = 1
                subscribe = Subscribe(id=new_id,
                                      path=[self.params.mri, field, "value"],
                                      callback=self.update_part_modified)
                self.config_subscriptions[new_id] = subscribe
                # Signal that any change we get is a difference
                if field not in self.saved_structure:
                    self.saved_structure[field] = None
                spawned.append(self.child_controller.handle_request(subscribe))

        # Wait for the first update to come in
        for s in spawned:
            s.wait()

        # Put data on the queue, so if spawns are handled out of order we
        # still get the most up to date data
        port_infos = [
            self.port_infos[f] for f in new_fields if f in self.port_infos
        ]
        self.exportable_update_queue.put((new_fields, port_infos))
        self.spawn(self._update_part_exportable).wait()
Пример #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 _make_field_part(self,
                      field_name,
                      meta,
                      writeable,
                      initial_value=None):
     if writeable:
         meta.set_tags(meta.tags + (config(), ))
     part = PandABlocksFieldPart(self.client, meta, self.block_name,
                                 field_name, writeable, initial_value)
     self._add_part(field_name, part)
Пример #6
0
 def _make_table(self, field_name, field_data):
     group_tag = self._make_group("parameters")
     tags = [widget("table"), group_tag, config()]
     meta = TableMeta(field_data.description, tags)
     part = PandABlocksTablePart(self.client,
                                 meta,
                                 self.block_name,
                                 field_name,
                                 writeable=True)
     self._add_part(field_name, part)
Пример #7
0
 def create_tags(self):
     tags = []
     if self.params.widget:
         tags.append(widget(self.params.widget))
     if self.params.config and self.is_writeable():
         # If we have a writeable func we can be a config param
         tags.append(config())
     if self.params.group:
         # If we have a group then add the tag
         tags.append(group(self.params.group))
     return tags
Пример #8
0
 def create_attribute_models(self):
     for data in super(ExposureDetectorDriverPart,
                       self).create_attribute_models():
         yield data
     # Create writeable attribute for how long we should allow for detector
     # read out
     meta = NumberMeta("float64",
                       "Time taken to readout detector",
                       tags=[widget("textinput"),
                             config()])
     self.readout_time = meta.create_attribute_model(
         self.params.readoutTime)
     yield "readoutTime", self.readout_time, self.readout_time.set_value
Пример #9
0
 def create_attribute_models(self):
     for data in super(PmacTrajectoryPart, self).create_attribute_models():
         yield data
     # Create writeable attribute for the minimum time to leave when there
     # is a gap between frames
     meta = NumberMeta("float64",
                       "Min time for any gaps between frames",
                       tags=[widget("textinput"),
                             config()])
     self.min_turnaround = meta.create_attribute_model(
         self.params.minTurnaround)
     yield "minTurnaround", self.min_turnaround, \
           self.min_turnaround.set_value
Пример #10
0
 def create_attribute_models(self):
     for data in super(ManagerController, self).create_attribute_models():
         yield data
     assert os.path.isdir(self.params.configDir), \
         "%s is not a directory" % self.params.configDir
     if not os.path.isdir(os.path.join(self.params.configDir, ".git")):
         # Try and make it a git repo, don't care if it fails
         self._run_git_cmd("init")
         self._run_git_cmd("commit", "--allow-empty", "-m", "Created repo")
     # Create writeable attribute table for the layout info we need
     elements = OrderedDict()
     elements["name"] = StringArrayMeta("Name of layout part")
     elements["mri"] = StringArrayMeta("Malcolm full name of child block")
     elements["x"] = NumberArrayMeta(
         "float64", "X Coordinate of child block")
     elements["y"] = NumberArrayMeta(
         "float64", "Y Coordinate of child block")
     elements["visible"] = BooleanArrayMeta("Whether child block is visible")
     layout_table_meta = TableMeta(
         "Layout of child blocks", elements=elements,
         tags=[widget("flowgraph")])
     layout_table_meta.set_writeable_in(ss.READY)
     self.layout = layout_table_meta.create_attribute_model()
     yield "layout", self.layout, self.set_layout
     # Create writeable attribute for loading an existing layout
     design_meta = ChoiceMeta(
         "Design name to load", tags=[config(), widget("combo")])
     design_meta.set_writeable_in(ss.READY)
     self.design = design_meta.create_attribute_model()
     yield "design", self.design, self.set_design
     # Create writeable attribute table for the exported fields
     elements = OrderedDict()
     elements["name"] = ChoiceArrayMeta("Name of exported block.field")
     elements["exportName"] = StringArrayMeta(
         "Name of the field within current block")
     exports_table_meta = TableMeta(
         "Exported fields of child blocks", tags=[widget("table")],
         elements=elements)
     exports_table_meta.set_writeable_in(ss.READY)
     self.exports = exports_table_meta.create_attribute_model()
     yield "exports", self.exports, self.set_exports
     # Create read-only indicator for when things are modified
     modified_meta = BooleanMeta(
         "Whether the design is modified", tags=[widget("led")])
     self.modified = modified_meta.create_attribute_model()
     yield "modified", self.modified, None
Пример #11
0
 def create_attribute_models(self):
     # Create writeable attribute for current counter value
     meta = NumberMeta("float64", "A counter", tags=[config()])
     self.counter = meta.create_attribute_model()
     yield "counter", self.counter, self.counter.set_value