[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Multiple widget_draw's and bad convert_coord

Hi all...

The attached sample code shows my problem. I have multiple widget_draws 
in a program that I'm writing, and I get button events from them so I 
can let the user select portions of a correlated spectrum to use as a 
gate for another spectrum. Anyway, I need to be able to get the 
coordinates that were selected in multiple plots (one at a time, of 
course), but when I try to do this, convert_coord always returns the 
coordinates from the last plot even if I'm clicking in the first plot, 
no matter how often I use wset to try and set the window.

In the example below, clicking in either the top plot or the bottom plot 
returns coordinates from the bottom plot. And you can complain about my 
use of common blocks some other time... I just wanted to get a sample 
program out the door. =)

print, !version
{ alpha OSF unix 5.4.1 Jan 16 2001      64      64}

;;----- Begin test code ---------
pro bad_test_event, ev, base
  common windowstuff, win1, win2, widget1, widget2

  if( tag_names( ev, /structure_name ) eq 'WIDGET_DRAW' ) then begin
      case ev.id of
          widget1: begin
              wset, win1
             result = convert_coord( ev.x, ev.y, /device, /to_data )
             print, result
          widget2: begin
              wset, win2
             result = convert_coord( ev.x, ev.y, /device, /to_data )
             print, result
end ;; bad_test_event

pro bad_test
  common windowstuff, win1, win2, widget1, widget2

  base = widget_base( /column )
  widget1 = widget_draw( base, xsize=300, ysize=300, /button_events ) 
  widget2 = widget_draw( base, xsize=300, ysize=300, /button_events )

  widget_control, base, /realize

  widget_control, widget1, get_value = win1
  widget_control, widget2, get_value = win2

  wset, win1
  plot, findgen(50), findgen(50)^2

  wset, win2
  plot, findgen(50)+50, sin(findgen(50)/49.*!pi)

  wset, win1
  xmanager, 'bad_test', base

;; --------- End test code ---------------

Thanks in advance for any help!