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