1 | ;+ |
---|
2 | ; |
---|
3 | ; @file_comments |
---|
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. |
---|
6 | ; To ask a question whose answer is not yes/no, use xquestion. |
---|
7 | ; |
---|
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" |
---|
10 | ; comporte qu''un element, on cherche les eventuels caracteres de |
---|
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 | ; |
---|
14 | ; @keyword SIMPLE |
---|
15 | ; activate to print only the message without the name |
---|
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. |
---|
20 | ; |
---|
21 | ; @keyword PARENT |
---|
22 | ; same as DIALOG_PARENT of <proidl>DIALOG_MESSAGE</proidl> |
---|
23 | ; |
---|
24 | ; @keyword QUESTION {default="Warning"} |
---|
25 | ; Set this keyword to create a "Question" dialog. |
---|
26 | ; |
---|
27 | ; @keyword DEFAULT_NO {default="Yes"} |
---|
28 | ; Set this keyword to make the "No" button the default selection for |
---|
29 | ; "Question" dialog. |
---|
30 | ; |
---|
31 | ; @keyword _EXTRA |
---|
32 | ; Used to pass keywords to <proidl>DIALOG_MESSAGE</proidl> and |
---|
33 | ; <proidl>MESSAGE</proidl> |
---|
34 | ; |
---|
35 | ; @returns |
---|
36 | ; -1 if the keyword QUESTION is not activated |
---|
37 | ; If the keyword QUESTION is activated, return 1 for yes and 0 for no. |
---|
38 | ; |
---|
39 | ; @examples |
---|
40 | ; If there is not any widget activated: |
---|
41 | ; |
---|
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 |
---|
52 | ; |
---|
53 | ; If widgets are already activated, it is the same thing but with widgets! |
---|
54 | ; |
---|
55 | ; @history |
---|
56 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
57 | ; 21/10/1999 |
---|
58 | ; |
---|
59 | ; @version |
---|
60 | ; $Id$ |
---|
61 | ; |
---|
62 | ;- |
---|
63 | ; |
---|
64 | FUNCTION report, text, DEFAULT_NO = default_no, PARENT = parent, QUESTION = question, SIMPLE = simple, _EXTRA = ex |
---|
65 | ; |
---|
66 | compile_opt idl2, strictarrsubs |
---|
67 | ; |
---|
68 | res = -1 ; |
---|
69 | ; we separate the text in different lines (separated by !C) if it is not already done... |
---|
70 | if n_elements(text) EQ 1 then text = str_sep(text, '!C', /trim) |
---|
71 | ; there is some widgets activated, it is easy, we call dialog_massage |
---|
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 |
---|
77 | ; there is not any widget activated |
---|
78 | ; do we ask a question ? |
---|
79 | if keyword_set(question) then BEGIN |
---|
80 | ; what i sthe answer by default ? |
---|
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) ; |
---|
87 | ; if the answer is not appropriated |
---|
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 ; |
---|
92 | ; we adjust res in function of th answer |
---|
93 | case answer of |
---|
94 | '':res = default_answer EQ 'y' |
---|
95 | 'y':res = 1 |
---|
96 | 'n':res = 0 |
---|
97 | endcase |
---|
98 | ENDIF |
---|
99 | ENDELSE |
---|
100 | ; If we do not ask any question, we just make a print |
---|
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 |
---|
107 | |
---|
108 | return, res |
---|
109 | end |
---|