From 2a881b6032c22c25a570bc69a99e3510e3ae12aa Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Fri, 26 Mar 2021 11:09:20 +0100 Subject: [PATCH 1/4] add MoveMacro class --- src/sardana/macroserver/macro.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sardana/macroserver/macro.py b/src/sardana/macroserver/macro.py index d0a32f6d58..0b7317221b 100644 --- a/src/sardana/macroserver/macro.py +++ b/src/sardana/macroserver/macro.py @@ -32,6 +32,7 @@ __all__ = ["OverloadPrint", "PauseEvent", "Hookable", "ExecMacroHook", "MacroFinder", "Macro", "macro", "iMacro", "imacro", + "MoveMacro", "movemacro", "MacroFunc", "Type", "Table", "List", "ViewOption", "LibraryError", "Optional", "StopException", "AbortException", "InterruptException"] @@ -2525,3 +2526,7 @@ def __init__(self, *args, **kwargs): def run(self, *args): return self._function(self, *args) + + +class MoveMacro(Macro, Hookable): + pass From 879efc889e075b3b7a6bcbf65c8fca2b1fda0a11 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Fri, 26 Mar 2021 11:14:35 +0100 Subject: [PATCH 2/4] mv, umv, mvr, umvr, br, ubr inherit from MoveMacro --- src/sardana/macroserver/macros/hkl.py | 6 +++--- src/sardana/macroserver/macros/standard.py | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/sardana/macroserver/macros/hkl.py b/src/sardana/macroserver/macros/hkl.py index 45e24b0ecb..3799ebf3bc 100644 --- a/src/sardana/macroserver/macros/hkl.py +++ b/src/sardana/macroserver/macros/hkl.py @@ -48,7 +48,7 @@ import numpy as np from sardana.sardanautils import py2_round -from sardana.macroserver.macro import Hookable, Macro, iMacro, Type +from sardana.macroserver.macro import Hookable, Macro, iMacro, Type, MoveMacro from sardana.macroserver.macros.scan import aNscan from sardana.macroserver.msexception import UnknownEnv @@ -196,7 +196,7 @@ def fl(self, ch, if mat: return regx.sub(repl, ch) -class br(Macro, _diffrac, Hookable): +class br(MoveMacro, _diffrac): """Move the diffractometer to the reciprocal space coordinates given by H, K and L. If a fourth parameter is given, the combination of angles to be set is @@ -274,7 +274,7 @@ def run(self, H, K, L, AnglesIndex, FlagNotBlocking, FlagPrinting): hkl_values[l_idx], self.diffrac.WaveLength]) -class ubr(Macro, _diffrac, Hookable): +class ubr(MoveMacro, _diffrac): """Move the diffractometer to the reciprocal space coordinates given by H, K and L und update. """ diff --git a/src/sardana/macroserver/macros/standard.py b/src/sardana/macroserver/macros/standard.py index cc1e4f7bc7..623d66d557 100755 --- a/src/sardana/macroserver/macros/standard.py +++ b/src/sardana/macroserver/macros/standard.py @@ -41,7 +41,7 @@ from PyTango import DevState from sardana.macroserver.macro import Macro, macro, Type, ViewOption, \ - iMacro, Hookable + iMacro, Hookable, MoveMacro from sardana.macroserver.msexception import StopException, UnknownEnv from sardana.macroserver.scan.scandata import Record from sardana.macroserver.macro import Optional @@ -460,7 +460,7 @@ def run(self, motor_list): self.execMacro('wm', motor_list, **Table.PrettyOpts) -class mv(Macro, Hookable): +class mv(MoveMacro): """Move motor(s) to the specified position(s)""" hints = {'allowsHooks': ('pre-move', 'post-move')} @@ -511,7 +511,7 @@ def run(self, motor): self.info("Motor %s" % str(motor.stateObj.read().rvalue)) -class umv(Macro, Hookable): +class umv(MoveMacro): """Move motor(s) to the specified position(s) and update""" hints = {'allowsHooks': ('pre-move', 'post-move')} @@ -564,7 +564,7 @@ def printAllPos(self): self.flushOutput() -class mvr(Macro, Hookable): +class mvr(MoveMacro): """Move motor(s) relative to the current position(s)""" hints = {'allowsHooks': ('pre-move', 'post-move')} @@ -591,7 +591,7 @@ def run(self, motor_disp_list): self.runMacro(mv) -class umvr(Macro, Hookable): +class umvr(MoveMacro): """Move motor(s) relative to the current position(s) and update""" hints = {'allowsHooks': ('pre-move', 'post-move')} From e9d89b5023d4f53d23e4c9e77be34277b62e50ff Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Fri, 26 Mar 2021 12:02:19 +0100 Subject: [PATCH 3/4] move hint to MoveMacro class --- src/sardana/macroserver/macro.py | 8 +++++- src/sardana/macroserver/macros/hkl.py | 2 -- src/sardana/macroserver/macros/standard.py | 29 ++++++++-------------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/sardana/macroserver/macro.py b/src/sardana/macroserver/macro.py index 0b7317221b..d96c4b611a 100644 --- a/src/sardana/macroserver/macro.py +++ b/src/sardana/macroserver/macro.py @@ -66,6 +66,7 @@ from sardana.macroserver.msoptions import ViewOption from sardana.taurus.core.tango.sardana.pool import PoolElement +from sardana import sardanacustomsettings class OverloadPrint(object): @@ -2529,4 +2530,9 @@ def run(self, *args): class MoveMacro(Macro, Hookable): - pass + + hints = {'allowsHooks': ('pre-move', 'post-move')} + + enable_hooks = getattr(sardanacustomsettings, + 'PRE_POST_MOVE_HOOK_IN_MV', + True) diff --git a/src/sardana/macroserver/macros/hkl.py b/src/sardana/macroserver/macros/hkl.py index 3799ebf3bc..08e6ca2c01 100644 --- a/src/sardana/macroserver/macros/hkl.py +++ b/src/sardana/macroserver/macros/hkl.py @@ -203,7 +203,6 @@ class br(MoveMacro, _diffrac): the correspondig to the given index. The index of the angles combinations are then changed.""" - hints = {'allowsHooks': ('pre-move', 'post-move')} param_def = [ ['H', Type.String, None, "H value"], ['K', Type.String, None, "K value"], @@ -278,7 +277,6 @@ class ubr(MoveMacro, _diffrac): """Move the diffractometer to the reciprocal space coordinates given by H, K and L und update. """ - hints = {'allowsHooks': ('pre-move', 'post-move')} param_def = [ ["hh", Type.String, "Not set", "H position"], ["kk", Type.String, "Not set", "K position"], diff --git a/src/sardana/macroserver/macros/standard.py b/src/sardana/macroserver/macros/standard.py index 623d66d557..fa2db061eb 100755 --- a/src/sardana/macroserver/macros/standard.py +++ b/src/sardana/macroserver/macros/standard.py @@ -45,7 +45,6 @@ from sardana.macroserver.msexception import StopException, UnknownEnv from sardana.macroserver.scan.scandata import Record from sardana.macroserver.macro import Optional -from sardana import sardanacustomsettings ########################################################################## # @@ -463,7 +462,6 @@ def run(self, motor_list): class mv(MoveMacro): """Move motor(s) to the specified position(s)""" - hints = {'allowsHooks': ('pre-move', 'post-move')} param_def = [ ['motor_pos_list', [['motor', Type.Moveable, None, 'Motor to move'], @@ -471,25 +469,22 @@ class mv(MoveMacro): None, 'List of motor/position pairs'], ] - def run(self, motor_pos_list): - self.motors, positions = [], [] + def prepare(self, motor_pos_list): + self.motors, self.positions = [], [] for m, p in motor_pos_list: self.motors.append(m) - positions.append(p) - - enable_hooks = getattr(sardanacustomsettings, - 'PRE_POST_MOVE_HOOK_IN_MV', - True) + self.positions.append(p) - if enable_hooks: + def run(self, motor_pos_list): + if self.enable_hooks: for preMoveHook in self.getHooks('pre-move'): preMoveHook() - for m, p in zip(self.motors, positions): + for m, p in zip(self.motors, self.positions): self.debug("Starting %s movement to %s", m.getName(), p) motion = self.getMotion(self.motors) - state, pos = motion.move(positions) + state, pos = motion.move(self.positions) if state != DevState.ON: self.warning("Motion ended in %s", state.name) msg = [] @@ -497,7 +492,7 @@ def run(self, motor_pos_list): msg.append(motor.information()) self.info("\n".join(msg)) - if enable_hooks: + if self.enable_hooks: for postMoveHook in self.getHooks('post-move'): postMoveHook() @@ -514,17 +509,16 @@ def run(self, motor): class umv(MoveMacro): """Move motor(s) to the specified position(s) and update""" - hints = {'allowsHooks': ('pre-move', 'post-move')} param_def = mv.param_def def prepare(self, motor_pos_list, **opts): self.all_names = [] self.all_pos = [] - self.motors = [] + # self.motors = [] self.print_pos = False for motor, pos in motor_pos_list: self.all_names.append([motor.getName()]) - self.motors.append(motor) + #self.motors.append(motor) pos, posObj = motor.getPosition(force=True), motor.getPositionObj() self.all_pos.append([pos]) posObj.subscribeEvent(self.positionChanged, motor) @@ -535,6 +529,7 @@ def run(self, motor_pos_list): mv, _ = self.createMacro('mv', motor_pos_list) mv._setHooks(self.hooks) self.runMacro(mv) + self.motors = mv.motors finally: self.finish() @@ -567,7 +562,6 @@ def printAllPos(self): class mvr(MoveMacro): """Move motor(s) relative to the current position(s)""" - hints = {'allowsHooks': ('pre-move', 'post-move')} param_def = [ ['motor_disp_list', [['motor', Type.Moveable, None, 'Motor to move'], @@ -594,7 +588,6 @@ def run(self, motor_disp_list): class umvr(MoveMacro): """Move motor(s) relative to the current position(s) and update""" - hints = {'allowsHooks': ('pre-move', 'post-move')} param_def = mvr.param_def def run(self, motor_disp_list): From c2716a677406b2750bf494470998ceae1beb7cb5 Mon Sep 17 00:00:00 2001 From: Daniel Schick Date: Fri, 26 Mar 2021 12:05:47 +0100 Subject: [PATCH 4/4] comment self.motors declaration --- src/sardana/macroserver/macros/standard.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sardana/macroserver/macros/standard.py b/src/sardana/macroserver/macros/standard.py index fa2db061eb..6ec8321a1b 100755 --- a/src/sardana/macroserver/macros/standard.py +++ b/src/sardana/macroserver/macros/standard.py @@ -518,7 +518,7 @@ def prepare(self, motor_pos_list, **opts): self.print_pos = False for motor, pos in motor_pos_list: self.all_names.append([motor.getName()]) - #self.motors.append(motor) + #self.motors.append(motor) # here? pos, posObj = motor.getPosition(force=True), motor.getPositionObj() self.all_pos.append([pos]) posObj.subscribeEvent(self.positionChanged, motor) @@ -527,9 +527,9 @@ def run(self, motor_pos_list): self.print_pos = True try: mv, _ = self.createMacro('mv', motor_pos_list) + self.motors = mv.motors # or here? mv._setHooks(self.hooks) self.runMacro(mv) - self.motors = mv.motors finally: self.finish()