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

Last change on this file since 232 was 232, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

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