Interactive macros

Interactive macros can speak to the SardanaMacroExecutor like in the example below.

#!/usr/bin/env python

import HasyUtils
from sardana.macroserver.macro import macro, Macro, Type

class interactive_macro(Macro):
    """
    interactive macro class. communicates to the MacroExecutor, if it is alive.

    p09/door/haso107tk.01 [1]: %interactive_macro
    interactive_macro: {u'result': u'yes'}
    interactive_macro: {u'result': u'dev1'}

    """

    interactive = True

    def run(self):

        if HasyUtils.isMacroExecutorAlive():
            answer = HasyUtils.toMacroExecutor( { 'yesno': "Really start scan?"})
            self.output( "interactive_macro: %s" % repr( answer))
            answer = HasyUtils.toMacroExecutor( { 'getstring': "Enter device name"})
            self.output( "interactive_macro: %s" % repr( answer))
        else: 
            answer = self.input("Enter device name",data_type=Type.String)
            self.output("Device name is '%s'", answer)

        return

Figure 7.2: toMacroExecutor, yesno
Image yesnoME

Figure 7.3: toMacroExecutor, getstring
Image getstringME