219 lines
4.6 KiB
Python
219 lines
4.6 KiB
Python
from PyQt4 import QtGui, QtCore
|
|
|
|
from tango import DevState
|
|
|
|
|
|
class cm:
|
|
FOFB_STATE = {
|
|
1: "#000000",
|
|
2: "#7CFC00",
|
|
4: "#FFFF00"
|
|
}
|
|
|
|
RED_BOOL = {
|
|
0: "#000000",
|
|
1: "#FF0000"
|
|
}
|
|
|
|
GREEN_BOOL = {
|
|
0: "#000000",
|
|
1: "#7CFC00"
|
|
}
|
|
|
|
SER_OFF = {
|
|
0: "#FF0000",
|
|
1: "#000000",
|
|
2: "#000000"
|
|
}
|
|
|
|
SER_MANUAL = {
|
|
0: "#000000",
|
|
1: "#000000",
|
|
2: "#FF8C00"
|
|
}
|
|
|
|
SER_FOFB = {
|
|
0: "#000000",
|
|
1: "#7CFC00",
|
|
2: "#000000"
|
|
}
|
|
|
|
|
|
class TangoLabel(QtGui.QLabel):
|
|
def __init__(self, parent=None):
|
|
QtGui.QLabel.__init__(self, parent)
|
|
|
|
self.device = None
|
|
self.attr = None
|
|
|
|
def setModel(self, device, attr):
|
|
self.window().addAttribute(device, attr)
|
|
self.device = device
|
|
self.attr = attr
|
|
# force the color of the tooltip text
|
|
if self.toolTip():
|
|
self.setToolTip("<font color=\"black\">%s<br><br>%s/%s</font>" % (self.toolTip(), device, attr))
|
|
else:
|
|
self.setToolTip("<font color=\"black\">%s/%s</font>" % (device, attr))
|
|
self.connect(self.window(), QtCore.SIGNAL("update"), self.update)
|
|
|
|
def update(self, cache):
|
|
value = cache[self.device][self.attr]
|
|
if value is None:
|
|
value = float("-inf")
|
|
try:
|
|
fmt = self.window().units[self.device][self.attr]["format"]
|
|
except (KeyError, TypeError):
|
|
fmt = "%d"
|
|
try:
|
|
unit = self.window().units[self.device][self.attr]["unit"]
|
|
except (KeyError, TypeError):
|
|
unit = None
|
|
value = fmt % value
|
|
if unit is not None:
|
|
value = "%s %s" % (value, unit)
|
|
self.setText(value)
|
|
|
|
|
|
class StateLabel(TangoLabel):
|
|
ColorMap = {
|
|
DevState.ON: "#7CFC00",
|
|
DevState.OFF: "#FFFFFF",
|
|
DevState.CLOSE: "#FFFFFF",
|
|
DevState.OPEN: "#7CFC00",
|
|
DevState.INSERT: "#FFFFFF",
|
|
DevState.EXTRACT: "#7CFC00",
|
|
DevState.MOVING: "#80A0FF",
|
|
DevState.STANDBY: "#FFFF00",
|
|
DevState.FAULT: "#FF0000",
|
|
DevState.INIT: "#CCCC7A",
|
|
DevState.RUNNING: "#80A0FF",
|
|
DevState.ALARM: "#FF8C00",
|
|
DevState.DISABLE: "#FF00FF",
|
|
DevState.UNKNOWN: "#808080"
|
|
}
|
|
|
|
def __init__(self, parent=None):
|
|
TangoLabel.__init__(self, parent)
|
|
|
|
def setModel(self, device, attr="State"):
|
|
TangoLabel.setModel(self, device, attr)
|
|
|
|
def update(self, cache):
|
|
state = cache[self.device][self.attr]
|
|
if state is None:
|
|
state = DevState.UNKNOWN
|
|
self.setStyleSheet("color: %s" % self.ColorMap[state])
|
|
|
|
|
|
class BeamLabel(TangoLabel):
|
|
def __init__(self, parent=None):
|
|
TangoLabel.__init__(self, parent)
|
|
|
|
def update(self, cache):
|
|
value = cache[self.device][self.attr]
|
|
if value > 0:
|
|
self.setStyleSheet("background-color: yellow")
|
|
else:
|
|
self.setStyleSheet("background-color: gray")
|
|
|
|
|
|
class OperationLabel(QtGui.QLabel):
|
|
ColorMap = {
|
|
"on": "#7CFC00",
|
|
"off": "#000000",
|
|
"manual": "#FFA500",
|
|
"skipped": "#ADD8E6",
|
|
"fault": "#FF0000"
|
|
}
|
|
|
|
def __init__(self, parent=None):
|
|
QtGui.QLabel.__init__(self, parent)
|
|
|
|
def setState(self, state):
|
|
self.setStyleSheet("color: %s" % self.ColorMap[state])
|
|
|
|
|
|
class BstLabel(TangoLabel):
|
|
ColorMap = {
|
|
"Status: OPEN": "#7CFC00",
|
|
"Status: UNKNOWN": "#80A0FF",
|
|
"STATUS: UNKNOWN": "#80A0FF",
|
|
"Status: CLOSED": "#FFFFFF",
|
|
None: "#808080"
|
|
}
|
|
|
|
def __init__(self, parent=None):
|
|
TangoLabel.__init__(self, parent)
|
|
|
|
def update(self, cache):
|
|
state = cache[self.device][self.attr]
|
|
self.setStyleSheet("color: %s" % self.ColorMap[state])
|
|
|
|
|
|
class BooleanLabel(TangoLabel):
|
|
def __init__(self, parent=None):
|
|
TangoLabel.__init__(self, parent)
|
|
|
|
self.true_color = "#7CFC00"
|
|
self.false_color = "#000000"
|
|
|
|
def setColors(self, true_color, false_color):
|
|
self.true_color = true_color
|
|
self.false_color = false_color
|
|
|
|
def update(self, cache):
|
|
if cache[self.device][self.attr]:
|
|
self.setStyleSheet("color: %s" % self.true_color)
|
|
else:
|
|
self.setStyleSheet("color: %s" % self.false_color)
|
|
|
|
|
|
class InterlockLabel(TangoLabel):
|
|
def __init__(self, parent=None):
|
|
TangoLabel.__init__(self, parent)
|
|
|
|
def update(self, cache):
|
|
if cache[self.device][self.attr]:
|
|
self.setStyleSheet("background:red; color:white")
|
|
else:
|
|
self.setStyleSheet("")
|
|
|
|
|
|
class ArrayElementLabel(TangoLabel):
|
|
ColorMap = {
|
|
0: "#000000",
|
|
1: "#7CFC00"
|
|
}
|
|
|
|
def __init__(self, parent=None):
|
|
TangoLabel.__init__(self, parent)
|
|
|
|
def setModel(self, device, attr, i):
|
|
self.i = i
|
|
TangoLabel.setModel(self, device, attr)
|
|
|
|
def setColorMap(self, cm):
|
|
self.ColorMap = cm
|
|
|
|
def update(self, cache):
|
|
value = cache[self.device][self.attr][self.i]
|
|
self.setStyleSheet("color: %s" % self.ColorMap[value])
|
|
|
|
|
|
class EnumStateLabel(TangoLabel):
|
|
ColorMap = {
|
|
0: "#000000",
|
|
1: "#7CFC00"
|
|
}
|
|
|
|
def __init__(self, parent=None):
|
|
TangoLabel.__init__(self, parent)
|
|
|
|
def setColorMap(self, cm):
|
|
self.ColorMap = cm
|
|
|
|
def update(self, cache):
|
|
value = cache[self.device][self.attr]
|
|
self.setStyleSheet("color: %s" % self.ColorMap[value])
|