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

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

modification of headers : mainly blanks around = sign for keywords in declaration of function and pro

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.5 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;   <proidl>DIALOG_MESSAGE</proidl>.
44;
45; @categories
46; Widget
47;
48; @param QUESTION {type=A scalar string or a array of string}
49; If this argument is set to :
50;      - an array of strings: each array element is
51;        displayed as a separate line of text.
52;      - a scalar string: we are looking for the "separate line
53;        character" '!C'
54;
55; @param PROPOSEDANSWER {type=string}
56; proposing a answer
57;
58; @keyword CHKWIDGET
59; Active this keyword if you want that <pro>xquestion</pro>
60; check if managed widget are present. If not, <pro>xquestion</pro> do not
61; open a widget but print the question in the IDL window.
62;
63; @keyword _EXTRA
64; Used to pass keywords
65;
66; @returns
67; answer: a string
68;
69; @restrictions
70; The function does not return to its caller until the user
71; press "Enter" key in the widget.
72;
73; @examples
74; IDL> help, xquestion('Postscript name')
75; <Expression>    STRING    = 'toto.ps'
76;
77; @history
78; Sebastien Masson (smasson\@lodyc.jussieu.fr)
79;                      13/10/1999
80;
81; @version
82; $Id$
83;
84;-
85FUNCTION xquestion, question, proposedanswer, CHKWIDGET=chkwidget, _EXTRA=ex
86;
87  compile_opt idl2, strictarrsubs
88;
89; is separate line a scalar? we must cut it into pieces?
90   if n_elements(question) EQ 1 then question = str_sep(question, '!C', /trim)
91; is a widget necessary?
92   if keyword_set(chkwidget) then BEGIN
93      if (widget_info(/managed))[0] EQ 0 then BEGIN
94         if n_elements(proposedanswer) EQ 0 then BEGIN
95            proposedanswer = ''
96            answer = ''
97            complete = ''
98         ENDIF ELSE BEGIN
99            answer = proposedanswer
100            complete = '(default answer is '+proposedanswer+') '
101         ENDELSE
102         if n_elements(question) GT 1 THEN $
103          for i = 0, n_elements(question)-2 do print,question[i]
104         read, question[n_elements(question)-1]+' '+complete , answer
105         if keyword_set(answer) EQ 0 then answer = proposedanswer
106         return, answer
107      endif
108   endif
109; definition of the widget
110   BaseId = widget_base(/column, title = 'Question', _extra = ex)
111   screensize = get_screen_size()
112   widget_control, BaseId, tlb_set_xoffset = screensize[0]/2.2, tlb_set_yoffset = screensize[1]/2.2
113   for i = 0,  n_elements(question)-1 DO trash = widget_label(BaseId, value = question[i], /align_left)
114   if n_elements(proposedanswer) EQ 0 then answer = '' ELSE answer = proposedanswer
115   trash = widget_text(BaseId, value = answer, /editable, _extra = ex, uname = 'text')
116   trash = widget_button(BaseId, value = 'ok')
117   ptranswer = ptr_new(/allocate_heap)
118   widget_control, BaseId, set_uvalue = ptranswer
119; we realize the widget and wait for an answer
120   widget_control,BaseId,/realize
121   xmanager,'xquestion',BaseId
122; we get the answer
123   answer = *ptranswer
124; we freeing the pointer
125   ptr_free, ptranswer
126;
127   return, answer
128end
Note: See TracBrowser for help on using the repository browser.