diff --git a/ModuleFixTarget.py b/ModuleFixTarget.py index 85d2f52..18999b0 100644 --- a/ModuleFixTarget.py +++ b/ModuleFixTarget.py @@ -16,7 +16,7 @@ This contains a Widget to handle FixTargetFrames and fiducials, calculate final import logging _log=logging.getLogger(__name__) -import json, base64 +import json, base64, yaml import numpy as np import pyqtUsrObj as UsrGO import pyqtgraph as pg @@ -161,6 +161,48 @@ class WndFixTarget(QWidget): act.triggered.connect(self.tree_ctx_delete) 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()", "Grid()", "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): path=[] it=self._tree.currentItem() @@ -213,6 +255,21 @@ class WndFixTarget(QWidget): r1.translate(r2.center()-r1.center()) 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): app = QApplication.instance() if filename is None: diff --git a/swissmx.py b/swissmx.py index b9b8db8..4c033e6 100755 --- a/swissmx.py +++ b/swissmx.py @@ -2139,41 +2139,7 @@ object settings: bm_pos=self._goBeamMarker.pos() bm_sz=self._goBeamMarker.size() idx=mft._cbType.currentIndex() - param=mft._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()", "Grid()", "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() + param=mft.get_param() if idx==0: #go=UsrGO.Fiducial(bm_pos+bm_sz/2-(20, 20), (40, 40),(fx,fy,bz)) 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']) dlg.setLabelText("Download motion program");dlg+=5 - sp.setup_motion(fnPrg=fn+'.prg', **kwargs) + try: + sp.setup_motion(fnPrg=fn+'.prg', **kwargs) + except BaseException as e: + _log.error(repr(e));return sp.setup_gather() try: p=geo._fitPlane