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

Last change on this file since 153 was 136, checked in by pinsard, 18 years ago

some improvements and corrections in some .pro file according to
aspell and idldoc log file

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.2 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 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;
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 Sebastien Masson (smasson\@lodyc.jussieu.fr)
59;                      21/10/1999
60;
61; @version $Id$
62;
63;-
64;------------------------------------------------------------
65;------------------------------------------------------------
66;------------------------------------------------------------
67FUNCTION report, text, DEFAULT_NO = default_no, PARENT = parent, QUESTION = question, SIMPLE = simple, _extra = ex
68;
69  compile_opt idl2, strictarrsubs
70;
71  res = -1                      ;
72; we separate the text in different lines (separated by !C) if it is not already done...
73   if n_elements(text) EQ 1 then text = str_sep(text, '!C', /trim)
74; there is some widgets activated, it is easy, we call dialog_massage
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
80; there is not any widget activated
81; do we ask a question ?
82      if keyword_set(question) then BEGIN
83; what i sthe answer by default ?
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) ;
90; if the answer is not appropriated
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               ;
95; we adjust res in function of th answer
96         case answer of
97            '':res = default_answer EQ 'y'
98            'y':res = 1
99            'n':res = 0
100         endcase
101      endif ELSE BEGIN
102; If we do not ask any question, we just make a print
103        IF keyword_set(simple) THEN prefix = '' ELSE prefix = '% '+routine_name(1)+': '
104         if n_elements(text) GT 1 THEN $
105          for i = 0, n_elements(text)-2 do print, prefix+text[i]
106         print, prefix+text[n_elements(text)-1]
107      ENDELSE
108   ENDELSE
109
110   return,  res
111end
Note: See TracBrowser for help on using the repository browser.