On Sep 15, 9:58 pm, "b.a" <u4565...@anu.edu.au> wrote:
> Thanks for your solution. But I couldn't get it to work. What happens
> now, is that I get 3 separate window: one for my GUI (a simple tlb and
> draw widget), one for the legend (but the legend doesn't appear in it)
> and one for my plots.
The first empty one is because you are making an empty window object
(in mywindow = OBJ_NEW('IDLgrWindow')), and as such it will show up on
its own, not in your draw widget. Remove that line. The window object
you want is the one in the draw widget.
> as you see, I have commented this line:
> ;mywindow->Draw, myview
>
> If I don't do that, it gives error:
> Unable to invoke method on NULL object reference: <OBJREF
> (<NullObject>)>.
> ehich I think means that mywindow is a null object.
Sorry, forgot to say that the widget must be realized before you ask
for the
window object. That is why it was null at that point.
The third window is created by your call to plot. Plot is a direct
graphics routine, so it cannot draw on your widget_draw. You must put
object graphics in your view object, as you did with the legend. For a
plot, it usually means making and setting up a bunch of them (plots,
axes, titles, symbols). I usually prefer to make an invisible iplot
and borrow its view object, so that iplot does all the work of making
and setting up the objects in the plot.
Without getting into how to make the plots, your code would work as
pro demolegend
x1 = [1,2,3,4,5]
y1 = [4,5,6,7,8]
x2 = [2,3,4,4.5,5]
y2 = [4,5,6,7,8]
tlb = Widget_Base(column=1, XSIZE=350, YSIZE= 400,$
XOFFSET=250, YOFFSET= 300)
dr_window = WIDGET_DRAW(tlb, UVALUE= 'draw', $
XSIZE= 348, YSIZE=200, GRAPHICS_LEVEL = 2)
myview = OBJ_NEW('IDLgrView')
itemNameArr = ['One', 'two']
myLegend = OBJ_NEW('IDLgrLegend', itemNameArr)
myview->Add, mylegend
Widget_Control, tlb, /realize
WIDGET_CONTROL, dr_window, GET_VALUE = mywindow
mywindow->Draw, myview
;plot, y2, x2, COLOR= 40, BACKGROUND= 255
;oplot, y1, x1, COLOR= 80
Xmanager, 'demolegend', tlb
end
|