Example #1
0
def makeNodeDataItem (node,viewer=None,viewopts={}):
  """creates a GridDataItem for a node""";
  udi = meqds.node_udi(node);
  nodeclass = meqds.NodeClass(node);
  vo = viewopts.copy();
  vo.update(defaultNodeViewopts);
  (name,caption) = meqds.make_udi_node_caption(node,None);
  # curry is used to create a call for refreshing its state
  return Grid.DataItem(udi,name=name,caption=caption,desc=name,
            datatype=nodeclass,
            refresh=curry(meqds.request_node_state,node.nodeindex),
            viewer=viewer,viewopts=vo);
Example #2
0
def makeNodeDataItem (node,viewer=None,viewopts={}):
  """creates a GridDataItem for a node""";
  udi = meqds.node_udi(node);
  nodeclass = meqds.NodeClass(node);
  vo = viewopts.copy();
  vo.update(defaultNodeViewopts);
  (name,caption) = meqds.make_udi_node_caption(node,None);
  # curry is used to create a call for refreshing its state
  return Grid.DataItem(udi,name=name,caption=caption,desc=name,
            datatype=nodeclass,
            refresh=curry(meqds.request_node_state,node.nodeindex),
            viewer=viewer,viewopts=vo);
Example #3
0
def makeDataItem(udi, data=None, viewer=None, publish=False, viewopts={}):
    """Creates a data item given a UDI"""
    # parse udi
    (cat, name, trailer) = meqds.parse_udi(udi)
    if cat == 'node':
        if not name:
            raise ValueError, "invalid UDI: " + udi
        # check name or node index
        nn = name.split('#', 1)
        if not nn[0]:
            name = int(nn[1])
            # use node index if no name given
        node = meqds.nodelist[name]
        # enable publishing but do not ask for a state update -- this will
        # be done by the item later
        if publish:
            meqds.enable_node_publish(node, True, get_state=False)
        if not trailer:
            return makeNodeDataItem(node, viewer, viewopts)
        else:
            (name, caption) = meqds.make_udi_node_caption(node, trailer)
            desc = "node %s#%d, state field %s" % (node.name, node.nodeindex,
                                                   trailer)
            return Grid.DataItem(udi,
                                 name=name,
                                 caption=caption,
                                 desc=desc,
                                 data=data,
                                 refresh=curry(meqds.request_node_state,
                                               node.nodeindex),
                                 viewer=viewer,
                                 viewopts=viewopts)
    elif cat == 'forest':
        if not trailer:
            return makeForestDataItem(data, viewer, viewopts)
        else:
            (name,
             caption) = meqds.make_parsed_udi_caption(cat, name, trailer)
            return Grid.DataItem(udi,
                                 name=name,
                                 caption=caption,
                                 desc="Forest state field " + trailer,
                                 data=data,
                                 refresh=meqds.request_forest_state,
                                 viewer=viewer,
                                 viewopts=viewopts)
    else:
        raise ValueError, "can't display " + udi
Example #4
0
def makeDataItem (udi,data=None,viewer=None,publish=False,viewopts={}):
  """Creates a data item given a UDI""";
  # parse udi
  (cat,name,trailer) = meqds.parse_udi(udi);
  if cat == 'node':
    if not name:
      raise ValueError,"invalid UDI: "+udi;
    # check name or node index
    nn = name.split('#',1);
    if not nn[0]:
      name = int(nn[1]);     # use node index if no name given
    node = meqds.nodelist[name];
    # enable publishing but do not ask for a state update -- this will
    # be done by the item later
    if publish:
      meqds.enable_node_publish(node,True,get_state=False);
    if not trailer:
      return makeNodeDataItem(node,viewer,viewopts);
    else:
      (name,caption) = meqds.make_udi_node_caption(node,trailer);
      desc = "node %s#%d, state field %s" % (node.name,node.nodeindex,trailer);
      return Grid.DataItem(udi,
                name=name,caption=caption,desc=desc,
                data=data,
                refresh=curry(meqds.request_node_state,node.nodeindex),
                              viewer=viewer,viewopts=viewopts);
  elif cat == 'forest':
    if not trailer:
      return makeForestDataItem(data,viewer,viewopts);
    else:
      (name,caption) = meqds.make_parsed_udi_caption(cat,name,trailer);
      return Grid.DataItem(udi,
         name=name,caption=caption,desc="Forest state field "+trailer,
         data=data,
         refresh=meqds.request_forest_state,
         viewer=viewer,viewopts=viewopts);
  else:
    raise ValueError,"can't display "+udi;