add app_utils for motion_assert, contextMenu og GraphItem, further fixes

This commit is contained in:
2022-09-21 11:06:10 +02:00
parent 158150a954
commit 1393269ceb
11 changed files with 177 additions and 144 deletions

View File

@@ -5,10 +5,10 @@
# | Based on Zac great first implementation |
# | Author Thierry Zamofing (thierry.zamofing@psi.ch) |
# *-----------------------------------------------------------------------*
'''
"""
SwissMx experiment application.
Based on Zac great first implementation
bitmask for simulation:
0x01: backlight
@@ -18,7 +18,7 @@ bitmask for simulation:
0x10: Deltatau motors
0x20: SmarAct motors
'''
"""
import logging
logging.basicConfig(level=logging.DEBUG, format='%(levelname)s:%(module)s:%(lineno)d:%(funcName)s:%(message)s ')
@@ -439,9 +439,6 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
self.shortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_S), self)
self.shortcut.activated.connect(self.cb_save_cam_image)
self.shortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_T), self)
self.shortcut.activated.connect(lambda: qutilities.toggle_warn(SKIP_ESCAPE_TRANSITIONS_IF_SAFE))
for k in range(10):
qkey = k + Qt.Key_0
self.shortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.SHIFT + qkey), self)
@@ -632,11 +629,12 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
_log.debug('TODO: check to not connect smultiple igNewCamImg')
if index > 0: # not showing camera image
_log.warning("listening to zescape")
self.timer.stop()
zescape.start_listening()
self.timer = QtCore.QTimer(self)
self.timer.timeout.connect(self.check_zescape)
self.timer.start(20)
pass
#self.timer.stop()
#zescape.start_listening()
#self.timer = QtCore.QTimer(self)
#self.timer.timeout.connect(self.check_zescape)
#self.timer.start(20)
else:
app=QApplication.instance()
try:
@@ -1461,15 +1459,16 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
vb.removeItem(go)
tmpGoLst.clear()
n=int(p.shape[0]/100)+1
for i in range(0,p.shape[0],n):
fx,fy=p[i, :]/1000
fx=-fx #X axis has inverted sign !
l=.06
go=UsrGO.Fiducial((fx-l/2, fy-l/2), (l, l), i)
grp.addItem(go)
tmpGoLst.append(go)
mft._tree.setData(grp.childItems())
# adding debug fiducials
#n=int(p.shape[0]/100)+1
#for i in range(0,p.shape[0],n):
# fx,fy=p[i, :]/1000
# fx=-fx #X axis has inverted sign !
# l=.06
# go=UsrGO.Fiducial((fx-l/2, fy-l/2), (l, l), i)
# grp.addItem(go)
# tmpGoLst.append(go)
#mft._tree.setData(grp.childItems())
#_log.debug(f'first point:{p[0,:]}')
#_log.debug(f'step to 2nd point:{p[1,:]-p[0,:]}')
@@ -1541,7 +1540,7 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
app=QApplication.instance()
steps = [
# lambda: sample_selection.tell.set_current(30.0),
lambda: self.move_collimator("ready"),
lambda: self.move_collimator("out"),
lambda:self.move_detector("out"),
lambda:self.move_post_tube("out"),
lambda:app._backlight.move("in"),
@@ -2080,14 +2079,20 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
j=0
elif type(go)==UsrGO.Fiducial and go.size()[0]==0.12:
ptFitTrf[j]=go.pos()+go.size()/2
if j<ptFitTrf.shape[0]:
ptFitTrf[j]=go.pos()+go.size()/2
j+=1
ptFitPlane[i]=go.ctr()
i+=1;j+=1
i+=1
app=QApplication.instance()
geo=app._geometry
if n>=3:
geo.least_square_plane(ptFitPlane)
def cb_progress(self,i,sz,dlg):
dlg.setValue(int(sz*90/i))
if dlg.wasCanceled():
raise AttributeError('canceled')
def daq_collect(self, **kwargs):# points, visualizer_method, visualizer_params):
#def _OLD_daq_collect_points(self, points, visualizer_method, visualizer_params):
@@ -2134,14 +2139,21 @@ Author Thierry Zamofing (thierry.zamofing@psi.ch)
sp.setup_coord_trf() # reset to shape path system
# sp.meta['pt2pt_time']=10 #put between setup_sync and setup_motion to have more motion points than FEL syncs
dlg.setLabelText("Download motion program");dlg+=5
try:
sp.comm.gpascii._cb_func=lambda i, sz:self.cb_progress(i, sz, dlg)
except AttributeError:
pass
sp.setup_motion(fnPrg=fn+'.prg', mode=3, scale=1., dwell=10)
dlg.setLabelText("Homing and get ready");dlg+=35
if dlg.wasCanceled():
return
dlg.setLabelText("Homing and get ready");dlg+=5
sp.homing() # homing if needed
sp.run() # start motion program
sp.wait_armed() # wait until motors are at first position
sp.trigger(0.5) # send a start trigger (if needed) after given time
#PV with the current pulse
# [sf-lc7a ~]$ caget
jf.acquire('filename.tmp',sp.points.shape[0])
if not dt._comm is None:
dlg.setLabelText("run motion/acquisition")
@@ -3906,10 +3918,13 @@ if __name__=="__main__":
app._geometry._opt_ctr=cfg.value(cfg.GEO_OPT_CTR)
startupWin.set(15, f'connect backlight')
pfx=app._cfg.value(AppCfg.GBL_DEV_PREFIX)[0]
dft_pos_bklgt=app._cfg.value(AppCfg.DFT_POS_BKLGT)
if args.sim&0x01:
app._backlight = backlight.Backlight(None)
app._backlight = backlight.Backlight(None,dft_pos_bklgt)
else:
app._backlight = backlight.Backlight()
app._backlight = backlight.Backlight(f'{pfx}:MOT_BLGT',dft_pos_bklgt)
startupWin.set(20, f'connect illumination')
if args.sim&0x02:
app._illumination = illumination.IlluminationControl(None)