Gentle readers,
I've spent some time over the last few days narrowing down and finding
a workaround for a new behaviour in IDL 4.0 widgets, so I thought I'd
post my findings here in case it might help someone else.
In one of my applications, I do a lot of fiddling with adding and
deleting widgets in already-realized bases, and while some of this
actually works better in 4.0 than 3.6, there is one bug described
below.
I've been in touch with RSI, and this is acknowledged as a bug, and my
workaround a reasonable one.
I hope my running to column 80 doesn't make this unreadable! (if so,
I'll fix and repost)
Cheers,
-Dick
-----
;IDL Version: 4.0
;Platform: IRIX 5.3
;Symptom: Adding widgets to a base within an already-realized scrolling
base
; sometimes causes widgets to disappear.
;Details: If we are adding the new widget into empty space that's
already there
; (say, an open corner of a base) which causes no change in the
; top-level widget's size, all widgets in the top-level base
disappear.
; However, if adding the new widget causes an expansion or
contraction,
; it works fine! Running the code below illustrates this
clearly.
; Put this into a .pro file, .run it, and watch the resulting
window
; as you hit Enter to let it proceed.
;Workaround: Anytime a widget is added, add a dummy widget somewhere to
kick
; the top-level widget to grow, then destroy the dummy
widget.
t = systime(1)
b = widget_base(title = 'Widget Test Window', x_scroll_size = 300, $
y_scroll_size = 300)
frame_flag = 1
b_inner = widget_base(b, /column, frame = frame_flag)
widget_control,b,/realize
s = ''
text_list = [0L]
label_list = ['']
for i = 1, 2 do begin
bi = widget_base(b_inner, /row, frame=frame_flag)
for j = 1, 2 do begin
bj = widget_base(bi, /column, frame=frame_flag)
for k = 1, 2 do begin
bk = widget_base(bj, /row, frame=frame_flag)
for l = 1, 2 do begin
label = strtrim(long(total([i, j, k, l] * [1000, 100, 10, 1])),
2)
wt = widget_text(bk, value = label, xsize = 4)
;; The bug caused by the preceding line:
;; If adding the new widget causes no change in the containing
widgets'
;; size, all widgets in the top-level base disappear.
;; However, if adding the new widget causes an expansion or
contraction
;; it's OK!
;; In this 4x4 grid of text widgets created, X=ones that show
bug, O=OK
;; O O O O
;; O X X X
;; O X X X
;; O X X X
print, 'Created widget ' + label
text_list = [wt, text_list]
label_list = [label, label_list]
read, s ; pause for user to hit Enter
;; Trying to fix by adding/removing extra widget from top base
;; THIS WORKS!!
dummy = widget_base(b_inner)
widget_control, dummy, /destroy
print, 'Fixed (if broken) by adding and destroying base within
base '+$
'b_inner.'
read, s
end
end
end
end
for i = 0, n_elements(text_list)-2 do begin
widget_control, text_list(i), /destroy
print, 'Destroyed widget ' + label_list(i)
read, s
end
print, 'Execution time: '+strtrim(systime(1)-t)+' seconds.'
end
-----
-Dick
Dick Jackson djackson@ibd.nrc.ca Institute for Biodiagnostics
Opinions are mine alone. National Research Council Canada, Winnipeg
"And I told him my dream was to live for all time
In some perfect refrain, like the man who wrote 'Danny Boy'."
- Joe Jackson, from the album _Night_Music_, 1994.
|