Mark Piper writes:
>
> On Tuesday, November 12, 2013 10:22:02 AM UTC-7, Paul van Delst wrote:
>>
>> What I want to do is access w and modify the properties of the various
>> plots (e.g. font size, legend font size) via the "w" object reference.
>>
>
> Hi Paul,
>
> You can access plot properties by NAME. For example, given:
>
> w = window()
> for i=0, 5 do begin
>
> !null = plot(/test, color=!color.(i), layout=[3,2,i+1], $
> current=w, name=string(i, format='(i2.2)'))
> endfor
>
> you can set the color of the fifth plot to red with:
>
> w['04'].color = 'red'
This is pretty useful. Especially if you know the name of the plot
(although unlikely in a widget program). I was curious just what was in
a window object (I assumed it was a container), so I wrote a small
program to give me back the contents of an object.
;----------------------------------------------------------- -----------
FUNCTION cgGetObjects, theObject, ISA=isa, COUNT=count
On_Error, 2
count = 0
IF Obj_HasMethod(theObject, 'GET') THEN BEGIN
contents = theObject -> Get(/ALL,COUNT=childCount)
ENDIF ELSE RETURN, !NULL
; If there is nothing in the container, return !NULL.
IF childCount EQ 0 THEN BEGIN
RETURN, !NULL
ENDIF
; Make this call recursively.
result = contents
FOR j=0,childCount-1 DO BEGIN
thisResult = cgGetObjects(contents[j], COUNT=count, ISA=isa)
IF count GT 0 THEN result = [result, thisResult]
ENDFOR
IF N_Elements(isa) NE 0 THEN BEGIN
indices = Where(Obj_ISA(result, isa), count)
IF count GT 0 THEN result = result[indices] ELSE result = !Null
ENDIF
count = N_Elements(result)
RETURN, result
END
;----------------------------------------------------------- -----------
Then, I found I could do this without knowing the name of anything.
win = window()
p1 = plot(cgdemodata(17), color='red', /current)
p2 = plot(cgdemodata(17), color='green', /overplot, /current)
objs = cgGetObjects(win, ISA='IDLGRPLOT')
Oddly, there are four plot objects in the window, not two. Maybe the
other two are used for backing store? Not sure about that. Maybe Mark
can help us understand this. But, in any case, there appear to be
duplicates. Oddly, I can't do this:
objs[0].color = 'blue'
objs[2].color = 'orange'
But, I can do this:
objs[0] -> SetProperty, Color=cgColor('navy', /Triple, /Row)
objs[2] -> SetProperty, Color=cgColor('orange', /Triple, /Row)
win.refresh
For what it is worth. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|