Changeset 485


Ignore:
Timestamp:
08/02/13 18:25:50 (11 years ago)
Author:
pinsard
Message:

improve non interactive report

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SRC/Utilities/report.pro

    r375 r485  
    2525; @keyword QUESTION {default="Warning"} 
    2626; Set this keyword to create a "Question" dialog. 
     27; If batch mode is detected, answer to be given is ANSWER_BATCH if exists or  
     28; the default one (see DEFAULT_NO keyword). 
     29; 
     30; @keyword ANSWER_BATCH 
     31; Answer to be given to replace human being when running in non interactive 
     32; session. Only used when QUESTION keyword is set. 
    2733; 
    2834; @keyword DEFAULT_NO {default="Yes"} 
     
    5258; <Expression>    BYTE      =    1 
    5359; 
     60; To simulated non interactive session : 
     61; 
     62;   IDL> set_default_device 
     63;   IDL> key_batch = 1 
     64;   IDL> help, report('question1: !C does it works ?',/question, answer_batch='y') 
     65; question1: 
     66; does it works ? y/n (default answer is y) 
     67; <Expression>    BYTE      =    1 
     68; 
     69; Like in determineminmax.pro: 
     70; 
     71;   set_default_device 
     72;   key_batch = 1 
     73;   vraimin = 0.d0 
     74;   question = ['Warning: constant filed, same value everywhere : ' + strtrim(vraimin, 2) +'!', 'Shall we make the plot?'] 
     75;   answer = report(question, /default_no, /question) 
     76; 
     77; 
    5478; If widgets are already activated, it is the same thing but with widgets! 
    5579; 
    5680; @history 
    57 ; Sebastien Masson (smasson\@lodyc.jussieu.fr) 
    58 ;                      21/10/1999 
     81; 
     82; - fplod 20130802T123116Z cratos.locean-ipsl.upmc.fr (Linux) 
     83; 
     84;   * add ANSWER_BATCH keyword and handle key_batch 
     85; 
     86; - Sebastien Masson (smasson\@lodyc.jussieu.fr) 21/10/1999  
    5987; 
    6088; @version 
     
    6391;- 
    6492FUNCTION report, textin, DEFAULT_NO=default_no, PARENT=parent $ 
    65                , QUESTION=question, SIMPLE=simple, _EXTRA=ex 
     93               , QUESTION=question, SIMPLE=simple $ 
     94               , ANSWER_BATCH=answer_batch $ 
     95               , _EXTRA=ex 
    6696; 
    6797  compile_opt idl2, strictarrsubs 
     98 
     99  @cm_general 
    68100; 
    69101  res = -1                      ; 
     102 
     103  ; check parameter and keywords 
     104  if keyword_set(default_no) then default_answer = 'n' ELSE default_answer = 'y' 
     105 
     106  ; if QUESTION keyword is set, ANSWER_BATCH must be also set with value in '', 'y' or 'n' 
     107  IF keyword_set(QUESTION) THEN BEGIN 
     108     IF NOT keyword_set(ANSWER_BATCH) THEN BEGIN 
     109        print, 'www : ANSWER_BATCH is not set, default answer while be used' 
     110        answer_batch = default_answer 
     111     ENDIF ELSE BEGIN 
     112         IF answer_batch NE '' and answer_batch NE 'y' and answer_batch NE 'n' THEN BEGIN 
     113             answer_batch = default_answer 
     114         ENDIF 
     115     ENDELSE 
     116  ENDIF 
     117 
    70118; we separate the text in different lines (separated by !C) if it is not already done... 
    71119  if n_elements(textin) EQ 1 then text = '% ' + str_sep(textin, '!C', /trim) ELSE text = '% ' + textin 
     
    90138    text = [prefix, text] 
    91139  ENDIF 
    92 ; there is some widgets activated, it is easy, we call dialog_massage 
     140  ; there is some widgets activated, it is easy, we call dialog_massage 
    93141  if (widget_info(/managed))[0] NE 0 then BEGIN 
    94142    res = dialog_message(text, dialog_parent = parent, QUESTION = question $ 
     
    96144    if keyword_set(question) THEN res = res EQ 'Yes' ELSE res = -1 
    97145  ENDIF ELSE BEGIN 
    98 ; there is not any widget activated 
    99 ; do we ask a question ? 
     146    ; there is not any widget activated 
     147    ; do we ask a question ? 
    100148    IF keyword_set(question) THEN BEGIN 
    101 ; what is the answer by default ? 
     149      ; what is the answer by default ? 
    102150      if keyword_set(default_no) then answer = 'n' ELSE answer = 'y' 
    103151      default_answer = answer 
    104152      if n_elements(text) GT 1 THEN $ 
    105153         for i = 0, n_elements(text)-2 do print, text[i] 
    106       read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer 
     154      ; 
     155      ; if non interactive mode has not yet have been tested, do it 
     156      IF NOT testvar(var = key_batch) THEN BEGIN 
     157         set_default_device 
     158      ENDIF 
     159      if key_batch EQ 0 THEN BEGIN 
     160          ; if interactive mode is the current one, wait for human being answer ... 
     161          read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer 
     162      ENDIF ELSE BEGIN 
     163          ; if not, answer with ANSWER_BATCH keyword or the default answer if not set 
     164          IF testvar(var = answer_batch) THEN BEGIN 
     165              print, 'batch answer with answer_batch ', answer_batch 
     166              answer = answer_batch 
     167          ENDIF ELSE BEGIN 
     168              print, 'batch answer with default_answer ', default_answer 
     169              answer = default_answer 
     170          ENDELSE 
     171      ENDELSE 
     172  
    107173      answer = strlowcase(answer) ; 
    108 ; if the answer is not appropriated 
     174      ; if the answer is not appropriated 
    109175      while answer NE '' and answer NE 'y' and answer NE 'n' do begin 
    110176        read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer 
    111177        answer = strlowcase(answer) 
    112178      ENDWHILE                  ; 
    113 ; we adjust res in function of the answer 
     179      ; we adjust res in function of the answer 
    114180      case answer of 
    115181        '':res = default_answer EQ 'y' 
Note: See TracChangeset for help on using the changeset viewer.