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

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

slight bugfix + nicer print in report, see #65

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.4 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 <pro>xquestion</pro>.
7;
8; @param TEXTIN {in}{required} {type=scalar string or arrays of string}
9; If TEXTIN is a scalar string, we look for the line feed character "!C".
10; If TEXTIN is set to an array of strings, each
11; array element is displayed as a separate line of text.
12;
13; @keyword SIMPLE
14; activate to print only the message without the name
15; and the line of the routine (defined by calling <pro>routine_name</pro>)
16; or++
17; Activate to print the error message without printing the routine name with
18; its full path.
19;
20; @keyword PARENT
21; same as DIALOG_PARENT of <proidl>DIALOG_MESSAGE</proidl>
22;
23; @keyword QUESTION {default="Warning"}
24; Set this keyword to create a "Question" dialog.
25;
26; @keyword DEFAULT_NO {default="Yes"}
27; Set this keyword to make the "No" button the default selection for
28; "Question" dialog.
29;
30; @keyword _EXTRA
31; Used to pass keywords to <proidl>DIALOG_MESSAGE</proidl> and
32; <proidl>MESSAGE</proidl>
33;
34; @returns
35; -1 if the keyword QUESTION is not activated
36; If the keyword QUESTION is activated, return 1 for yes and 0 for no.
37;
38; @examples
39; If there is not any widget activated:
40;
41; IDL> help, report('toto tata')
42; % $MAIN$: toto tata
43; <Expression>    INT       =       -1
44; IDL> help, report('does it works ?',/question)
45; does it works ? y/n (default answer is y)
46; <Expression>    BYTE      =    1
47; IDL> help, report('question1: !C does it works ?',/question)
48; question1:
49; does it works ? y/n (default answer is y)
50; <Expression>    BYTE      =    1
51;
52; If widgets are already activated, it is the same thing but with widgets!
53;
54; @history
55; Sebastien Masson (smasson\@lodyc.jussieu.fr)
56;                      21/10/1999
57;
58; @version
59; $Id$
60;
61;-
62;
63FUNCTION report, textin, DEFAULT_NO = default_no, PARENT = parent, QUESTION = question, SIMPLE = simple, _EXTRA = ex
64;
65  compile_opt idl2, strictarrsubs
66;
67  res = -1                      ;
68; we separate the text in different lines (separated by !C) if it is not already done...
69  if n_elements(textin) EQ 1 then text = '% ' + str_sep(textin, '!C', /trim) ELSE text = '% ' + textin
70; we get the line, routine name ad revision version
71  IF NOT keyword_set(simple) THEN BEGIN
72;    Look for the revsion in the code of the procedure/function calling this
73;    report function (ie the one where an problem was detected) in the first
74;    occurence of the form :
75;    "; $Id$"
76    prefix = routine_name(1)
77    split = STRSPLIT(prefix, ' ', /EXTRACT) 
78    coderoutine = getfile(split[1])
79    idline = (where(stregex(coderoutine, '^; \$Id: .* .* .* .* \$', /boolean) EQ 1))[0]
80    IF (idline GT 0) THEN BEGIN
81      split = STRSPLIT(coderoutine[idline], ' ', /EXTRACT)
82      prefix = '% '+prefix+ ' rev. ' + split[3] + ': '
83    ENDIF ELSE BEGIN
84      prefix = '% '+prefix+': '
85    ENDELSE
86    text = [prefix, text]
87  ENDIF
88; there is some widgets activated, it is easy, we call dialog_massage
89  if (widget_info(/managed))[0] NE 0 then BEGIN
90    res = dialog_message(text, dialog_parent = parent, QUESTION = question $
91                         , title = routine_name(1), DEFAULT_NO = default_no, _extra = ex)
92    if keyword_set(question) THEN res = res EQ 'Yes' ELSE res = -1
93  ENDIF ELSE BEGIN
94; there is not any widget activated
95; do we ask a question ?
96    IF keyword_set(question) THEN BEGIN
97; what is the answer by default ?
98      if keyword_set(default_no) then answer = 'n' ELSE answer = 'y'
99      default_answer = answer
100      if n_elements(text) GT 1 THEN $
101         for i = 0, n_elements(text)-2 do print, text[i]
102      read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer
103      answer = strlowcase(answer) ;
104; if the answer is not appropriated
105      while answer NE '' and answer NE 'y' and answer NE 'n' do begin
106        read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer
107        answer = strlowcase(answer)
108      ENDWHILE                  ;
109; we adjust res in function of the answer
110      case answer of
111        '':res = default_answer EQ 'y'
112        'y':res = 1
113        'n':res = 0
114      endcase
115    ENDIF
116  ENDELSE
117; If we do not ask any question, we just make a print
118  IF NOT keyword_set(question) THEN BEGIN
119    FOR i = 0, n_elements(text)-1 do print, text[i]
120  ENDIF
121
122  return,  res
123end
Note: See TracBrowser for help on using the repository browser.