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

Last change on this file since 239 was 239, checked in by smasson, 17 years ago

cleaning + minor bugfix related to the path definition

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
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}
9; one string or one vector of string. Si le string ne
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 routine_name)
17;
18; @keyword _EXTRA
19; Used to pass keywords to <proidl>dialog_message</proidl> and
20; <proidl>message</proidl>
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;
28; @keyword DEFAULT_NO {default="Yes"}
29; Set this keyword to make the "No" button the default selection for
30; "Question" dialog.
31;
32; @keyword SIMPLE
33; Activate to print the error message without printing the routine name with
34; its full path.
35;
36; @returns
37; -1 if the keyword QUESTION is not activated
38; If the keyword QUESTION is activated, return 1 for yes and 0 for no.
39;
40; @examples
41; If there is not any widget activated:
42;
43; IDL> help, report('toto tata')
44; % $MAIN$: toto tata
45; <Expression>    INT       =       -1
46; IDL> help, report('does it works ?',/question)
47; does it works ? y/n (default answer is y)
48; <Expression>    BYTE      =    1
49; IDL> help, report('question1: !C does it works ?',/question)
50; question1:
51; does it works ? y/n (default answer is y)
52; <Expression>    BYTE      =    1
53;
54; If widgets are already activated, it is the same thing but with widgets!
55;
56; @history
57; Sebastien Masson (smasson\@lodyc.jussieu.fr)
58;                      21/10/1999
59;
60; @version
61; $Id$
62;
63;-
64;
65FUNCTION report, text, DEFAULT_NO = default_no, PARENT = parent, QUESTION = question, SIMPLE = simple, _EXTRA = ex
66;
67  compile_opt idl2, strictarrsubs
68;
69  res = -1                      ;
70; we separate the text in different lines (separated by !C) if it is not already done...
71  if n_elements(text) EQ 1 then text = str_sep(text, '!C', /trim)
72; there is some widgets activated, it is easy, we call dialog_massage
73  if (widget_info(/managed))[0] NE 0 then BEGIN
74    res = dialog_message(text, dialog_parent = parent, QUESTION = question $
75                         , title = routine_name(1), DEFAULT_NO = default_no, _extra = ex)
76    if keyword_set(question) THEN res = res EQ 'Yes' ELSE res = -1
77  ENDIF ELSE BEGIN
78; there is not any widget activated
79; do we ask a question ?
80    if keyword_set(question) then BEGIN
81; what i sthe answer by default ?
82      if keyword_set(default_no) then answer = 'n' ELSE answer = 'y'
83      default_answer = answer
84      if n_elements(text) GT 1 THEN $
85        for i = 0, n_elements(text)-2 do print, text[i]
86      read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer
87      answer = strlowcase(answer) ;
88; if the answer is not appropriated
89      while answer NE '' and answer NE 'y' and answer NE 'n' do begin
90        read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer
91        answer = strlowcase(answer)
92      ENDWHILE                  ;
93; we adjust res in function of th answer
94      case answer of
95        '':res = default_answer EQ 'y'
96        'y':res = 1
97        'n':res = 0
98      endcase
99    ENDIF
100  ENDELSE
101; If we do not ask any question, we just make a print
102  IF NOT keyword_set(question) THEN BEGIN
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  ENDIF
108
109   return,  res
110end
Note: See TracBrowser for help on using the repository browser.