-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfirm.pro
89 lines (70 loc) · 2.27 KB
/
confirm.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
;-----------------------------------------
; confirm.pro 2007/05/14
;
; usage : variable = confirm(parent,message,label0,label1)
;
; create pop-up confirmation dialog with 'message' and
; return 0 or 1 corresponding to button named 'label0' or 'label1'.
;
; author : N.Ikeda & sawada
;
; history : 2007-04-02 window & button sizes enlarged
; 2007-05-14 enlarged window size again
;-----------------------------------------
;event handler for pop-up confirmation dialog
;-----------------------------------------
pro confirm_event,ev
compile_opt hidden
;get type of event
;-----------------------------------------
widget_control,ev.id,get_uvalue=uval
widget_control,ev.top,get_uvalue=storage
;event handler
;-----------------------------------------
case uval of
0 : begin
(*storage.ptr).flag=0
end
1 : begin
(*storage.ptr).flag=1
end
endcase
widget_control,ev.top,/destroy
end
function confirm,group_leader=groupleader,message=msg,label0=label0,label1=label1, title=title
compile_opt hidden
;create pop-up dialog
;-----------------------------------------
if ~(keyword_set(title)) then title="Confirmation"
dialog=widget_base(title=title, $
Group_leader=groupleader,/modal,/column)
;create confirmation message and button
;-----------------------------------------
label=widget_label(dialog, value="")
for i=0,n_elements(msg)-1 do label=widget_label(dialog,value=msg[i])
label=widget_label(dialog, value="")
buttons = widget_base(dialog, /grid_layout,/row)
space = widget_label(buttons,value=" ")
confcancel=widget_button(buttons,value=label0,uvalue=0, $
xsize=100,ysize=30,xoffset=65)
space = widget_label(buttons,value=" ")
confexit=widget_button(buttons,value=label1,uvalue=1, $
xsize=100,ysize=30,xoffset=230)
space = widget_label(buttons,value=" ")
;show pop-up confirmation
;-----------------------------------------w
widget_control,dialog,/realize
;make data storage to send data to event handler
;-----------------------------------------
ptr=ptr_new({flag:1})
storage={ptr:ptr}
;store storage
;-----------------------------------------
widget_control,dialog,set_uvalue=storage,/no_copy
;event loop
;-----------------------------------------
xmanager,'confirm',dialog
result=(*ptr).flag
ptr_free,ptr
return,result
end