esrf

Beamline Instrument Software Support
SPEC Macro documentation: [ Macro Index | BCU Home ]

#%TITLE% spec_zenity.mac
#$Revision: 1.2 $%BR%
#%DESCRIPTION%
#Utility macros using a graphical interface.%BR%
#This program is a linux utility called zenity.%BR%
#%B%Note, %B%that it is difficult to determine, if the DISPLAY is going to work, due to
#session programs or DISPLAYs not set etc. So basically you need to trust that
#the display it ok and usable. If you use session, the window will open on the
#user`s screen!


#%UU%(path to start with)
#%MDESC%read a directory name using a graphical interface.
def zenity_getdirectory(offered, title) '{
    local cmd dir aux[]
    if (offered) {
        offered = "--filename=" offered
    }
    if (title) title = ": " title
    cmd = "zenity --title \"" SPEC " Spec session" title  "\" --file-selection --directory " offered "/" 
    unix(cmd, dir)
    split(dir, aux, "\n")
    dir = aux[0]
    return dir
}
'

#%UU%(text to display, background)
#%MDESC%display an information to be confirmed with a click using a graphical interface.
#Setting the second arg to 1 can be used to put zenity into the background, leaving spec to 
#continue the macro.
def zenity_info(text, background) '{
    local cmd
    cmd = "zenity --title \"" SPEC " Spec session\" --info --text=\"" text "\""
    if (background) cmd = cmd " &"
    unix(cmd)
}
'

#%UU%(text to display)
#%MDESC%display a warning to be confirmed with a click using a graphical interface.
#Setting the second arg to 1 can be used to put zenity into the background, leaving spec to 
#continue the macro.
def zenity_warning(text, background) '{
    local cmd
    cmd = "zenity --title \"" SPEC " Spec session\" --warning --text=\"" text "\""
    if (background) cmd = cmd " &"
    unix(cmd)
}
'

#%UU%(text to display)
#%MDESC%display an error text to be confirmed with a click using a graphical interface.
#Setting the second arg to 1 can be used to put zenity into the background, leaving spec to 
#continue the macro.
def zenity_error(text, background) '{
    local cmd
    cmd = "zenity --title \"" SPEC " Spec session\" --error --text=\"" text "\""
    if (background) cmd = cmd " &"
    unix(cmd)
}
'


#%UU%(text to display)
#%MDESC%display an erro text to be confirmed with a click using a graphical interface.
#
#Return 0 for yes and 1 for no.
def zenity_question(text) '{
    local cmd, answer
    cmd = "zenity --title \"" SPEC " Spec session\" --question --text=\"" text "\""
    answer = unix(cmd)
    return answer
}
'

#%UU%(initial, min, max, step)
#%MDESC%display an erro text to be confirmed with a click using a graphical interface.
#
#Returns a value between 0 and 100. Nothing for cancel. All values are integers.
def zenity_scale(initial, min, max, step) '{
    local cmd, answer
    cmd = "zenity --title \"" SPEC " Spec session\" --scale"
    if (int(initial)) cmd = cmd " --value=" int(initial)
    if (int(min)) cmd = cmd " --min-value=" int(min)
    if (int(max)) cmd = cmd " --max-value=" int(max)
    if (int(step)) cmd = cmd " --step=" int(step)
    unix(cmd, answer)
    return answer
}
'


#%UU%(offer text, text label)
#%MDESC%display an input window using a graphical interface.
#
#Return 0 for yes and 1 for no.
def zenity_entry(offer, text) '{
    local cmd, answer, retval
    cmd = "zenity --title \"" SPEC " Spec session\" --entry"
    if (offer) cmd = cmd " --entry-text=\"" offer "\""
    if (text) cmd = cmd " --text=\"" text "\""
    retval = unix(cmd, answer)
    if(retval) answer = offer # if user hit cancel
    # answer comes with a CR at end
    answer = removeEndingChar(answer, "\n")
    return answer
}
'



#%MACROS% 
#%IMACROS% 
#%AUTHOR%H. Witsch.
#%TOC%