Exemplo n.º 1
0
def getPVs(widgets):
    map_pvs = []
    for row in range(len(widgets)):
        row_pvs = []
        for col in range(len(widgets[row])):
            pv = ScriptUtil.getPrimaryPV(widgets[row][col])
            if pv is None:
                raise Exception("No PV for row %d, col %d" % (row, col))
            row_pvs.append(pv)
        map_pvs.append(row_pvs)
    return map_pvs
def startSound():
    global audio
    if not 'audio' in globals()  or  audio is None:
        print("Play Sound")
        audio = ScriptUtil.playAudio(widget, "timer.mp3")
Exemplo n.º 3
0
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")

Exemplo n.º 4
0
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)
# 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)

"""
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],
Exemplo n.º 7
0
# 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)

Exemplo n.º 8
0
def startSound():
    global audio
    if not 'audio' in globals() or audio is None:
        print("Play Sound")
        audio = ScriptUtil.playAudio(widget, "timer.mp3")
Exemplo n.º 9
0
# This script is attached to a display
# and triggered by a PV like
#     loc://initial_trigger$(DID)(1)
# to execute once when the display is loaded.

# Read information for the various devices from somewhere, for example an XML file
import os
import xml.etree.ElementTree as ET
from org.csstudio.display.builder.runtime.script import ScriptUtil

# Locate XML file relative to the display file
display_file = ScriptUtil.workspacePathToSysPath(
    widget.getDisplayModel().getUserData("_input_file"))
directory = os.path.dirname(display_file)
file = directory + "/devices.xml"

# Parse XML
# Actual content of the XML file would of course depend
# on what's needed to describe one device.
# In here we treat each XML element of a device as a macro
xml = ET.parse(file).getroot()
devices = []
for device in xml.iter("device"):
    macros = dict()
    for el in device:
        macros[el.tag] = el.text
    devices.append(macros)

# For testing, it's tedious to add 200 device entries to the XML file.
# So ignore the XML content and just create 200 elements right here
devices = []
Exemplo n.º 10
0
"""
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)
Exemplo n.º 11
0
#   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)
Exemplo n.º 12
0
from org.csstudio.display.builder.runtime.script import ScriptUtil

ScriptUtil.getLogger().info("Initializing " + widget.getDisplayModel().getName())
Exemplo n.º 13
0
   Displays updates from running game,
   allows changing the cells.
   
   pvs[0] - dummy PV that once triggers the script.
            Script remains running!!
   pvs[1] - 0/1 PV to pause/run
   
   @author Kay Kasemir
"""
from org.csstudio.display.builder.runtime.script import ScriptUtil, PVUtil
from org.csstudio.display.builder.model import WidgetFactory
from org.csstudio.display.builder.model.properties import WidgetColor
from time import time, sleep
from life import GameOfLife

logger = ScriptUtil.getLogger()
display = widget.getDisplayModel()

SIZE = 19
GAP = 0


def createPiece(row, col, value):
    widget = WidgetFactory.getInstance().getWidgetDescriptor(
        "checkbox").createWidget()
    widget.setPropertyValue("x", col * (SIZE + GAP))
    widget.setPropertyValue("y", 75 + row * (SIZE + GAP))
    widget.setPropertyValue("width", SIZE)
    widget.setPropertyValue("height", SIZE)
    widget.setPropertyValue("label", "")
    widget.setPropertyValue("pv_name",
# This script is attached to a display
# and triggered by a PV like 
#     loc://initial_trigger$(DID)(1)
# to execute once when the display is loaded.

# Read information for the various devices from somewhere, for example an XML file
import os
import xml.etree.ElementTree as ET
from org.csstudio.display.builder.runtime.script import ScriptUtil

# Locate XML file relative to the display file
display_file = ScriptUtil.workspacePathToSysPath(widget.getDisplayModel().getUserData("_input_file"))
directory = os.path.dirname(display_file)
file = directory + "/devices.xml"

# Parse XML
# Actual content of the XML file would of course depend
# on what's needed to describe one device.
# In here we treat each XML element of a device as a macro
xml = ET.parse(file).getroot()
devices = []
for device in xml.iter("device"):
    macros = dict()
    for el in device:
        macros[el.tag] = el.text
    devices.append(macros)

# For testing, it's tedious to add 200 device entries to the XML file.
# So ignore the XML content and just create 200 elements right here
devices = []
for i in range(200):
Exemplo n.º 15
0
from org.csstudio.display.builder.runtime.script import ScriptUtil

ScriptUtil.getLogger().info("Initializing " +
                            widget.getDisplayModel().getName())