X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 17 Jan 2007 07:07 PM by  anon
opening file
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
17 Jan 2007 07:07 PM
    Hello, sorry in advance for the silly question. I've opened an existing file using Dialog_PICKFILE function in my first widget (WID_BROWSE). What shall I do to read and operate the data from this file in my second widget ( WID_CALCULATE)? Thank you for your help. PRO WID_BROWSE, EVENT file = Dialog_PICKFILE(FILTER = '*.csv') END PRO WID_CALCULATE, EVENT openr, lun, file, /get_lun data = lonarr(2,300) readf, lun, data free_lun, lun .... END PRO WID tlb = widget_base(column=1, mbar=mbar, $ tlb_frame_attr=1, xoffset=250, yoffset=250) .... xmanager, 'widgetcommon', tlb END

    Deleted User



    New Member


    Posts:
    New Member


    --
    17 Jan 2007 07:07 PM
    There are two typical ways to pass data from one event handler function to another in a traditional IDL Widget Application. The one most favored in IDL documentation is to assign a "state structure" as the UVALUE ("user value") of the top-level base widget. The state structure would be created with one field for every parameter that you want to share with all event handlers. Thus, in a widget application that, let's say, has a draw widget and a textbox a state structure might be intialized like this: info = { datafile:'', wDraw:wDraw, wText:wText } Before the XMANAGER call, one would then normally have an assignment like this: widget_control, tlb, SET_UVALUE=info After this all event handler functions could access the current "state" of shared parameters in the widget application, by starting off with the following code call: widget_control, event.top, GET_UVALUE=info your WID_BROWSE could update the state structure with code like the following: info.datafile = dialog_pickfile(FILTER='.csv') widget_control, event.top, SET_UVALUE=info ; Update the struct stored with the 'tlb' WID_CALCULATE could then get the current state of the 'datafile' parameter with the following code: widget_control, event.top, GET_UVALUE=info openr, lun, info.datafile, /GET_LUN That is the method you see most often in IDL documentation. An alternative method could be to have your program initialize and share parameters through "global variables" that IDL can initialize in a COMMON block for all the procedures/functions in the program. In your example, this might mean adding three lines of COMMON statements right after each PRO statement that, let's say, might look like this: COMMON myglobals, datafile, wDraw, wText All the procedures in the program with the above call would be sharing the same 'datafile', 'wDraw' and 'wText' with equal rights to read or update. Finally, I should mention the modern way to do this: Making your widget program and your event handlers be methods in your own custom-made IDL object class application. The shared parameters, like 'datafile' can then be fields in the structure that programmers typically initialize in the application's '...__DEFINE' method. And the methods that need acurrent stored value can get it with syntax like: self.datafile = dialog_pickfile(FILTER='.csv') If you enjoy programming, then this last approach would be the best for you to learn for long-term benefits. James Jones
    You are not authorized to post a reply.