from org.csstudio.opibuilder.scriptUtil import PVUtil


indices = [0, 1, 2]
positions = PVUtil.getStringArray(pvs[0])


def get_visible(index):
    """
    Args:
        index: The index of the set point

    Returns: True if a motion set point with this index exists, False otherwise.
    """
    if not positions:
        return False
    elif len(positions) <= index + 1:
        return False
    return True


def set_macros(widget, index):
    """
    Sets the proper index and name macros on the LED indicator widgets for a given motion setpoint.
    Args:
        widget: The target widget
        index: The index of the motion set point
    """
    macros = widget.getPropertyValue("macros")
    macros.put("INDEX", str(index))
    macros.put("POS", positions[index].strip())
Ejemplo n.º 2
0
#8 local_XTITLE
#9 $(P)_YTITLE
#10 local_YTITLE
#11 local TRACETYPE

init = widget.getPropertyValue("border_width")  #misuse this as an init flag

if init == 0:  #if not already initialised
    xmin = PVUtil.getDouble(pvArray[0])  #get all the PVs
    lxmin = PVUtil.getDouble(pvArray[1])
    xmax = PVUtil.getDouble(pvArray[2])
    lxmax = PVUtil.getDouble(pvArray[3])
    nbinsx = PVUtil.getLong(pvArray[4])
    lnbinsx = PVUtil.getLong(pvArray[5])
    nelm = PVUtil.getLong(pvArray[6])
    xt = PVUtil.getStringArray(pvArray[7])
    lxt = PVUtil.getString(pvArray[8])
    yt = PVUtil.getStringArray(pvArray[9])
    lyt = PVUtil.getString(pvArray[10])
    trace = PVUtil.getLong(pvArray[11])

    xt = list(map(int, xt))  #convert the waveforms into strings - ugly!
    xtstr = "".join([chr(c) for c in xt])
    yt = list(map(int, yt))
    ytstr = "".join([chr(c) for c in yt])

    #in all cases we let the local PVs (from MACROS) override those from the ioc,

    #for axes, if XMAX<XMIN it means the variables are not filled - do it anther way.

    if (lxmin < lxmax):  #test macro version first
    widget.setPropertyValue("opi_file", "param_move.opi")


def _add_macros(widget_index, name, value):
    """
    Add the macro with name to a motor widget with value. 
    Widgets are identified as "Motor_n" for n in [1,8] in the parent OPI
    Args:
        widget_index: index of the widget
        name: macro name
        value: macro value
    """
    motor_widget = display.getWidget("pos_" + str(widget_index))
    motor_macros = motor_widget.getPropertyValue("macros")
    motor_macros.put(name, value)
    motor_widget.setPropertyValue("macros", motor_macros)
    motor_widget.setPropertyValue("visible", True)

value = PVUtil.getStringArray(pvs[0])
value = "".join(chr(int(i)) for i in value[:-1])
value = zlib.decompress(value.decode("hex"))
params = json.loads(value)

pos = 1
for pv, name in params.items():
    _add_macros(pos, "PARAM_PV", pv)
    _add_macros(pos, "PARAM_NAME", name)
    pos += 1

reload_widgets(pos)