source: trunk/WIDGET/xquestion.pro @ 2

Last change on this file since 2 was 2, checked in by opalod, 22 years ago

Initial revision

  • 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; we get the answer
57   widget_control, widget_info(event.top, find_by_uname = 'text') $
58    , get_value = answer & answer = answer[0]
59; now we give the answer to xquestion.pro by using the pointer uvalue
60   widget_control, event.top, get_uvalue = ptranswer
61   *ptranswer = answer
62; we destroy the widget
63   widget_control, event.top, /destroy
64   return
65end
66;-------------------------------------------------------------------------
67FUNCTION xquestion, question, proposedanswer, CHKWIDGET = chkwidget, _extra = ex ;
68; is separate line a scalar? we must cut it into pieces?
69   if n_elements(question) EQ 1 then question = str_sep(question, '!C', /trim)
70; is a widget necessary?
71   if keyword_set(chkwidget) then BEGIN
72      if (widget_info(/managed))[0] EQ 0 then BEGIN
73         if n_elements(proposedanswer) EQ 0 then BEGIN
74            proposedanswer = ''
75            answer = ''
76            complete = ''
77         ENDIF ELSE BEGIN
78            answer = proposedanswer
79            complete = '(default answer is '+proposedanswer+') '
80         ENDELSE
81         if n_elements(question) GT 1 THEN $
82          for i = 0, n_elements(question)-2 do print,question[i]
83         read, question[n_elements(question)-1]+' '+complete , answer
84         if keyword_set(answer) EQ 0 then answer = proposedanswer
85         return, answer
86      endif
87   endif
88; definition of the widget
89   BaseId = widget_base(/column, title = 'Question', _extra = ex)
90   screensize = get_screen_size()
91   widget_control, BaseId, tlb_set_xoffset = screensize[0]/2.2, tlb_set_yoffset = screensize[1]/2.2
92   for i = 0,  n_elements(question)-1 DO trash = widget_label(BaseId, value = question[i], /align_left)
93   if n_elements(proposedanswer) EQ 0 then answer = '' ELSE answer = proposedanswer
94   trash = widget_text(BaseId, value = answer, /editable, _extra = ex, uname = 'text')
95   trash = widget_button(BaseId, value = 'ok')
96   ptranswer = ptr_new(/allocate_heap)
97   widget_control, BaseId, set_uvalue = ptranswer
98; we realize the widget and wait for an answer
99   widget_control,BaseId,/realize
100   xmanager,'xquestion',BaseId
101; we get the answer
102   answer = *ptranswer
103; we freeing the pointer
104   ptr_free, ptranswer
105;
106   return, answer
107end
Note: See TracBrowser for help on using the repository browser.