source: trunk/SRC/ToBeReviewed/WIDGET/xquestion.pro @ 114

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1;------------------------------------------------------------
2;------------------------------------------------------------
3;------------------------------------------------------------
4;+
5; NAME:xquestion
6;
7; PURPOSE: a small widget who ask a question and give an answer.
8;          WARNING: For a binary question with yes/no answer use
9;                   DIALOG_MESSAGE.
10;
11; CATEGORY: widget
12;
13; CALLING SEQUENCE: answer = xquestion(question[,proposedanswer])
14;
15; INPUTS:
16;        question: a scalar string or a array of string. If this
17;        argument is set to :
18;          + an array of strings: each array element is
19;            displayed as a separate line of text.
20;          + a scalar string: we are looking for the "separate line
21;          character" '!C'
22;
23;        proposedanswer: a string proposing a answer
24;
25; KEYWORD PARAMETERS: those from WIDGET_BASE and WIDGET_TEXT
26;
27;        /CHKWIDGET: active this keyword if you whant that xquestion
28;        check if managed widget are present. If not, xquestion do not
29;        open a widget but print the question in the IDL window.
30;
31; OUTPUTS:
32;        answer: a string
33;
34; COMMON BLOCKS:
35;        none (we use a "false widget")
36;
37; SIDE EFFECTS:
38;        The function does not return to its caller until the user
39;        press "Enter" key in the widget.
40;
41; RESTRICTIONS:
42;
43; EXAMPLE:
44;
45;        IDL> help, xquestion('Postscript name')
46;        <Expression>    STRING    = 'toto.ps'
47;
48; MODIFICATION HISTORY:Sebastien Masson (smasson@lodyc.jussieu.fr)
49;                      13/10/1999
50;-
51;------------------------------------------------------------
52;------------------------------------------------------------
53;------------------------------------------------------------
54;-------------------------------------------------------------------------
55pro xquestion_event, event
56;
57  compile_opt idl2, strictarrsubs
58;
59; we get the answer
60   widget_control, widget_info(event.top, find_by_uname = 'text') $
61    , get_value = answer & answer = answer[0]
62; now we give the answer to xquestion.pro by using the pointer uvalue
63   widget_control, event.top, get_uvalue = ptranswer
64   *ptranswer = answer
65; we destroy the widget
66   widget_control, event.top, /destroy
67   return
68end
69;-------------------------------------------------------------------------
70FUNCTION xquestion, question, proposedanswer, CHKWIDGET = chkwidget, _extra = ex ;
71;
72  compile_opt idl2, strictarrsubs
73;
74; is separate line a scalar? we must cut it into pieces?
75   if n_elements(question) EQ 1 then question = str_sep(question, '!C', /trim)
76; is a widget necessary?
77   if keyword_set(chkwidget) then BEGIN
78      if (widget_info(/managed))[0] EQ 0 then BEGIN
79         if n_elements(proposedanswer) EQ 0 then BEGIN
80            proposedanswer = ''
81            answer = ''
82            complete = ''
83         ENDIF ELSE BEGIN
84            answer = proposedanswer
85            complete = '(default answer is '+proposedanswer+') '
86         ENDELSE
87         if n_elements(question) GT 1 THEN $
88          for i = 0, n_elements(question)-2 do print,question[i]
89         read, question[n_elements(question)-1]+' '+complete , answer
90         if keyword_set(answer) EQ 0 then answer = proposedanswer
91         return, answer
92      endif
93   endif
94; definition of the widget
95   BaseId = widget_base(/column, title = 'Question', _extra = ex)
96   screensize = get_screen_size()
97   widget_control, BaseId, tlb_set_xoffset = screensize[0]/2.2, tlb_set_yoffset = screensize[1]/2.2
98   for i = 0,  n_elements(question)-1 DO trash = widget_label(BaseId, value = question[i], /align_left)
99   if n_elements(proposedanswer) EQ 0 then answer = '' ELSE answer = proposedanswer
100   trash = widget_text(BaseId, value = answer, /editable, _extra = ex, uname = 'text')
101   trash = widget_button(BaseId, value = 'ok')
102   ptranswer = ptr_new(/allocate_heap)
103   widget_control, BaseId, set_uvalue = ptranswer
104; we realize the widget and wait for an answer
105   widget_control,BaseId,/realize
106   xmanager,'xquestion',BaseId
107; we get the answer
108   answer = *ptranswer
109; we freeing the pointer
110   ptr_free, ptranswer
111;
112   return, answer
113end
Note: See TracBrowser for help on using the repository browser.