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

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

change *.pro file properties (del eof-style, del executable, set keywords Id

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