Mixed classes

A file may contain several classes. This is demonstrated in the following code. If the code is edited, it can be reloaded by one of these commands:

Spock> relmac mixed1
Spock> relmac mixed2
Spock> relmac LoopOfScansMixed

Spock> relmaclib mixed_class

#!/usr/bin/env python
# 
# file name: /home/pXXuser/sardanaMacros/mixed_class.py 
# 
"""this module contains some macros"""

__all__ = ["mixed1", "mixed2", "LoopOfScansMixed"]

from sardana.macroserver.macro import *
from sardana.macroserver.macro import macro

class mixed1(Macro):
    """Mixed1"""
    def run(self):
        self.output( "This is mixed1")

class mixed2(Macro):
    """Mixed2"""
    def run(self):
        self.output( "This is mixed2")

class LoopOfScansMixed(Macro):
    """reads an environment variable and displays it"""
    param_def = [
        [ "mot1", Type.Moveable, None, "the inner loop motor" ],
        [ "mot2", Type.Moveable, None, "the outer loop motor" ],
        [ "delta", Type.Float, None, "a floating point number" ],
        [ "np", Type.Integer, None, "the no. of points" ],
        [ "comment", Type.String, None, "a comment line" ],
        ]
    def run(self, mot1, mot2, delta, np, comment):

        self.output( "Comment: %s " % comment)
        posOld = mot2.position

        for i in range(0, np):
            newPos = posOld + i*delta
            self.output( "%s is moving to %g" % (mot2.name, newPos))
            self.mv(mot2, newPos)
            self.output( "%s is at %g" % (mot2.name, mot2.position))
            self.ascan( mot1, 0, 0.1, 5, 0.1)
        self.mv( mot2, posOld)



2019-12-04