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 | ; |
---|
23 | PRO 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 |
---|
36 | end |
---|
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 | ;- |
---|
85 | ; |
---|
86 | FUNCTION xquestion, question, proposedanswer, CHKWIDGET = chkwidget, _EXTRA = ex ; |
---|
87 | ; |
---|
88 | compile_opt idl2, strictarrsubs |
---|
89 | ; |
---|
90 | ; is separate line a scalar? we must cut it into pieces? |
---|
91 | if n_elements(question) EQ 1 then question = str_sep(question, '!C', /trim) |
---|
92 | ; is a widget necessary? |
---|
93 | if keyword_set(chkwidget) then BEGIN |
---|
94 | if (widget_info(/managed))[0] EQ 0 then BEGIN |
---|
95 | if n_elements(proposedanswer) EQ 0 then BEGIN |
---|
96 | proposedanswer = '' |
---|
97 | answer = '' |
---|
98 | complete = '' |
---|
99 | ENDIF ELSE BEGIN |
---|
100 | answer = proposedanswer |
---|
101 | complete = '(default answer is '+proposedanswer+') ' |
---|
102 | ENDELSE |
---|
103 | if n_elements(question) GT 1 THEN $ |
---|
104 | for i = 0, n_elements(question)-2 do print,question[i] |
---|
105 | read, question[n_elements(question)-1]+' '+complete , answer |
---|
106 | if keyword_set(answer) EQ 0 then answer = proposedanswer |
---|
107 | return, answer |
---|
108 | endif |
---|
109 | endif |
---|
110 | ; definition of the widget |
---|
111 | BaseId = widget_base(/column, title = 'Question', _extra = ex) |
---|
112 | screensize = get_screen_size() |
---|
113 | widget_control, BaseId, tlb_set_xoffset = screensize[0]/2.2, tlb_set_yoffset = screensize[1]/2.2 |
---|
114 | for i = 0, n_elements(question)-1 DO trash = widget_label(BaseId, value = question[i], /align_left) |
---|
115 | if n_elements(proposedanswer) EQ 0 then answer = '' ELSE answer = proposedanswer |
---|
116 | trash = widget_text(BaseId, value = answer, /editable, _extra = ex, uname = 'text') |
---|
117 | trash = widget_button(BaseId, value = 'ok') |
---|
118 | ptranswer = ptr_new(/allocate_heap) |
---|
119 | widget_control, BaseId, set_uvalue = ptranswer |
---|
120 | ; we realize the widget and wait for an answer |
---|
121 | widget_control,BaseId,/realize |
---|
122 | xmanager,'xquestion',BaseId |
---|
123 | ; we get the answer |
---|
124 | answer = *ptranswer |
---|
125 | ; we freeing the pointer |
---|
126 | ptr_free, ptranswer |
---|
127 | ; |
---|
128 | return, answer |
---|
129 | end |
---|