""" Sudoku board creator. @author Amanda Carpenter """ from org.csstudio.display.builder.runtime.script import PVUtil, ScriptUtil logger = ScriptUtil.getLogger() logger.info("Loading sudoku.py") pvVal = int(PVUtil.getDouble(pvs[0])) if pvVal == -1: board = [ [0, 1, 2, 0, 4, 5, 6, 7, 8], [1, 2, 3, 0, 5, 6, 7, 8, 0], [2, 3, 4, 0, 6, 7, 8, 0, 1], [3, 4, 5, 0, 7, 8, 0, 1, 2], [4, 5, 6, 0, 8, 0, 1, 2, 3], [5, 6, 7, 0, 0, 1, 2, 3, 4], [6, 7, 8, 0, 1, 2, 3, 4, 5], [7, 8, 0, 0, 2, 3, 4, 5, 6], [8, 0, 1, 0, 3, 4, 5, 6, 7], ] elif pvVal == 3: board = [ [0, 2, 0, 0, 0, 4, 3, 0, 0], [9, 0, 0, 0, 2, 0, 0, 0, 8], [0, 0, 0, 6, 0, 9, 0, 5, 0],
# only the package name differs. # # from org.csstudio.opibuilder.scriptUtil import PVUtil # # needs to change into # # from org.csstudio.display.builder.runtime.script import PVUtil # # This specific package name is actually patched by the # display builder, so this script, attached to a Label, # will simply 'run', issuing a warning that the package # name has been patched: # # from org.csstudio.opibuilder.scriptUtil import PVUtil # widget.setPropertyValue("text", "Hello") # To write a portable script, check for the display builder's widget type: display_builder = 'getVersion' in dir(widget) if display_builder: from org.csstudio.display.builder.runtime.script import PVUtil, ScriptUtil ScriptUtil.getLogger().info("Executing in display builder") else: from org.csstudio.opibuilder.scriptUtil import PVUtil, ConsoleUtil ConsoleUtil.writeInfo("Executing in BOY") # This API is now the same: val = PVUtil.getDouble(pvs[0]) widget.setPropertyValue("text", "Value is %.3f" % val)
# Set color map from org.csstudio.display.builder.runtime.script import PVUtil, ScriptUtil from org.csstudio.display.builder.model.properties import PredefinedColorMaps mapname = PVUtil.getString(pvs[0]) colormap = None # Initial Display Builder used ColorMap.PREDEFINED .. for map in PredefinedColorMaps.PREDEFINED: if mapname == map.getName(): colormap = map break if colormap is None: ScriptUtil.getLogger().warning("Unknown color map " + mapname) else: widget.setPropertyValue("color_map", colormap)
""" Writes the value in the widget named 'pv_value' to the PV named in the widget called 'pv_name' """ from org.csstudio.display.builder.runtime.script import PVUtil, ScriptUtil logger = ScriptUtil.getLogger() # Locate other widgets in the display based on their name children = widget.getDisplayModel().runtimeChildren() name_widget = children.getChildByName("pv_name") value_widget = children.getChildByName("pv_value") # Get the current value of those widgets logger.info("Name widget " + str(name_widget)) logger.info("Value widget " + str(value_widget)) name_pv = ScriptUtil.getPrimaryPV(name_widget) value_pv = ScriptUtil.getPrimaryPV(value_widget) name = PVUtil.getString(name_pv) value = PVUtil.getString(value_pv) logger.info("Need to set " + name + " = " + value) # Locate one of the target widgets based on their name target_widget_name = name.replace("loc://", "") target_widget = children.getChildByName(target_widget_name) logger.info("Widget named " + target_widget_name + ": " + str(target_widget)) # Write to the PV of the target widget pv = ScriptUtil.getPrimaryPV(target_widget)
# from org.csstudio.display.builder.runtime.script import PVUtil # # This specific package name is actually patched by the # display builder, so this script, attached to a Label, # will simply 'run', issuing a warning that the package # name has been patched: # # from org.csstudio.opibuilder.scriptUtil import PVUtil # widget.setPropertyValue("text", "Hello") # To write a portable script, check for the display builder's widget type: display_builder = 'getVersion' in dir(widget) if display_builder: from org.csstudio.display.builder.runtime.script import PVUtil, ScriptUtil ScriptUtil.getLogger().info("Executing in display builder") # For the display builder, might further check if running in RCP or Phoebus phoebus = 'PHOEBUS' in dir(ScriptUtil) if phoebus: ScriptUtil.getLogger().info(".. on Phoebus") else: ScriptUtil.getLogger().info(".. on Eclipse/RCP") else: from org.csstudio.opibuilder.scriptUtil import PVUtil, ConsoleUtil ConsoleUtil.writeInfo("Executing in BOY") # This API is now the same: val = PVUtil.getDouble(pvs[0]) widget.setPropertyValue("text", "Value is %.3f" % val)
from org.csstudio.display.builder.runtime.script import ScriptUtil ScriptUtil.getLogger().info("Initializing " + widget.getDisplayModel().getName())