source: trunk/SRC/Utilities/report.pro @ 226

Last change on this file since 226 was 226, checked in by pinsard, 17 years ago

corrections of some misspellings in some *.pro

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5;
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.
10;
11; @param TEXT {in}{required}
12; one string or one vector of string. Si le string ne
13; comporte qu''un element, on cherche les eventuels caracteres 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;
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)
20;
21; @keyword _EXTRA
22; used to pass keywords from dialog_message.pro and message.pro
23;
24; @keyword PARENT
25; same as DIALOG_PARENT de dialog_message.pro
26;
27; @keyword QUESTION {default="Warning"}
28; Set this keyword to create a "Question" dialog.
29;
30; @keyword DEFAULT_NO {default="Yes"}
31; Set this keyword to make the "No" button the default selection for
32; "Question" dialog.
33;
34; @keyword SIMPLE
35; Activate to print the error message without printing the routine name with
36; its full path.
37;
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.
41;
42; @examples
43; If there is not any widget activated:
44;
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
55;
56; If widgets are already activated, it is the same thing but with widgets!
57;
58; @history
59; Sebastien Masson (smasson\@lodyc.jussieu.fr)
60;                      21/10/1999
61;
62; @version
63; $Id$
64;
65;-
66;------------------------------------------------------------
67;------------------------------------------------------------
68;------------------------------------------------------------
69FUNCTION report, text, DEFAULT_NO = default_no, PARENT = parent, QUESTION = question, SIMPLE = simple, _extra = ex
70;
71  compile_opt idl2, strictarrsubs
72;
73  res = -1                      ;
74; we separate the text in different lines (separated by !C) if it is not already done...
75   if n_elements(text) EQ 1 then text = str_sep(text, '!C', /trim)
76; there is some widgets activated, it is easy, we call dialog_massage
77   if (widget_info(/managed))[0] NE 0 then BEGIN
78      res = dialog_message(text, dialog_parent = parent, QUESTION = question $
79                           , title = routine_name(1), DEFAULT_NO = default_no, _extra = ex)
80      if keyword_set(question) THEN res = res EQ 'Yes' ELSE res = -1
81   ENDIF ELSE BEGIN
82; there is not any widget activated
83; do we ask a question ?
84      if keyword_set(question) then BEGIN
85; what i sthe answer by default ?
86         if keyword_set(default_no) then answer = 'n' ELSE answer = 'y'
87         default_answer = answer
88         if n_elements(text) GT 1 THEN $
89          for i = 0, n_elements(text)-2 do print,text[i]
90         read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')' , answer
91         answer = strlowcase(answer) ;
92; if the answer is not appropriated
93         while answer NE '' and answer NE 'y' and answer NE 'n' do begin
94            read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')' , answer
95            answer = strlowcase(answer)
96         ENDWHILE               ;
97; we adjust res in function of th answer
98         case answer of
99            '':res = default_answer EQ 'y'
100            'y':res = 1
101            'n':res = 0
102         endcase
103      endif ELSE BEGIN
104; If we do not ask any question, we just make a print
105        IF keyword_set(simple) THEN prefix = '' ELSE prefix = '% '+routine_name(1)+': '
106         if n_elements(text) GT 1 THEN $
107          for i = 0, n_elements(text)-2 do print, prefix+text[i]
108         print, prefix+text[n_elements(text)-1]
109      ENDELSE
110   ENDELSE
111
112   return,  res
113end
Note: See TracBrowser for help on using the repository browser.