X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 15 Jan 2013 06:45 AM by  anon
IDL routines with GUI
 7 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
15 Jan 2013 06:45 AM
    Hi there! I'd like to write a very simple program with a GUI consisting of a editable text box and a button that saves in a text file anything written in the box. However, I couldn't find on the web a clear tutorial to do such a simple task. I'd appreciate any help! Cheers

    Deleted User



    New Member


    Posts:
    New Member


    --
    15 Jan 2013 08:50 AM
    You'll want to check out all of the WIDGET_* functions, and also take a look at this document: http://www.exelisvis.com/...vent_Processing.html Basically, you'll need to write an IDL widget program, and an event handler to process events from the widget. Start with something like the following code. And then type "example_widget" at the IDL command line to test it out: pro example_widget_event, event compile_opt idl2 Widget_Control, event.top, GET_UVALUE=pState uName = Widget_Info(event.id, /UNAME) case (uName) of 'Save': begin openw, lun, 'testfile.txt', /GET_LUN, /APPEND Widget_control, (*pState).wText, GET_VALUE=text printf, lun, text close, lun free_lun, lun end else: begin end endcase end ;example_widget_event, event pro example_widget compile_opt idl2 wBase = Widget_Base(/COLUMN) wText = Widget_Text(wBase, /EDITABLE) wButton = Widget_Button(wBase, VALUE='Save', UNAME='Save') pState = Ptr_New({ $ wBase:wBase, $ wText:wText, $ wButton:wButton $ }) Widget_Control, wBase, SET_UVALUE=pState Widget_Control, wBase, /REALIZE XMANAGER, 'example_widget', wBase end ;example_widget

    Deleted User



    New Member


    Posts:
    New Member


    --
    15 Jan 2013 01:04 PM
    Dear Josh, thank you very much for your help. Now I'm trying to add a "Quit" button to your example but I cannot find the way to do it yet. I'll keep trying! Cheers

    Deleted User



    New Member


    Posts:
    New Member


    --
    15 Jan 2013 03:09 PM
    In general, all you need to do when creating a widget button, is give it a uname, which can then be identified in your event handler. So you can create other buttons like so: wButton1 = Widget_Button(wBase, value='Button 1 text', uname='b1') And then in your event handler, create another entry in the case-statement for that uname: case (uName) of 'Save': begin ; ... save code here end 'b1': begin ; ... button 1 operation here end else: begin end endcase In this way, you can add as many cases as you like to handle the events from each button, or other widget type. So for a "Quit" button, you could do the same thing, and close the widget using something like this: Widget_Control, id, /destroy -Josh Exelis VIS

    Deleted User



    New Member


    Posts:
    New Member


    --
    16 Jan 2013 07:24 AM
    Dear Josh, thanks again for your help. Obviously I'm doing something wrong since with my "Quit" bottom the program only closes the "Quit" bottom instead the whole window. The problem is probably due to the fact that I don't understand the code :) Specifically, I don't understand the following line: pState = Ptr_New({wBase:wBase,wText:wText,wButton:wButton}) My code now is: pro example_widget_event, event compile_opt idl2 Widget_Control, event.top, GET_UVALUE=pState uName = Widget_Info(event.id, /UNAME) case (uName) of 'Save': begin openw, lun, 'testfile.txt', /GET_LUN, /APPEND Widget_control, (*pState).wText, GET_VALUE=text printf, lun, text close, lun free_lun, lun end 'Quit': begin widget_control, (*pState).wQuit, /destroy end endcase end ;example_widget_event, event pro example_widget compile_opt idl2 wBase = Widget_Base(/COLUMN) wText = Widget_Text(wBase, /EDITABLE) wButton = Widget_Button(wBase, VALUE='Save', UNAME='Save') wQuit = widget_button(wBase, value='Quit', UNAME='Quit') pState = Ptr_New({wBase:wBase,wText:wText,wButton:wButton,wQuit:wQuit}) Widget_Control, wBase, SET_UVALUE=pState Widget_Control, wBase, /REALIZE XMANAGER, 'example_widget', wBase end ;example_widget Cheers

    Deleted User



    New Member


    Posts:
    New Member


    --
    16 Jan 2013 08:44 AM
    You are almost there. Sorry, I should have been more clear, the id that you want to /destroy is the main base widget id. So try doing this instead: 'Quit': begin widget_control, (*pState).wBase, /destroy end -Josh Exelis VIS

    Deleted User



    New Member


    Posts:
    New Member


    --
    16 Jan 2013 09:18 AM
    Nice!!! Thank you very much!!!! I successfully created a 'Load' bottom that reads a list of names. Now I want that the routine creates a WIDGET_LIST with those names. It seems complicated with my current "programing level". I'll let you know how I'm doing! Thank you very much for your help!!!!!

    Deleted User



    New Member


    Posts:
    New Member


    --
    17 Jan 2013 08:52 AM
    No problem, I'm happy to help. Good luck! -Josh Exelis VIS
    You are not authorized to post a reply.