def clearConflictsDisplay(): if PVUtil.getDouble(pvs[1]) != 0: return for row in range(9): for col in range(9): cell = getWidget(row, col) pv = pvs[calcPVIndex(row, col)] if PVUtil.getString(pv) == "#": pv.write(" ") cell.setPropertyValue("foreground_color", text)
def findConflicts(row, col, value): conflicts = [] if value == " " or value == "_": return conflicts for currCol in range(9): if currCol != col and \ value == PVUtil.getString(pvs[calcPVIndex(row,currCol)]): conflicts.append((row, currCol)) for currRow in range(9): if currRow != row and \ value == PVUtil.getString(pvs[calcPVIndex(currRow,col)]): conflicts.append((currRow, col)) for currRow in calcBlockRange(row): for currCol in calcBlockRange(col): if currRow != row and \ currCol != col and \ value == PVUtil.getString(pvs[calcPVIndex(currRow,currCol)]): conflicts.append((currRow, currCol)) if len(conflicts) > 0: conflicts.append((row, col)) return conflicts
from org.csstudio.display.builder.runtime.script import PVUtil, ScriptUtil secs = PVUtil.getDouble(pvs[0]) max_time = PVUtil.getDouble(pvs[1]) sound = PVUtil.getInt(pvs[2]) > 0 def startSound(): global audio if not 'audio' in globals() or audio is None: print("Play Sound") audio = ScriptUtil.playAudio(widget, "timer.mp3") def stopSound(): global audio if 'audio' in globals() and audio is not None: print("End Sound") audio.cancel(True) audio = None fraction = secs/max_time widget.setPropertyValue("total_angle", 360.0*fraction) if fraction < 0.25: color = [ 255, 0, 0 ] play = True elif fraction < 0.4: color = [ 255, 255, 0 ] play = False else: color = [ 0, 255, 0 ] play = False
from org.csstudio.display.builder.runtime.script import PVUtil, ScriptUtil from java.util.concurrent import TimeUnit from java.lang import Throwable max_duration = 5 play = PVUtil.getInt(pvs[0]) if play: widget.setPropertyValue("text", "Playing audio..") # Start playing audio audio = ScriptUtil.playAudio(widget, "timer.wav") try: # Could wait until end of playback with # audio.get() # In this example, using a timeout to limit the playback audio.get(max_duration, TimeUnit.SECONDS) # Without timeout, we're done widget.setPropertyValue("text", "Done") except Throwable, ex: # In case of timeout, we cancel the player print(str(ex)) widget.setPropertyValue("text", "Cancelling") audio.cancel(True) # else: Called with play=0, so don't do anything print("Script done")
from org.csstudio.display.builder.runtime.script import ScriptUtil, PVUtil doit = PVUtil.getInt(pvs[0]) if doit: print "Loading other display.." ScriptUtil.openDisplay(widget, "other.bob", "REPLACE", None) pvs[0].write(0)
from org.csstudio.display.builder.runtime.script import PVUtil, ScriptUtil # Which trace parm is this for? #trace_parm = "trace_0_visible" trace_parm = PVUtil.getString(pvs[1]) # Locate graph widget in the display based on name graph_widget = widget.getDisplayModel().runtimeChildren().getChildByName( "time-history") if PVUtil.getLong(pvs[0]) == 1: state = True else: state = False graph_widget.setPropertyValue(trace_parm, state)
# pvs[0]: initial trigger # pvs[1]: Re-fetch? # import sys # print("Search path:\n" + "\n".join(sys.path)) from org.csstudio.display.builder.runtime.script import PVUtil if PVUtil.getInt(pvs[1]): message = "Re-fetching logbook entries" else: message = "Fetching Logbook entries..." widget.setValue([["-", message]]) from my_service import read_html, create_table html = read_html() widget.setValue(create_table(html))
""" 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],
""" Input: pvs[0] - Value around -5 .. 5 """ from org.csstudio.display.builder.runtime.script import PVUtil value = PVUtil.getDouble(pvs[0]); if value >= 0: widget.setPropertyValue("text", "Positive") else: widget.setPropertyValue("text", "Negative")
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) pv.write(value)
def showInfo(text): w = display.runtimeChildren().getChildByName("info") w.setPropertyValue("text", str(text)) t3 = display.getUserData("T3") if t3 is None: # Initialize new board t3 = T3() display.setUserData("T3", t3) showBoard(t3) else: # User entered a move pos = int(PVUtil.getString(pvs[0])) if not (0 <= pos < 9): showInfo("Field must be 0 .. 8") elif t3.board[pos] != ' ': showInfo("Field %d already occupied!" % pos) else: # Perform user's move t3.board[pos] = 'x' showBoard(t3) # Compute computer's move test = T3(t3.board) pos = test.makeMove('o') if pos is not None: showInfo("I set " + str(pos)) t3.board[pos] = 'o'
from org.csstudio.display.builder.runtime.script import PVUtil, ScriptUtil sizex = PVUtil.getLong(pvs[1]) sizey = PVUtil.getLong(pvs[2]) max_widget_height = 337 max_widget_width = 450 aspect_ratio = 1.0 * sizex / sizey if aspect_ratio > 1 and (max_widget_width / aspect_ratio <= max_widget_height): widget.setPropertyValue("height", max_widget_width / aspect_ratio) widget.setPropertyValue("width", max_widget_width) elif aspect_ratio > 1 and (max_widget_width / aspect_ratio > max_widget_height): widget.setPropertyValue("height", max_widget_height) widget.setPropertyValue("width", max_widget_height * aspect_ratio) elif aspect_ratio < 1: widget.setPropertyValue("width", max_widget_height * aspect_ratio) widget.setPropertyValue("height", max_widget_height) else: widget.setPropertyValue("height", max_widget_height) widget.setPropertyValue("width", max_widget_height)
from org.csstudio.display.builder.runtime.script import PVUtil import time run = PVUtil.getInt(pvs[0]) max_time = PVUtil.getString(pvs[1]) indicator = pvs[2] def format(secs): """Format seconds as 'MM:SS' """ sec = int(secs) min = sec / 60 sec -= min * 60 return "%02d:%02d" % (min, sec) if run: # Expecting "MM:SS" as runtime total = float(max_time[0:2]) * 60 + float(max_time[3:5]) end = time.time() + total now = time.time() while run and now < end: secs = end - now fraction = secs / total widget.setPropertyValue("total_angle", 360.0 * fraction) if fraction < 0.25: color = [255, 0, 0] elif fraction < 0.4: color = [255, 255, 0] else:
# Script that receives a n image widget's "Cursor Info PV" # # Value is a VTable with columns X, Y, Value, one row of data from org.csstudio.display.builder.runtime.script import PVUtil try: x = PVUtil.getTableCell(pvs[0], 0, 0) xt = "left" if x < 50 else "right" y = PVUtil.getTableCell(pvs[0], 0, 1) yt = "top" if y > 40 else "bottom" v = PVUtil.getTableCell(pvs[0], 0, 2) text = "X: %.1f (%s) Y: %.1f (%s) Value: %.1f" % (x, xt, y, yt, v) except: text = "" widget.setPropertyValue("text", text)
def readMap(map, map_pvs): for row in range(len(map)): for col in range(len(map[row])): map[row][col] = PVUtil.getInt(map_pvs[row][col])
""" Input: pvs[0] - PV name to use """ from org.csstudio.display.builder.runtime.script import PVUtil value = PVUtil.getString(pvs[0]); # print "update_pv_name.py: Name is %s" % value widget.setPropertyValue("pv_name", value)
""" Input: pvs[0] - Value around -5 .. 5 pvs[1] - Default value for X pvs[2] - Scaling factor """ from org.csstudio.display.builder.runtime.script import PVUtil value = PVUtil.getDouble(pvs[0]) x0 = PVUtil.getDouble(pvs[1]) scale = PVUtil.getDouble(pvs[2]) widget.setPropertyValue("x", x0 + scale * value)
from org.csstudio.display.builder.runtime.script import PVUtil import time run = PVUtil.getInt(pvs[0]) max_time = PVUtil.getString(pvs[1]) indicator = pvs[2] def format(secs): """Format seconds as 'MM:SS' """ sec = int(secs) min = sec / 60 sec -= min*60 return "%02d:%02d" % (min, sec) if run: # Expecting "MM:SS" as runtime total = float(max_time[0:2])*60 + float(max_time[3:5]) end = time.time() + total now = time.time() while run and now < end: secs = end - now fraction = secs/total widget.setPropertyValue("total_angle", 360.0*fraction) if fraction < 0.25: color = [ 255, 0, 0 ] elif fraction < 0.4: color = [ 255, 255, 0 ] else: color = [ 0, 255, 0 ] widget.setPropertyValue("background_color", color)
# 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)
# 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]).upper() colormap = None # Initial Display Builder used ColorMap.PREDEFINED .. for m in PredefinedColorMaps.PREDEFINED: if mapname == m.getName(): colormap = m break if colormap is None: ScriptUtil.getLogger().warning("Unknown color map " + mapname) else: widget.setPropertyValue("color_map", colormap)
# 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)
# For Phoebus, disable widgets that have not been implemented # pvs[0] - widget type to check from org.csstudio.display.builder.runtime.script import ScriptUtil, PVUtil if 'PHOEBUS' in dir(ScriptUtil): from org.csstudio.display.builder.representation.javafx.widgets import BaseWidgetRepresentations type = PVUtil.getString(pvs[0]) supported = False for t in BaseWidgetRepresentations().getWidgetRepresentationFactories(): if t.getType() == type: supported = True break if not supported: print("Disable " + type) widget.setPropertyValue("visible", False)
from org.csstudio.display.builder.runtime.script import PVUtil from org.csstudio.display.builder.model.properties import WidgetColor pid_out = PVUtil.getDouble(pvs[0]) sine = PVUtil.getDouble(pvs[1]) if pid_out > 600: text = "Giving it all ..." color = WidgetColor(255, 0, 255) # PINK elif pid_out > 400: text = "Heating a lot ..." color = WidgetColor(180, 50, 255) # PURPLE elif pid_out > 200: text = "Heating some ..." color = WidgetColor(255, 50, 50) # RED elif pid_out > 100: text = "Warming up ..." color = WidgetColor(255, 155, 50) # ORANGE elif pid_out > 0: text = "Keeping warm ..." color = WidgetColor(255, 255, 50) # YELLOW elif pid_out < 0: text = "Cooling down ..." color = WidgetColor(200, 200, 255) # LIGHT_BLUE else: text = "Temperature is just right" color = WidgetColor(0, 255, 0) # GREEN widget.setPropertyValue("text", text) widget.setPropertyValue("background_color", color) widget.setPropertyValue("x", 440 + sine)
from org.csstudio.display.builder.runtime.script import PVUtil, ScriptUtil sizex = PVUtil.getLong(pvs[1]) sizey = PVUtil.getLong(pvs[2]) minx = PVUtil.getLong(pvs[3]) miny = PVUtil.getLong(pvs[4]) widget.setPropertyValue("x_axis.maximum", sizex + minx) widget.setPropertyValue("x_axis.minimum", minx) widget.setPropertyValue("data_width", sizex) widget.setPropertyValue("y_axis.maximum", miny) widget.setPropertyValue("y_axis.minimum", sizey + miny) widget.setPropertyValue("data_height", sizey)
from org.csstudio.display.builder.runtime.script import PVUtil, ConsoleUtil cameras = PVUtil.getStringArray(pvs[0]) timeout = 2000 if PVUtil.getString(pvs[1]) == "Fine": pvToWrite = ":SET_ROI_VIEW.PROC" else: pvToWrite = ":SET_FULL_CHIP.PROC" [PVUtil.writePV(cam + pvToWrite, 1, timeout) for cam in cameras]
# Script executed by jython # Can import any Java package from org.csstudio.display.builder.runtime.script import PVUtil # Can also import some python code that's available under Jython import sys, time trigger = PVUtil.getInt(pvs[0]) if trigger: info = "%s,\ninvoked at %s" % (sys.version, time.strftime("%Y-%m-%d %H:%M:%S")) widget.setPropertyValue("text", info)
from org.csstudio.display.builder.runtime.script import PVUtil qualities = PVUtil.getStructureElement(pvs[0], "Quality") average = 0 for rating in qualities: average += rating average /= len(qualities) widget.setPropertyValue("text", str(average))
# Script that receives a n image widget's "Cursor Info PV" # # Value is a VTable with columns X, Y, Value, one row of data from org.csstudio.display.builder.runtime.script import PVUtil try: x = PVUtil.getTableCell(pvs[0], 0, 0) y = PVUtil.getTableCell(pvs[0], 0, 1) v = PVUtil.getTableCell(pvs[0], 0, 2) text = "X: %d, Y: %d, Val: %d" % (x, y, v) except: text = "" widget.setPropertyValue("text", text)
from org.csstudio.display.builder.runtime.script import PVUtil, ScriptUtil secs = PVUtil.getDouble(pvs[0]) max_time = PVUtil.getDouble(pvs[1]) sound = PVUtil.getInt(pvs[2]) > 0 def startSound(): global audio if not 'audio' in globals() or audio is None: print("Play Sound") audio = ScriptUtil.playAudio(widget, "timer.mp3") def stopSound(): global audio if 'audio' in globals() and audio is not None: print("End Sound") audio.cancel(True) audio = None fraction = secs / max_time widget.setPropertyValue("total_angle", 360.0 * fraction) if fraction < 0.25: color = [255, 0, 0] play = True elif fraction < 0.4: color = [255, 255, 0] play = False
def clearConflictsDisplay(): if PVUtil.getDouble(pvs[1]) != 0: return for row in range(9): for col in range(9): cell = getWidget(row, col) pv = pvs[calcPVIndex(row, col)] if PVUtil.getString(pv) == "#": pv.write(" ") cell.setPropertyValue("foreground_color", text) #logger.warning("finished clearing conflicts") selected = int(widget.getPropertyValue("name")[4:]) value = PVUtil.getString(pvs[0]) #logger.warning("*Entry for %d" % selected) if value != "#" and PVUtil.getDouble(pvs[1]) != -1: col = selected % 10 row = (selected - col) / 10 if value != " ": clearConflictsDisplay() conflicts = findConflicts(row, col, value) if value == "_": pvs[0].write(" ") elif len(conflicts) > 0: pvs[0].write("#") #logger.warning("conflicted (%d,%d)" % (row, col)) for pos in conflicts: cell = getWidget(pos[0], pos[1]) cell.setPropertyValue(