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

Last change on this file since 375 was 375, checked in by pinsard, 16 years ago

improvements of headers (paragraphs and alignments)

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