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

Last change on this file since 133 was 133, checked in by navarro, 18 years ago

english and nicer header (1)

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 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} un string on un vecteur de string. Si le string ne
12; comporte qu''un element, on cherche les eventuels characteres de
13; retour a la ligne: '!C'. If text is set to an array of strings, each
14; array element is displayed as a separate line of text.
15;
16; @keyword SIMPLE activate to print only the message without the name
17;             and the line of the routine (defined by calling routine_name)
18;
19; @keyword _extra used to pass keywords from dialog_message.pro and message.pro
20;
21; @keyword PARENT same as DIALOG_PARENT de dialog_message.pro
22;
23; @keyword QUESTION Set this keyword to create a "Question" dialog.
24;                   The default dialog type is "Warning"
25;
26; @keyword DEFAULT_NO Set this keyword to make the "No" button the default
27;                     selection for "Question" dialog. Normally, the default is yes.
28;
29; @keyword SIMPLE Activate to print the error message without printing
30;                 the routine name with its full path.
31;
32; @returns -1 if the keyword QUESTION is not activated
33;          If the keyword is activated, return 1 for yes and 0 for no.
34;
35; @example If there is not any widget activated:
36;
37;     IDL> help, report('toto tata')
38;     % $MAIN$: toto tata
39;     <Expression>    INT       =       -1
40;     IDL> help, report('does it works ?',/question)
41;     does it works ? y/n (default answer is y)
42;     <Expression>    BYTE      =    1
43;     IDL> help, report('question1: !C does it works ?',/question)
44;     question1:
45;     does it works ? y/n (default answer is y)
46;     <Expression>    BYTE      =    1
47;
48; If widgets are already activated, it is the same thing but with widgets!
49;
50; @history Sebastien Masson (smasson@lodyc.jussieu.fr)
51;                      21/10/1999
52;
53; @version $ID$
54;
55;-
56;------------------------------------------------------------
57;------------------------------------------------------------
58;------------------------------------------------------------
59FUNCTION report, text, DEFAULT_NO = default_no, PARENT = parent, QUESTION = question, SIMPLE = simple, _extra = ex
60;
61  compile_opt idl2, strictarrsubs
62;
63  res = -1                      ;
64; we separate the text in different lines (separated by !C) if it is not already done...
65   if n_elements(text) EQ 1 then text = str_sep(text, '!C', /trim)
66; there is some widgets activated, it is easy, we call dialog_massage
67   if (widget_info(/managed))[0] NE 0 then BEGIN
68      res = dialog_message(text, dialog_parent = parent, QUESTION = question $
69                           , title = routine_name(1), DEFAULT_NO = default_no, _extra = ex)
70      if keyword_set(question) THEN res = res EQ 'Yes' ELSE res = -1
71   ENDIF ELSE BEGIN
72; there is not any widget activated
73; do we ask a question ?
74      if keyword_set(question) then BEGIN
75; what i sthe answer by default ?
76         if keyword_set(default_no) then answer = 'n' ELSE answer = 'y'
77         default_answer = answer
78         if n_elements(text) GT 1 THEN $
79          for i = 0, n_elements(text)-2 do print,text[i]
80         read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')' , answer
81         answer = strlowcase(answer) ;
82; if the answer is not appropriated
83         while answer NE '' and answer NE 'y' and answer NE 'n' do begin
84            read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')' , answer
85            answer = strlowcase(answer)
86         ENDWHILE               ;
87; we adjust res in function of th answer
88         case answer of
89            '':res = default_answer EQ 'y'
90            'y':res = 1
91            'n':res = 0
92         endcase
93      endif ELSE BEGIN
94; If we do not ask any question, we just make a print
95        IF keyword_set(simple) THEN prefix = '' ELSE prefix = '% '+routine_name(1)+': '
96         if n_elements(text) GT 1 THEN $
97          for i = 0, n_elements(text)-2 do print, prefix+text[i]
98         print, prefix+text[n_elements(text)-1]
99      ENDELSE
100   ENDELSE
101
102   return,  res
103end
Note: See TracBrowser for help on using the repository browser.