try to cleanup stuff(2)

This commit is contained in:
2024-11-27 11:30:06 +01:00
parent 24b7f1292d
commit cc7d7c8e79
2 changed files with 63 additions and 37 deletions

View File

@@ -16,7 +16,7 @@ This contains a Widget to handle FixTargetFrames and fiducials, calculate final
import logging import logging
_log=logging.getLogger(__name__) _log=logging.getLogger(__name__)
import json, base64 import json, base64, yaml
import numpy as np import numpy as np
import pyqtUsrObj as UsrGO import pyqtUsrObj as UsrGO
import pyqtgraph as pg import pyqtgraph as pg
@@ -161,6 +161,48 @@ class WndFixTarget(QWidget):
act.triggered.connect(self.tree_ctx_delete) act.triggered.connect(self.tree_ctx_delete)
tree.addAction(act) tree.addAction(act)
act = QAction("update param", self)
act.triggered.connect(self.tree_ctx_update)
tree.addAction(act)
def get_param(self):
param=self._txtParam.text().replace('(','[').replace(')',']').strip()
if param=='' or param[0]!='{':
param='{'+param+'}'
#mft._cbType.addItems(["Fiducial", "FixTarget(12.5x12.5)", "FixTarget(23.0x23.0)", "FixTarget(<param>)", "Grid(<param>)", "SwissMX-path"])
#bm_pos_eu=self._goBeamMarker._pos_eu
#bm_size_eu=self._goBeamMarker._size_eu
try:
#parse the parameters: 'key:value [,key:value]'
# as key value separator : and = are allowed
#examples:
#Fiducial:
# no param
#FixTarget(12.5x12.5), FixTarget(23.0x23.0), FixTarget(test):
# code_gen:2
# code_gen=3 | tmove=10 | twait=30
#Grid():
# size:(30, 20)
# cnt:(30, 22)
# fiducialSize:0.1
#SwissMX():
# ofs:(.2, .2)
# width:10
# fidScl:.02
# fiducial:((.1, .1), (.1, 2.7), (10.3, .1), (10.3, 2.7))
#SwissFEL():
# ofs:(.2, .2)
# width:10
# fidScl:.02
# fiducial:((.1, .1), (.1, 2.2), (10.3, .1), (10.3, 2.2))
param=param.replace(':', ': ') # allow gen:4 without space
param=yaml.safe_load(param) # "ofs":[10, 5],"width":200,"fidScl":0.5,"fiducial":[[18,7],[25,16],[70, 20]]
except BaseException as e:
_log.error(f'{e}:{param}')
param=dict()
return param
def tree_get_path(self): def tree_get_path(self):
path=[] path=[]
it=self._tree.currentItem() it=self._tree.currentItem()
@@ -213,6 +255,21 @@ class WndFixTarget(QWidget):
r1.translate(r2.center()-r1.center()) r1.translate(r2.center()-r1.center())
vb.setRange(r1) vb.setRange(r1)
def tree_ctx_update(self):
app=QApplication.instance()
path=self.tree_get_path()
if len(path)==1:
try:
wnd=app._mainWnd
except AttributeError:
_log.info('_mainWnd not handeled')
else:
grp=wnd._goTracked
go=grp.childItems()[path[0]]
go._param=self.get_param()
data=grp.childItems()
self._tree.setData(data)
def load_file(self, filename=None): def load_file(self, filename=None):
app = QApplication.instance() app = QApplication.instance()
if filename is None: if filename is None:

View File

@@ -2139,41 +2139,7 @@ object settings:
bm_pos=self._goBeamMarker.pos() bm_pos=self._goBeamMarker.pos()
bm_sz=self._goBeamMarker.size() bm_sz=self._goBeamMarker.size()
idx=mft._cbType.currentIndex() idx=mft._cbType.currentIndex()
param=mft._txtParam.text().replace('(','[').replace(')',']').strip() param=mft.get_param()
if param=='' or param[0]!='{':
param='{'+param+'}'
#mft._cbType.addItems(["Fiducial", "FixTarget(12.5x12.5)", "FixTarget(23.0x23.0)", "FixTarget(<param>)", "Grid(<param>)", "SwissMX-path"])
#bm_pos_eu=self._goBeamMarker._pos_eu
#bm_size_eu=self._goBeamMarker._size_eu
try:
#parse the parameters: 'key:value [,key:value]'
# as key value separator : and = are allowed
#examples:
#Fiducial:
# no param
#FixTarget(12.5x12.5), FixTarget(23.0x23.0), FixTarget(test):
# code_gen:2
# code_gen=3 | tmove=10 | twait=30
#Grid():
# size:(30, 20)
# cnt:(30, 22)
# fiducialSize:0.1
#SwissMX():
# ofs:(.2, .2)
# width:10
# fidScl:.02
# fiducial:((.1, .1), (.1, 2.7), (10.3, .1), (10.3, 2.7))
#SwissFEL():
# ofs:(.2, .2)
# width:10
# fidScl:.02
# fiducial:((.1, .1), (.1, 2.2), (10.3, .1), (10.3, 2.2))
param=param.replace(':', ': ') # allow gen:4 without space
param=yaml.safe_load(param) # "ofs":[10, 5],"width":200,"fidScl":0.5,"fiducial":[[18,7],[25,16],[70, 20]]
except BaseException as e:
_log.error(f'{e}:{param}')
param=dict()
if idx==0: if idx==0:
#go=UsrGO.Fiducial(bm_pos+bm_sz/2-(20, 20), (40, 40),(fx,fy,bz)) #go=UsrGO.Fiducial(bm_pos+bm_sz/2-(20, 20), (40, 40),(fx,fy,bz))
l=.120 l=.120
@@ -2355,7 +2321,10 @@ object settings:
sp.setup_sync(verbose=sp.verbose&0x40, timeOfs=dt_misc['time_ofs'], timeCor=dt_misc['time_cor']) sp.setup_sync(verbose=sp.verbose&0x40, timeOfs=dt_misc['time_ofs'], timeCor=dt_misc['time_cor'])
dlg.setLabelText("Download motion program");dlg+=5 dlg.setLabelText("Download motion program");dlg+=5
try:
sp.setup_motion(fnPrg=fn+'.prg', **kwargs) sp.setup_motion(fnPrg=fn+'.prg', **kwargs)
except BaseException as e:
_log.error(repr(e));return
sp.setup_gather() sp.setup_gather()
try: try:
p=geo._fitPlane p=geo._fitPlane