finalize gui to move "simulated motors"
This commit is contained in:
115
graphExample.py
115
graphExample.py
@@ -20,7 +20,7 @@ import geometry
|
||||
|
||||
import sys
|
||||
import logging
|
||||
#import CaChannel,time
|
||||
import epics
|
||||
|
||||
_log=logging.getLogger(__name__)
|
||||
|
||||
@@ -355,17 +355,8 @@ class RIXSgrating(QWidget):
|
||||
try:
|
||||
mot=self._vlsg_raw
|
||||
except AttributeError:
|
||||
mot={'mt': None,
|
||||
'gtz': 1089.7275273601558,
|
||||
'gty1': None,
|
||||
'gty2': None,
|
||||
'grx': 1.9320525786473723,
|
||||
'gtx': None,
|
||||
'dtz': 4355.976416183402,
|
||||
'dty1': 683.4429089462491,
|
||||
'dty2': 683.4429089462491,
|
||||
'drx': 41.4374216118389}
|
||||
|
||||
_log.error('no current energy set')
|
||||
return
|
||||
dlg=DlgMoveMotors()
|
||||
dlg.initUI('prefix',mot)
|
||||
#dlg.initUI('prefix',self._vlsg_raw)
|
||||
@@ -545,8 +536,8 @@ class DlgMoveMotors(QtGui.QDialog):
|
||||
super().__init__()
|
||||
#self.initUI()
|
||||
|
||||
def initUI(self,prefix,motDict):
|
||||
|
||||
def initUI(self,prefix,motDst):
|
||||
self._motDst=motDst
|
||||
self.setWindowTitle("Move Motors:")
|
||||
|
||||
#QBtn=QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.Cancel
|
||||
@@ -555,7 +546,8 @@ class DlgMoveMotors(QtGui.QDialog):
|
||||
#self.buttonBox.rejected.connect(self.reject)
|
||||
|
||||
self.buttonBox=QtGui.QDialogButtonBox()
|
||||
self.buttonBox.addButton('move all',QtGui.QDialogButtonBox.ActionRole)
|
||||
btn=self.buttonBox.addButton('move all',QtGui.QDialogButtonBox.ActionRole)
|
||||
btn.clicked.connect(self.OnMove)
|
||||
self.buttonBox.addButton('stop all',QtGui.QDialogButtonBox.ActionRole)
|
||||
|
||||
self.layout=QtGui.QVBoxLayout()
|
||||
@@ -564,19 +556,33 @@ class DlgMoveMotors(QtGui.QDialog):
|
||||
|
||||
self._wdGrpRaw=w=QtGui.QGroupBox("Motors", self)
|
||||
self.layout.addWidget(w)
|
||||
lg=QtGui.QGridLayout(w)
|
||||
self._layoutGrid=lg=QtGui.QGridLayout(w)
|
||||
|
||||
|
||||
for i,(k,v) in enumerate(motDict.items()):
|
||||
# dev=epics.Device('SATES30-RX:MOT_ABL.', attrs=('VAL', 'RBV', 'DESC'))
|
||||
app=QApplication.instance()
|
||||
devs=app._devs
|
||||
prefix='SATES30-RX:'
|
||||
for i,(k,v) in enumerate(motDst.items()):
|
||||
m='MOT_'+k.upper()
|
||||
w=QtGui.QCheckBox(m)
|
||||
#devs[k]=dev=epics.Device(prefix+m+'.', attrs=('RBV', 'DESC'), timeout=.5) # for safty: removed 'VAL',
|
||||
try:
|
||||
dev=devs[k]
|
||||
except KeyError:
|
||||
devs[k]=dev=SimDevice(prefix+m+'.', attrs=('VAL', 'RBV', 'DESC'))
|
||||
w=QtGui.QCheckBox(m,objectName=k)
|
||||
lg.addWidget(w, i, 0)
|
||||
if v is None:
|
||||
#v="<P><b><font color='#808080'>(null)</i></b></font>"
|
||||
v="<font color='#808080'>(null)</font>"
|
||||
|
||||
else:
|
||||
v=f'{v:.5g}<font color="#ff0000"> (-123)</font>'
|
||||
rbv=dev.RBV
|
||||
d=v-rbv
|
||||
if d>0:
|
||||
c='ff8080'
|
||||
else:
|
||||
c='60a060'
|
||||
v=f"{v:.5g} <font color='#808080'>(old:{rbv:.5g} <font color='#{c}'> {d:.5g})</font></font>"
|
||||
w.setChecked(True)
|
||||
w=QLabel(v)
|
||||
lg.addWidget(w, i, 1)
|
||||
@@ -584,6 +590,73 @@ class DlgMoveMotors(QtGui.QDialog):
|
||||
self.layout.addWidget(self.buttonBox)
|
||||
self.setLayout(self.layout)
|
||||
|
||||
def OnMove(self):
|
||||
app=QApplication.instance()
|
||||
devs=app._devs
|
||||
motDst=self._motDst
|
||||
lg=self._layoutGrid
|
||||
col=lg.columnCount()
|
||||
for i,(k,v) in enumerate(motDst.items()):
|
||||
cb=lg.itemAt(i*col).widget()
|
||||
if cb.isChecked():
|
||||
if v is not None:
|
||||
dev=devs[k]
|
||||
#print(dev)
|
||||
dev.VAL=v # move motor
|
||||
print(f'{cb.objectName()} {dev}')
|
||||
|
||||
|
||||
# ->>>> https://pyepics.github.io/pyepics/devices.html >>> USE THIS
|
||||
#[satesf-cons-03 ~]$ /opt/gfa/python-3.8/latest/bin/ipython3
|
||||
#import CaChannel
|
||||
#import epics
|
||||
|
||||
#capv=CaChannel.CaChannel('SATES30-RX:MOT_ABL.VAL') -> THIS IS REALLY BASIC...
|
||||
#capv.state()
|
||||
#m=epics.Motor('SATES30-RX:MOT_ABL')
|
||||
#pv=pvm.PV('RBV')
|
||||
#dev=epics.Device('SATES30-RX:MOT_ABL.', attrs=('VAL', 'RBV', 'DESC'))
|
||||
#dev.RBV
|
||||
class SimDevice():
|
||||
def __init__(self, prefix='', attrs=None,
|
||||
nonpvs=None, delim='', timeout=None,
|
||||
mutable=True, aliases=None, with_poll=True):
|
||||
self._prefix=prefix
|
||||
self._pvs={}
|
||||
for k in attrs:
|
||||
self._pvs[k]=0
|
||||
|
||||
def __getattr__(self, attr):
|
||||
#if self._pvs:
|
||||
if '_pvs' in self.__dict__:
|
||||
return self._pvs[attr]
|
||||
else:
|
||||
_log.debug(attr)
|
||||
raise AttributeError
|
||||
|
||||
def __setattr__(self, attr, val):
|
||||
if attr in ('_pvs','_prefix'):
|
||||
self.__dict__[attr]=val
|
||||
elif attr in self._pvs:
|
||||
self._pvs[attr]= val
|
||||
if attr=='VAL' and 'RBV' in self._pvs:
|
||||
self._pvs['RBV']=val
|
||||
else:
|
||||
self.__dict__[attr]=val
|
||||
|
||||
def __repr__(self):
|
||||
"string representation"
|
||||
attr=[]
|
||||
for k,v in self._pvs.items():
|
||||
attr.append(f'{k}: {v}')
|
||||
s=f"<Device: {self._prefix} ( "+', '.join(attr)+' )'
|
||||
return s
|
||||
|
||||
|
||||
# if attr in self._pvs:
|
||||
# return self.get(attr)
|
||||
# elif attr in self.__dict__:
|
||||
# return self.__dict__[attr]
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.basicConfig(level=logging.DEBUG, format='%(levelname)s:%(module)s:%(lineno)d:%(funcName)s:%(message)s ')
|
||||
@@ -592,6 +665,8 @@ if __name__ == '__main__':
|
||||
vlsg=geometry.VLSgrating()
|
||||
vlsg.setup('80meV')
|
||||
app._vlsg=vlsg
|
||||
app._devs=dict() # all device (grouped PVs)
|
||||
|
||||
#app._wndGirder= RIXSgirder()
|
||||
app._wndGrating=RIXSgrating()
|
||||
sys.exit(app.exec_())
|
||||
|
||||
Reference in New Issue
Block a user