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