[2] | 1 | ;------------------------------------------------------------ |
---|
| 2 | ;------------------------------------------------------------ |
---|
| 3 | ;------------------------------------------------------------ |
---|
| 4 | ;+ |
---|
| 5 | ; |
---|
[133] | 6 | ; @file_comments |
---|
| 7 | ; Like dialog_message.pro if there is already some widget |
---|
| 8 | ; active or like message.pro if there is not any widget active. |
---|
| 9 | ; To ask a question whose answer is not yes/no,use xquestion. |
---|
[2] | 10 | ; |
---|
[136] | 11 | ; @param text {in}{required} |
---|
| 12 | ; one string or one vector of string. Si le string ne |
---|
[2] | 13 | ; comporte qu''un element, on cherche les eventuels characteres de |
---|
| 14 | ; retour a la ligne: '!C'. If text is set to an array of strings, each |
---|
| 15 | ; array element is displayed as a separate line of text. |
---|
| 16 | ; |
---|
[136] | 17 | ; @keyword SIMPLE |
---|
| 18 | ; activate to print only the message without the name |
---|
| 19 | ; and the line of the routine (defined by calling routine_name) |
---|
[11] | 20 | ; |
---|
[136] | 21 | ; @keyword _extra |
---|
| 22 | ; used to pass keywords from dialog_message.pro and message.pro |
---|
[2] | 23 | ; |
---|
[136] | 24 | ; @keyword PARENT |
---|
| 25 | ; same as DIALOG_PARENT de dialog_message.pro |
---|
[2] | 26 | ; |
---|
[136] | 27 | ; @keyword QUESTION {default="Warning"} |
---|
| 28 | ; Set this keyword to create a "Question" dialog. |
---|
[2] | 29 | ; |
---|
[136] | 30 | ; @keyword DEFAULT_NO {default="Yes"} |
---|
| 31 | ; Set this keyword to make the "No" button the default selection for |
---|
| 32 | ; "Question" dialog. |
---|
[2] | 33 | ; |
---|
[136] | 34 | ; @keyword SIMPLE |
---|
| 35 | ; Activate to print the error message without printing the routine name with |
---|
| 36 | ; its full path. |
---|
[2] | 37 | ; |
---|
[136] | 38 | ; @returns |
---|
| 39 | ; -1 if the keyword QUESTION is not activated |
---|
| 40 | ; If the keyword is activated, return 1 for yes and 0 for no. |
---|
[2] | 41 | ; |
---|
[136] | 42 | ; @examples |
---|
| 43 | ; If there is not any widget activated: |
---|
[2] | 44 | ; |
---|
[136] | 45 | ; IDL> help, report('toto tata') |
---|
| 46 | ; % $MAIN$: toto tata |
---|
| 47 | ; <Expression> INT = -1 |
---|
| 48 | ; IDL> help, report('does it works ?',/question) |
---|
| 49 | ; does it works ? y/n (default answer is y) |
---|
| 50 | ; <Expression> BYTE = 1 |
---|
| 51 | ; IDL> help, report('question1: !C does it works ?',/question) |
---|
| 52 | ; question1: |
---|
| 53 | ; does it works ? y/n (default answer is y) |
---|
| 54 | ; <Expression> BYTE = 1 |
---|
[2] | 55 | ; |
---|
[133] | 56 | ; If widgets are already activated, it is the same thing but with widgets! |
---|
[2] | 57 | ; |
---|
[136] | 58 | ; @history Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[2] | 59 | ; 21/10/1999 |
---|
[133] | 60 | ; |
---|
[136] | 61 | ; @version $Id$ |
---|
[133] | 62 | ; |
---|
[2] | 63 | ;- |
---|
| 64 | ;------------------------------------------------------------ |
---|
| 65 | ;------------------------------------------------------------ |
---|
| 66 | ;------------------------------------------------------------ |
---|
[11] | 67 | FUNCTION report, text, DEFAULT_NO = default_no, PARENT = parent, QUESTION = question, SIMPLE = simple, _extra = ex |
---|
[114] | 68 | ; |
---|
| 69 | compile_opt idl2, strictarrsubs |
---|
| 70 | ; |
---|
[133] | 71 | res = -1 ; |
---|
| 72 | ; we separate the text in different lines (separated by !C) if it is not already done... |
---|
[2] | 73 | if n_elements(text) EQ 1 then text = str_sep(text, '!C', /trim) |
---|
[133] | 74 | ; there is some widgets activated, it is easy, we call dialog_massage |
---|
[2] | 75 | if (widget_info(/managed))[0] NE 0 then BEGIN |
---|
| 76 | res = dialog_message(text, dialog_parent = parent, QUESTION = question $ |
---|
| 77 | , title = routine_name(1), DEFAULT_NO = default_no, _extra = ex) |
---|
| 78 | if keyword_set(question) THEN res = res EQ 'Yes' ELSE res = -1 |
---|
| 79 | ENDIF ELSE BEGIN |
---|
[133] | 80 | ; there is not any widget activated |
---|
| 81 | ; do we ask a question ? |
---|
[2] | 82 | if keyword_set(question) then BEGIN |
---|
[133] | 83 | ; what i sthe answer by default ? |
---|
[2] | 84 | if keyword_set(default_no) then answer = 'n' ELSE answer = 'y' |
---|
| 85 | default_answer = answer |
---|
| 86 | if n_elements(text) GT 1 THEN $ |
---|
| 87 | for i = 0, n_elements(text)-2 do print,text[i] |
---|
| 88 | read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')' , answer |
---|
| 89 | answer = strlowcase(answer) ; |
---|
[133] | 90 | ; if the answer is not appropriated |
---|
[2] | 91 | while answer NE '' and answer NE 'y' and answer NE 'n' do begin |
---|
| 92 | read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')' , answer |
---|
| 93 | answer = strlowcase(answer) |
---|
| 94 | ENDWHILE ; |
---|
[133] | 95 | ; we adjust res in function of th answer |
---|
[2] | 96 | case answer of |
---|
| 97 | '':res = default_answer EQ 'y' |
---|
| 98 | 'y':res = 1 |
---|
| 99 | 'n':res = 0 |
---|
| 100 | endcase |
---|
| 101 | endif ELSE BEGIN |
---|
[133] | 102 | ; If we do not ask any question, we just make a print |
---|
[11] | 103 | IF keyword_set(simple) THEN prefix = '' ELSE prefix = '% '+routine_name(1)+': ' |
---|
[2] | 104 | if n_elements(text) GT 1 THEN $ |
---|
[11] | 105 | for i = 0, n_elements(text)-2 do print, prefix+text[i] |
---|
| 106 | print, prefix+text[n_elements(text)-1] |
---|
[2] | 107 | ENDELSE |
---|
| 108 | ENDELSE |
---|
| 109 | |
---|
| 110 | return, res |
---|
| 111 | end |
---|