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 | ; |
---|
7 | ; To ask a question whose answer is not yes/no, use <pro>xquestion</pro>. |
---|
8 | ; |
---|
9 | ; @param textin {in}{required} {type=scalar string or arrays of string} |
---|
10 | ; If textin is a scalar string, we look for the line feed character "!C". |
---|
11 | ; |
---|
12 | ; If textin is set to an array of strings, each |
---|
13 | ; array element is displayed as a separate line of text. |
---|
14 | ; |
---|
15 | ; @keyword SIMPLE |
---|
16 | ; activate to print only the message without the name |
---|
17 | ; and the line of the routine (defined by calling <pro>routine_name</pro>) |
---|
18 | ; or++ |
---|
19 | ; Activate to print the error message without printing the routine name with |
---|
20 | ; its full path. |
---|
21 | ; |
---|
22 | ; @keyword PARENT |
---|
23 | ; same as DIALOG_PARENT of <proidl>DIALOG_MESSAGE</proidl> |
---|
24 | ; |
---|
25 | ; @keyword QUESTION {default="Warning"} |
---|
26 | ; Set this keyword to create a "Question" dialog. |
---|
27 | ; If batch mode is detected, answer to be given is ANSWER_BATCH if exists or |
---|
28 | ; the default one (see DEFAULT_NO keyword). |
---|
29 | ; |
---|
30 | ; @keyword ANSWER_BATCH |
---|
31 | ; Answer to be given to replace human being when running in non interactive |
---|
32 | ; session. Only used when QUESTION keyword is set. |
---|
33 | ; |
---|
34 | ; @keyword DEFAULT_NO {default="Yes"} |
---|
35 | ; Set this keyword to make the "No" button the default selection for |
---|
36 | ; "Question" dialog. |
---|
37 | ; |
---|
38 | ; @keyword _EXTRA |
---|
39 | ; Used to pass keywords to <proidl>DIALOG_MESSAGE</proidl> and |
---|
40 | ; <proidl>MESSAGE</proidl> |
---|
41 | ; |
---|
42 | ; @returns |
---|
43 | ; -1 if the keyword QUESTION is not activated |
---|
44 | ; If the keyword QUESTION is activated, return 1 for yes and 0 for no. |
---|
45 | ; |
---|
46 | ; @examples |
---|
47 | ; If there is not any widget activated: |
---|
48 | ; |
---|
49 | ; IDL> help, report('toto tata') |
---|
50 | ; % $MAIN$: toto tata |
---|
51 | ; <Expression> INT = -1 |
---|
52 | ; IDL> help, report('does it works ?',/question) |
---|
53 | ; does it works ? y/n (default answer is y) |
---|
54 | ; <Expression> BYTE = 1 |
---|
55 | ; IDL> help, report('question1: !C does it works ?',/question) |
---|
56 | ; question1: |
---|
57 | ; does it works ? y/n (default answer is y) |
---|
58 | ; <Expression> BYTE = 1 |
---|
59 | ; |
---|
60 | ; To simulated non interactive session : |
---|
61 | ; |
---|
62 | ; IDL> set_default_device |
---|
63 | ; IDL> key_batch = 1 |
---|
64 | ; IDL> help, report('question1: !C does it works ?',/question, answer_batch='y') |
---|
65 | ; question1: |
---|
66 | ; does it works ? y/n (default answer is y) |
---|
67 | ; <Expression> BYTE = 1 |
---|
68 | ; |
---|
69 | ; Like in determineminmax.pro: |
---|
70 | ; |
---|
71 | ; set_default_device |
---|
72 | ; key_batch = 1 |
---|
73 | ; vraimin = 0.d0 |
---|
74 | ; question = ['Warning: constant filed, same value everywhere : ' + strtrim(vraimin, 2) +'!', 'Shall we make the plot?'] |
---|
75 | ; answer = report(question, /default_no, /question) |
---|
76 | ; |
---|
77 | ; If widgets are already activated, it is the same thing but with widgets! |
---|
78 | ; |
---|
79 | ; @history |
---|
80 | ; |
---|
81 | ; - fplod 20130802T123116Z cratos.locean-ipsl.upmc.fr (Linux) |
---|
82 | ; |
---|
83 | ; * add ANSWER_BATCH keyword and handle key_batch |
---|
84 | ; |
---|
85 | ; - Sebastien Masson (smasson\@lodyc.jussieu.fr) 21/10/1999 |
---|
86 | ; |
---|
87 | ; @version |
---|
88 | ; $Id$ |
---|
89 | ; |
---|
90 | ;- |
---|
91 | FUNCTION report, textin, DEFAULT_NO=default_no, PARENT=parent $ |
---|
92 | , QUESTION=question, SIMPLE=simple $ |
---|
93 | , ANSWER_BATCH=answer_batch $ |
---|
94 | , _EXTRA=ex |
---|
95 | ; |
---|
96 | compile_opt idl2, strictarrsubs |
---|
97 | |
---|
98 | @cm_general |
---|
99 | ; |
---|
100 | res = -1 ; |
---|
101 | |
---|
102 | ; check parameter and keywords |
---|
103 | if keyword_set(default_no) then default_answer = 'n' ELSE default_answer = 'y' |
---|
104 | |
---|
105 | ; if QUESTION keyword is set, ANSWER_BATCH must be also set with value in '', 'y' or 'n' |
---|
106 | IF keyword_set(QUESTION) THEN BEGIN |
---|
107 | IF NOT keyword_set(ANSWER_BATCH) THEN BEGIN |
---|
108 | print, 'www : ANSWER_BATCH is not set, default answer while be used' |
---|
109 | answer_batch = default_answer |
---|
110 | ENDIF ELSE BEGIN |
---|
111 | IF answer_batch NE '' and answer_batch NE 'y' and answer_batch NE 'n' THEN BEGIN |
---|
112 | answer_batch = default_answer |
---|
113 | ENDIF |
---|
114 | ENDELSE |
---|
115 | ENDIF |
---|
116 | |
---|
117 | ; we separate the text in different lines (separated by !C) if it is not already done... |
---|
118 | if n_elements(textin) EQ 1 then text = '% ' + str_sep(textin, '!C', /trim) ELSE text = '% ' + textin |
---|
119 | ; we get the line, routine name and revision version |
---|
120 | IF NOT keyword_set(simple) THEN BEGIN |
---|
121 | ; Look for the revision in the code of the procedure/function calling this |
---|
122 | ; report function (ie the one where an problem was detected) in the first |
---|
123 | ; occurrence of the form : |
---|
124 | ; "; $Id$" |
---|
125 | prefix = routine_name(1) |
---|
126 | split = STRSPLIT(prefix, ' ', /EXTRACT, count = cnt) |
---|
127 | IF cnt GT 1 THEN BEGIN |
---|
128 | coderoutine = getfile(split[1]) |
---|
129 | idline = (where(stregex(coderoutine, '^; \$Id: .* .* .* .* \$', /boolean) EQ 1))[0] |
---|
130 | IF (idline GT 0) THEN BEGIN |
---|
131 | split = STRSPLIT(coderoutine[idline], ' ', /EXTRACT) |
---|
132 | prefix = '% '+prefix+ ' rev. ' + split[3] + ': ' |
---|
133 | ENDIF ELSE BEGIN |
---|
134 | prefix = '% '+prefix+': ' |
---|
135 | ENDELSE |
---|
136 | ENDIF |
---|
137 | text = [prefix, text] |
---|
138 | ENDIF |
---|
139 | ; there is some widgets activated, it is easy, we call dialog_massage |
---|
140 | if (widget_info(/managed))[0] NE 0 then BEGIN |
---|
141 | res = dialog_message(text, dialog_parent = parent, QUESTION = question $ |
---|
142 | , title = routine_name(1), DEFAULT_NO = default_no, _extra = ex) |
---|
143 | if keyword_set(question) THEN res = res EQ 'Yes' ELSE res = -1 |
---|
144 | ENDIF ELSE BEGIN |
---|
145 | ; there is not any widget activated |
---|
146 | ; do we ask a question ? |
---|
147 | IF keyword_set(question) THEN BEGIN |
---|
148 | ; what is the answer by default ? |
---|
149 | if keyword_set(default_no) then answer = 'n' ELSE answer = 'y' |
---|
150 | default_answer = answer |
---|
151 | if n_elements(text) GT 1 THEN $ |
---|
152 | for i = 0, n_elements(text)-2 do print, text[i] |
---|
153 | ; |
---|
154 | ; if non interactive mode has not yet have been tested, do it |
---|
155 | IF NOT testvar(var = key_batch) THEN BEGIN |
---|
156 | set_default_device |
---|
157 | ENDIF |
---|
158 | if key_batch EQ 0 THEN BEGIN |
---|
159 | ; if interactive mode is the current one, wait for human being answer ... |
---|
160 | read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer |
---|
161 | ENDIF ELSE BEGIN |
---|
162 | ; if not, answer with ANSWER_BATCH keyword or the default answer if not set |
---|
163 | IF testvar(var = answer_batch) THEN BEGIN |
---|
164 | print, 'batch answer with answer_batch ', answer_batch |
---|
165 | answer = answer_batch |
---|
166 | ENDIF ELSE BEGIN |
---|
167 | print, 'batch answer with default_answer ', default_answer |
---|
168 | answer = default_answer |
---|
169 | ENDELSE |
---|
170 | ENDELSE |
---|
171 | |
---|
172 | answer = strlowcase(answer) ; |
---|
173 | ; if the answer is not appropriated |
---|
174 | while answer NE '' and answer NE 'y' and answer NE 'n' do begin |
---|
175 | read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer |
---|
176 | answer = strlowcase(answer) |
---|
177 | ENDWHILE ; |
---|
178 | ; we adjust res in function of the answer |
---|
179 | case answer of |
---|
180 | '':res = default_answer EQ 'y' |
---|
181 | 'y':res = 1 |
---|
182 | 'n':res = 0 |
---|
183 | endcase |
---|
184 | ENDIF |
---|
185 | ENDELSE |
---|
186 | ; If we do not ask any question, we just make a print |
---|
187 | IF NOT keyword_set(question) THEN BEGIN |
---|
188 | FOR i = 0, n_elements(text)-1 do print, text[i] |
---|
189 | ENDIF |
---|
190 | |
---|
191 | return, res |
---|
192 | end |
---|