Re: Linking buttons to plot windows [message #42056] |
Mon, 20 December 2004 14:11  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Clive Cook writes:
> Thanks David, i'm pretty new to widget programming so i am not really sure
> what to do. This is an example of the code that the GUIbuilder generates. I
> assume that the first part of the code (WID_BASE_0_event) handles the
> events, so when i press wid_button_1 the function contour1 is called. As i
> mentioned before this plots in the last area designated for plots
> (wid_draw_1). How can i specifically plot it in the first area (wid_draw_0)?
It is my humble (and mostly ignored) opinion that it
is *impossible* to use the GUI_BUILDER to create widget
programs. At least programs you can understand. And this
code is like running your fingernails across the blackboard
to me. But, your code will look something like this (assuming
the CONTOUR event handlers aren't doing something weird):
pro WID_BASE_0_event, Event
wWidget = Event.top
case Event.id of
Widget_Info(wWidget, FIND_BY_UNAME='wid_button_0'): begin
if( Tag_Names(Event, /STRUCTURE_NAME) eq 'WIDGET_BUTTON' )then $
BEGIN
drawID = WIDGET_INFO(wWidget, FIND_BY_UNAME='WID_DRAW_O')
Widget_Control, drawID, Get_Value=wid
WSET, wid
contour1, Event
ENDIF
end
Widget_Info(wWidget, FIND_BY_UNAME='WID_BUTTON_1'): begin
if( Tag_Names(Event, /STRUCTURE_NAME) eq 'WIDGET_BUTTON' )then $
BEGIN
drawID = WIDGET_INFO(wWidget, FIND_BY_UNAME='WID_DRAW_1')
Widget_Control, drawID, Get_Value=wid
WSET, wid
contour2, Event
ENDIF
end
else:
endcase
end
If that is not the ugliest code I've ever posted in a newsgroup,
I don't know what is. :-(
Cheers,
David
P.S. Really do yourself a favor and ditch the GUI_BUILDER. You
(and your boss) will be glad you did. :-)
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: Linking buttons to plot windows [message #42060 is a reply to message #42056] |
Mon, 20 December 2004 11:50   |
Clive Cook
Messages: 5 Registered: December 2004
|
Junior Member |
|
|
Thanks David, i'm pretty new to widget programming so i am not really sure
what to do. This is an example of the code that the GUIbuilder generates. I
assume that the first part of the code (WID_BASE_0_event) handles the
events, so when i press wid_button_1 the function contour1 is called. As i
mentioned before this plots in the last area designated for plots
(wid_draw_1). How can i specifically plot it in the first area (wid_draw_0)?
many thanks
Clive Cook
;
; IDL Widget Interface Procedures. This Code is automatically
; generated and should not be modified.
;
; Generated on: 12/20/2004 14:15.45
;
pro WID_BASE_0_event, Event
wWidget = Event.top
case Event.id of
Widget_Info(wWidget, FIND_BY_UNAME='wid_button_0'): begin
if( Tag_Names(Event, /STRUCTURE_NAME) eq 'WIDGET_BUTTON' )then $
contour1, Event
end
Widget_Info(wWidget, FIND_BY_UNAME='WID_BUTTON_1'): begin
if( Tag_Names(Event, /STRUCTURE_NAME) eq 'WIDGET_BUTTON' )then $
contour2, Event
end
else:
endcase
end
pro WID_BASE_0, GROUP_LEADER=wGroup, _EXTRA=_VWBExtra_
Resolve_Routine, 'phoenix_eventcb',/COMPILE_FULL_FILE ; Load event
callback routines
WID_BASE_0 = Widget_Base( GROUP_LEADER=wGroup, UNAME='WID_BASE_0' $
,XOFFSET=5 ,YOFFSET=5 ,SCR_XSIZE=800 ,SCR_YSIZE=600 $
,TITLE='Phoenis Software V1.0' ,SPACE=3 ,XPAD=3 ,YPAD=3)
WID_DRAW_0 = Widget_Draw(WID_BASE_0, UNAME='WID_DRAW_0' ,XOFFSET=39 $
,YOFFSET=70 ,SCR_XSIZE=691 ,SCR_YSIZE=192)
WID_TEXT_0 = Widget_Text(WID_BASE_0, UNAME='WID_TEXT_0' ,XOFFSET=39 $
,YOFFSET=21 ,SCR_XSIZE=101 ,SCR_YSIZE=18 ,/ALL_EVENTS ,VALUE=[ $
'Channel 1 - 532 nm', '' ] ,XSIZE=20 ,YSIZE=1)
WID_BUTTON_0 = Widget_Button(WID_BASE_0, UNAME='wid_button_0' $
,XOFFSET=175 ,YOFFSET=20 ,SCR_XSIZE=111 ,SCR_YSIZE=20 $
,/ALIGN_CENTER ,VALUE='Plot Channel 1')
WID_DRAW_1 = Widget_Draw(WID_BASE_0, UNAME='WID_DRAW_1' ,XOFFSET=39 $
,YOFFSET=333 ,SCR_XSIZE=697 ,SCR_YSIZE=189)
WID_BUTTON_1 = Widget_Button(WID_BASE_0, UNAME='WID_BUTTON_1' $
,XOFFSET=182 ,YOFFSET=306 ,SCR_XSIZE=111 ,SCR_YSIZE=18 $
,/ALIGN_CENTER ,VALUE='Plot Channel 2')
Widget_Control, /REALIZE, WID_BASE_0
XManager, 'WID_BASE_0', WID_BASE_0, /NO_BLOCK
end
;
; Empty stub procedure used for autoloading.
;
pro phoenix, GROUP_LEADER=wGroup, _EXTRA=_VWBExtra_
WID_BASE_0, GROUP_LEADER=wGroup, _EXTRA=_VWBExtra_
end
|
|
|
Re: Linking buttons to plot windows [message #42071 is a reply to message #42060] |
Fri, 17 December 2004 10:53   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Clive Cook writes:
> I am using the IDL GUI builder and i want a display with two plotting window
> and 2 buttons on one page. Basically how do you link each button to the
> desired plotting window. At the moment my plot appears in the last plot
> window i create. Any ideas?
In your event handler you will have to find the ID
of the draw widget you want to plot into, get it's
value (which will be the correct window index number),
and make this window the current graphics window (with
WSET). Then draw your plot.
How one does this in the GUI Builder, I don't know. I've
never used it. It will probably involve some kind of
FIND_BY_UNAME, or something of the sort. :-)
Cheers,
David
P.S. You are probably lucking your plot went into your
widget windows at all. The number one problem with widget
programs I look at is that people have NO idea what window
they are drawing graphics in! In widget programs, as in life,
if you are not going to be lucky, you better be knowledgeable.
There is only one current graphics window in IDL, ever! :-)
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|
Re: Linking buttons to plot windows [message #42135 is a reply to message #42056] |
Wed, 22 December 2004 15:09  |
Robert Barnett
Messages: 70 Registered: May 2004
|
Member |
|
|
And look ... it's possible to write an entire application demonstrating
this in little over half the code it took to write the event loop for
GUI builder. Apologies, the excess documentation makes it a little hard
to read.
David Fanning wrote:
> Clive Cook writes:
>
>
>> Thanks David, i'm pretty new to widget programming so i am not really sure
>> what to do. This is an example of the code that the GUIbuilder generates. I
>> assume that the first part of the code (WID_BASE_0_event) handles the
>> events, so when i press wid_button_1 the function contour1 is called. As i
>> mentioned before this plots in the last area designated for plots
>> (wid_draw_1). How can i specifically plot it in the first area (wid_draw_0)?
>>
>
> It is my humble (and mostly ignored) opinion that it
> is *impossible* to use the GUI_BUILDER to create widget
> programs. At least programs you can understand. And this
> code is like running your fingernails across the blackboard
> to me. But, your code will look something like this (assuming
> the CONTOUR event handlers aren't doing something weird):
>
> pro WID_BASE_0_event, Event
>
> wWidget = Event.top
>
> case Event.id of
>
> Widget_Info(wWidget, FIND_BY_UNAME='wid_button_0'): begin
> if( Tag_Names(Event, /STRUCTURE_NAME) eq 'WIDGET_BUTTON' )then $
> BEGIN
> drawID = WIDGET_INFO(wWidget, FIND_BY_UNAME='WID_DRAW_O')
> Widget_Control, drawID, Get_Value=wid
> WSET, wid
> contour1, Event
> ENDIF
> end
> Widget_Info(wWidget, FIND_BY_UNAME='WID_BUTTON_1'): begin
> if( Tag_Names(Event, /STRUCTURE_NAME) eq 'WIDGET_BUTTON' )then $
> BEGIN
> drawID = WIDGET_INFO(wWidget, FIND_BY_UNAME='WID_DRAW_1')
> Widget_Control, drawID, Get_Value=wid
> WSET, wid
> contour2, Event
> ENDIF
> end
> else:
> endcase
>
> end
>
> If that is not the ugliest code I've ever posted in a newsgroup,
> I don't know what is. :-(
>
> Cheers,
>
> David
>
> P.S. Really do yourself a favor and ditch the GUI_BUILDER. You
> (and your boss) will be glad you did. :-)
>
--
nrb@
Robbie Barnett
imag
Research Assistant
wsahs
Nuclear Medicine & Ultrasound
nsw
Westmead Hospital
gov
Sydney Australia
au
+61 2 9845 7223
; Robbies Tools (rt)
; Plot brown noise
; Present a "redraw" button to redraw the plot in the given window
; This code has absolutely now warranty at all and is not guarunteed
; to actually work.
; Written by Robbie Barnett, Westmead Hospital Sydney
; Draw the graph of the brown noise in the specified window
pro rt_brownian_draw, window
; Keep the seed as a global variable between calls
common rt_brownian, seed
; Set the window to draw in
wset, window
; Create the array which contains the values of the brown noise
values = lonarr(20)
for i=1,19 do values[i] = values[i] + (randomu(seed)-0.5)*10.0
; Plot the brown noise
plot, values
end
; Process an event generated from the widget_button
pro rt_brownian_event, ev
; Get the draw_id which has been packed in the user value of the
; widget button. If this problem were more complicated I would have
; packed a pointer to a structure or object.
widget_control, ev.id, GET_UVALUE=draw_id
; Get the window id which maps to the desired the draw_widget
widget_control, draw_id, GET_VALUE=window
; Draw onto the desired window
rt_brownian_draw, window
end
; Create a widget which allows the user to redraw a plot of brown
; noise.
function rt_brownian, PARENT=parent
; Create the "top level base" widget. This lays out the widget_button
; and widget_draw in a column. Allow for the possibility that the
; parent was not specified.
if (keyword_set(parent)) then tlb = widget_base(parent,COLUMN=1) $
else tlb = widget_base(COLUMN=1)
; Create the canvas (window) for drawing on to
draw_id = widget_draw(tlb,XSIZE=300,YSIZE=300)
; Create the button
button_id = widget_button(tlb,VALUE="redraw",UVALUE=draw_id)
; Realize the widget elements
widget_control, tlb, /realize
; Register for events
xmanager, "rt_brownian", button_id, /JUST_REG
; Return an id for referencing to this widget
return, tlb
end
; Create 3 widgets arranged in a row. Each widget is independant and
; allows the user to redraw a plot of brown noise in each
pro rt_brownians
; Create the parent widget for holding all of them
parent = widget_base(ROW=1)
; Create the independant plots arranged in a single row
a = rt_brownian(PARENT=parent)
b = rt_brownian(PARENT=parent)
c = rt_brownian(PARENT=parent)
end
|
|
|