|
@@ -29,6 +29,12 @@ def caget(pv):
|
|
|
return -np.inf
|
|
|
|
|
|
class EpicsConfig(object):
|
|
|
+ """
|
|
|
+ need one instance at app startup
|
|
|
+ is done by kcgGUI via
|
|
|
+ from ..widgets import epics_widget
|
|
|
+ epics_widget.epicsConfig = epics_widget.EpicsConfig()
|
|
|
+ """
|
|
|
def __init__(self):
|
|
|
|
|
|
self.loadConfig(False)
|
|
@@ -103,16 +109,23 @@ class EpicsConfig(object):
|
|
|
return config.leval(self.parser['EPICS'][key])
|
|
|
|
|
|
def getPVList(self):
|
|
|
- return self.getKey(epics_log_entry_pvs)
|
|
|
+ return self.getKey('epics_log_entry_pvs')
|
|
|
|
|
|
def setPVList(self, pvList):
|
|
|
self.parser['EPICS']['epics_log_entry_pvs'] = self.generatePVKey(pvList)
|
|
|
|
|
|
- def addPV(self, name, pv, default):
|
|
|
+ def addPV(self, name, pv, default, monitor=False):
|
|
|
dat = self.getKey('epics_log_entry_pvs')
|
|
|
- dat.append((name,pv,default))
|
|
|
+ dat.append((name,pv,default,monitor))
|
|
|
self.parser['EPICS']['epics_log_entry_pvs'] = self.generatePVKey(dat)
|
|
|
|
|
|
+ def removePV(self, index):
|
|
|
+ n = int(index)
|
|
|
+ pvList = []
|
|
|
+ for i, item in enumerate(self.getPVList()):
|
|
|
+ if n != i: pvList.append((item[0], item[1], item[2], item[3]))
|
|
|
+ self.setPVList(pvList)
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -121,7 +134,7 @@ class EpicsConfig(object):
|
|
|
i=0
|
|
|
for item in pvList:
|
|
|
if i: out = out + ",\n"
|
|
|
- out = out + "('" + str(item[0]) + "', '" + str(item[1]) + "', '" + str(item[2]) + "')"
|
|
|
+ out = out + "('" + str(item[0]) + "', '" + str(item[1]) + "', '" + str(item[2]) + "', '" + str(item[3]) +"')"
|
|
|
i = i+1
|
|
|
|
|
|
out = out + "\n]"
|
|
@@ -155,78 +168,124 @@ class EpicsWidget(kcgw.KCGWidgets):
|
|
|
|
|
|
self.id = unique_id
|
|
|
self.par = parent
|
|
|
+ self.monitorPVList = {}
|
|
|
|
|
|
- self.layout = QtGui.QGridLayout()
|
|
|
+ self.layout = QtGui.QVBoxLayout() #.QGridLayout()
|
|
|
self.setLayout(self.layout)
|
|
|
- self.groupBox = QtGui.QGroupBox("Known PV List")
|
|
|
- self.groupBoxLayout = QtGui.QGridLayout()
|
|
|
- self.scrollArea = QtGui.QScrollArea()
|
|
|
+ self.editInnerGroupBox = QtGui.QGroupBox("")
|
|
|
+ self.editInnerGroupBoxLayout = QtGui.QGridLayout()
|
|
|
+ self.editScrollArea = QtGui.QScrollArea()
|
|
|
|
|
|
self.pvInputList = []
|
|
|
- self.groupBoxLayout.addWidget(self.createLabel("Name"), 0,0)
|
|
|
- self.groupBoxLayout.addWidget(self.createLabel("EPICS PV"), 0,1)
|
|
|
- self.groupBoxLayout.addWidget(self.createLabel("in Log"), 0,2)
|
|
|
- self.groupBoxLayout.addWidget(self.createLabel("Value"), 0,3)
|
|
|
- self.generateList()
|
|
|
+ self.editInnerGroupBoxLayout.addWidget(self.createLabel("Name"), 0,0)
|
|
|
+ self.editInnerGroupBoxLayout.addWidget(self.createLabel("EPICS PV"), 0,1)
|
|
|
+ self.editInnerGroupBoxLayout.addWidget(self.createLabel("in Log"), 0,2)
|
|
|
+ self.editInnerGroupBoxLayout.addWidget(self.createLabel("Monitoring"), 0,3)
|
|
|
+ self.editInnerGroupBoxLayout.addWidget(self.createLabel("Value"), 0,4)
|
|
|
+ self.generateList(False)
|
|
|
|
|
|
- self.groupBox.setLayout(self.groupBoxLayout)
|
|
|
- self.scrollArea.setWidget(self.groupBox)
|
|
|
- self.layout.addWidget(self.scrollArea,0,0,1,3)
|
|
|
-
|
|
|
-
|
|
|
+ self.editInnerGroupBox.setLayout(self.editInnerGroupBoxLayout)
|
|
|
+ self.editScrollArea.setWidget(self.editInnerGroupBox)
|
|
|
+ self.editOuterGroupBox = QtGui.QGroupBox("Epics PV List")
|
|
|
+ self.editOuterGroupBox.clicked.connect(self.toggleEdit)
|
|
|
+ self.editOuterGroupBoxLayout = QtGui.QGridLayout()
|
|
|
+ self.editOuterGroupBoxLayout.addWidget(self.editScrollArea,0,0,1,5)
|
|
|
|
|
|
self.readValues()
|
|
|
|
|
|
-
|
|
|
self.button1 = self.createButton("refresh values", connect=self.readValues)
|
|
|
- self.button2 = self.createButton("apply Changes", connect=self.apply, tooltip="save to configfile")
|
|
|
- self.button3 = self.createButton("restore Changes", connect=self.restore, tooltip="reload from configfile")
|
|
|
+ self.button2 = self.createButton("apply changes", connect=self.apply)
|
|
|
+ self.button3 = self.createButton("restore changes", connect=self.restore)
|
|
|
+ self.button4 = self.createButton("apply + save", connect=self.save)
|
|
|
+ self.button5 = self.createButton("load", connect=self.load)
|
|
|
+
|
|
|
+ self.editOuterGroupBoxLayout.addWidget(self.button1, 1,0)
|
|
|
+ self.editOuterGroupBoxLayout.addWidget(self.button2, 1,1)
|
|
|
+ self.editOuterGroupBoxLayout.addWidget(self.button3, 1,2)
|
|
|
+ self.editOuterGroupBoxLayout.addWidget(self.button4, 1,3)
|
|
|
+ self.editOuterGroupBoxLayout.addWidget(self.button5, 1,4)
|
|
|
+
|
|
|
+ self.editOuterGroupBox.setLayout(self.editOuterGroupBoxLayout)
|
|
|
+
|
|
|
+
|
|
|
+ self.monitorLabel = self.createLabel("Monitor\n")
|
|
|
+ self.layout.addWidget(self.monitorLabel)#,0,0)
|
|
|
+ self.layout.addWidget(self.createCheckbox("Open PV List", connect=self.toggleEdit))#, 1,0)
|
|
|
+ self.layout.addWidget(self.editOuterGroupBox)#,2,0)
|
|
|
|
|
|
- self.layout.addWidget(self.button1,1,0)
|
|
|
- self.layout.addWidget(self.button2,1,1)
|
|
|
- self.layout.addWidget(self.button3,1,2)
|
|
|
+ self.pvList = []
|
|
|
+ self.editHide = False
|
|
|
+ self.toggleEdit()
|
|
|
+
|
|
|
+ self.addMonitor()
|
|
|
|
|
|
+ # self.resize(self.monitorLabel.frameGeometry().width()+50, self.monitorLabel.frameGeometry().height()+10)
|
|
|
+ self.layout.addStretch(1)
|
|
|
self.setWindowTitle("Epics Widget")
|
|
|
|
|
|
|
|
|
- def generateList(self):
|
|
|
+
|
|
|
+ def generateList(self, updateMonitor=True):
|
|
|
+ if updateMonitor:
|
|
|
+ self.removeMonitor()
|
|
|
+
|
|
|
if len(self.pvInputList):
|
|
|
for item in self.pvInputList:
|
|
|
for q in item:
|
|
|
- self.groupBoxLayout.removeWidget(q)
|
|
|
+ self.editInnerGroupBoxLayout.removeWidget(q)
|
|
|
q.deleteLater()
|
|
|
self.pvInputList = []
|
|
|
for q in self.pvInputAdd:
|
|
|
- self.groupBoxLayout.removeWidget(q)
|
|
|
+ self.editInnerGroupBoxLayout.removeWidget(q)
|
|
|
q.deleteLater()
|
|
|
|
|
|
|
|
|
i = 0
|
|
|
for item in epicsConfig.getKey('epics_log_entry_pvs'): #config.epics_log_entry_pvs:
|
|
|
self.pvInputList.append([self.createInput(item[0]), self.createInput(item[1],width=300), self.createSwitch(item[2]=="True"),
|
|
|
- self.createLabel("value"),
|
|
|
+ self.createSwitch(item[3]=="True"), self.createLabel("value"),
|
|
|
self.createLabel(image=QtGui.QPixmap(config.icon_path('open-trash-can.png')), click=True, connect=partial(self.remove,i))
|
|
|
])
|
|
|
- self.groupBoxLayout.addWidget(self.pvInputList[i][0], i+1, 0)
|
|
|
- self.groupBoxLayout.addWidget(self.pvInputList[i][1], i+1, 1)
|
|
|
- self.groupBoxLayout.addWidget(self.pvInputList[i][2], i+1, 2)
|
|
|
- self.groupBoxLayout.addWidget(self.pvInputList[i][3], i+1, 3)
|
|
|
- self.groupBoxLayout.addWidget(self.pvInputList[i][4], i+1, 4)
|
|
|
+ self.editInnerGroupBoxLayout.addWidget(self.pvInputList[i][0], i+1, 0)
|
|
|
+ self.editInnerGroupBoxLayout.addWidget(self.pvInputList[i][1], i+1, 1)
|
|
|
+ self.editInnerGroupBoxLayout.addWidget(self.pvInputList[i][2], i+1, 2)
|
|
|
+ self.editInnerGroupBoxLayout.addWidget(self.pvInputList[i][3], i+1, 3)
|
|
|
+ self.editInnerGroupBoxLayout.addWidget(self.pvInputList[i][4], i+1, 4)
|
|
|
+ self.editInnerGroupBoxLayout.addWidget(self.pvInputList[i][5], i+1, 5)
|
|
|
i = i+1
|
|
|
|
|
|
- self.pvInputAdd = [self.createInput('name?'), self.createInput("?",width=300), self.createSwitch(item[2]=="True"),self.createButton("add",connect=self.add)]
|
|
|
- self.groupBoxLayout.addWidget(self.pvInputAdd[0], i+1, 0)
|
|
|
- self.groupBoxLayout.addWidget(self.pvInputAdd[1], i+1, 1)
|
|
|
- self.groupBoxLayout.addWidget(self.pvInputAdd[2], i+1, 2)
|
|
|
- self.groupBoxLayout.addWidget(self.pvInputAdd[3], i+1, 3)
|
|
|
+
|
|
|
+ self.pvInputAdd = [ self.createInput('name?'), self.createInput("?",width=300),
|
|
|
+ self.createSwitch(True), self.createSwitch(False),self.createButton("add",connect=self.add)]
|
|
|
+ self.editInnerGroupBoxLayout.addWidget(self.pvInputAdd[0], i+1, 0)
|
|
|
+ self.editInnerGroupBoxLayout.addWidget(self.pvInputAdd[1], i+1, 1)
|
|
|
+ self.editInnerGroupBoxLayout.addWidget(self.pvInputAdd[2], i+1, 2)
|
|
|
+ self.editInnerGroupBoxLayout.addWidget(self.pvInputAdd[3], i+1, 3)
|
|
|
+ self.editInnerGroupBoxLayout.addWidget(self.pvInputAdd[4], i+1, 4)
|
|
|
+
|
|
|
+ if updateMonitor:
|
|
|
+ self.addMonitor()
|
|
|
|
|
|
|
|
|
|
|
|
def closeEvent(self, event):
|
|
|
global __widget_id__
|
|
|
__widget_id__ = None
|
|
|
+ self.removeMonitor()
|
|
|
del self.par.widgets[self.id]
|
|
|
|
|
|
+ def toggleEdit(self):
|
|
|
+ if self.editHide:
|
|
|
+ # self.resize(800, 800)
|
|
|
+ self.editOuterGroupBox.show()
|
|
|
+ else:
|
|
|
+ # self.resize(self.monitorLabel.frameGeometry().width()+10, self.monitorLabel.frameGeometry().height()+50)
|
|
|
+ self.editOuterGroupBox.hide()
|
|
|
+
|
|
|
+ self.editHide = not self.editHide
|
|
|
+ #self.update()
|
|
|
+
|
|
|
+
|
|
|
def readValues(self):
|
|
|
for item in self.pvInputList:
|
|
|
try:
|
|
@@ -239,40 +298,80 @@ class EpicsWidget(kcgw.KCGWidgets):
|
|
|
except:
|
|
|
pass
|
|
|
|
|
|
- item[3].setText(val)
|
|
|
+ item[4].setText(val)
|
|
|
|
|
|
|
|
|
def add(self):
|
|
|
- epicsConfig.addPV(self.pvInputAdd[0].text(), self.pvInputAdd[1].text(), self.pvInputAdd[2].state)
|
|
|
+ epicsConfig.addPV(self.pvInputAdd[0].text(), self.pvInputAdd[1].text(), self.pvInputAdd[2].state, self.pvInputAdd[3].state)
|
|
|
self.generateList()
|
|
|
self.readValues()
|
|
|
|
|
|
def remove(self, n):
|
|
|
- n = int(n)
|
|
|
- #print("remove", n)
|
|
|
- pvList = []
|
|
|
- for i, item in enumerate(self.pvInputList):
|
|
|
- if n != i: pvList.append((item[0].text(), item[1].text(), item[2].state))
|
|
|
- epicsConfig.setPVList(pvList)
|
|
|
+ epicsConfig.removePV(n)
|
|
|
self.generateList()
|
|
|
self.readValues()
|
|
|
|
|
|
def restore(self):
|
|
|
+ self.generateList()
|
|
|
+ self.readValues()
|
|
|
+
|
|
|
+ def load(self):
|
|
|
epicsConfig.loadConfig()
|
|
|
self.generateList()
|
|
|
self.readValues()
|
|
|
|
|
|
+ def save(self):
|
|
|
+ self.apply()
|
|
|
+ epicsConfig.saveConfig()
|
|
|
+
|
|
|
def apply(self):
|
|
|
pvList = []
|
|
|
for item in self.pvInputList:
|
|
|
- pvList.append((item[0].text(), item[1].text(), item[2].state))
|
|
|
+ pvList.append((item[0].text(), item[1].text(), item[2].state, item[3].state))
|
|
|
epicsConfig.setPVList(pvList)
|
|
|
- epicsConfig.saveConfig()
|
|
|
self.generateList()
|
|
|
self.readValues()
|
|
|
|
|
|
|
|
|
|
|
|
+ def monitorPV(self, pvname=None, value=None, char_value=None, **kw):
|
|
|
+ self.monitorPVList[str(pvname)] = [str(pvname), char_value]
|
|
|
+ self.updateMonitor()
|
|
|
+
|
|
|
+ def updateMonitor(self):
|
|
|
+ string = "Monitor\n"
|
|
|
+ for item in self.monitorPVList:
|
|
|
+ string += str(self.monitorPVList[item][0]) + " = " + str(self.monitorPVList[item][1]) + "\n"
|
|
|
+ self.monitorLabel.setText(string)
|
|
|
+
|
|
|
+ def addMonitor(self):
|
|
|
+ if len(self.pvList):
|
|
|
+ self.removeMonitor()
|
|
|
+ for item in epicsConfig.getKey('epics_log_entry_pvs'):
|
|
|
+ if item[3] == 'True':
|
|
|
+ try:
|
|
|
+ if epics.caget(item[1]) != None:
|
|
|
+ self.pvList.append(item[1])
|
|
|
+ epics.camonitor(item[1], callback=self.monitorPV)
|
|
|
+ self.monitorPV(item[1], char_value=epics.caget(item[1]))
|
|
|
+ except:
|
|
|
+ print('add Failed', item[1])
|
|
|
+ pass
|
|
|
+
|
|
|
+ def removeMonitor(self):
|
|
|
+ for item in self.pvList:
|
|
|
+ try:
|
|
|
+ epics.camonitor_clear(item)
|
|
|
+ except:
|
|
|
+ print('remove Failed', item)
|
|
|
+ pass
|
|
|
+
|
|
|
+ self.pvList = []
|
|
|
+ self.monitorPVList = {}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|