Widget programing - Please help! [message #85854] |
Fri, 13 September 2013 21:46  |
moxament
Messages: 26 Registered: April 2008
|
Junior Member |
|
|
Deal All,
I am writing a simple widget program in IDL where the user is to select between two files: file one and file two. The code is below:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;
pro span, event
compile_opt idl2
;Define the main widget and its childs
main = WIDGET_BASE(Title = "Select Input File", XSIZE=260, /COLUMN)
values = ["file one", "file two"]
select = CW_BGROUP(main, values, /EXCLUSIVE)
line = WIDGET_BASE(main,column=3)
okay = WIDGET_BUTTON(line,VALUE=' Okay ',xsize=120)
cancel = WIDGET_BUTTON(line,VALUE=' Cancel ', xsize=120)
;Realize the widget
WIDGET_CONTROL, main, /REALIZE, tlb_get_size = tlb_size
WIDGET_CONTROL, select, GET_VALUE=val
screen_dim = GET_SCREEN_SIZE()
WIDGET_CONTROL, main, xoffset = screen_dim[0]/2 - fix(tlb_size[0]/2), yoffset = screen_dim[1]/2 - fix(tlb_size[1]/2)
event1 = WIDGET_EVENT(line)
CASE event1.id of
cancel: widget_control, event1.top, /destroy
okay : begin
event2 = WIDGET_EVENT(select)
WIDGET_CONTROL, select, GET_VALUE = val
if val eq 0 then print, "file one selected"
if val eq 1 then print, "file two selected"
end
endcase
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;
Now, my question is that how can I include the case where the user might click by mistake the button "Okay" without the selection of any of the two files. In case of this mistake by the user, I would like an error message to appear and say:
"ERROR: Please select one of the two files"
Your help is appreciated!
Khal.
|
|
|
Re: Widget programing - Please help! [message #85860 is a reply to message #85854] |
Sat, 14 September 2013 06:25  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Khaldanr writes:
> I am writing a simple widget program in IDL where the user is to select between two files: file one and file two.
Well, as Moe from the Three Stooges would say, I think you are doing
this "All wrong!" :-)
I think what you are trying to write here is a pop-up dialog widget, in
which you ask a user to choose something and you return the choice so
the rest of the program can operate with that choice. If so, this is an
extremely awkward and inflexible way to write the program, as you are
discovering.
You will have more luck, I think, by following the advice in this
article:
http://www.idlcoyote.com/widget_tips/popup.html
Also, I would advise you NOT to issue the error message you think you
want to offer if the user doesn't select a file. There are many reasons
for not selecting a file. Forcing a user to make a selection he has
decided he doesn't want to make is not a good way to make friends among
users of your software. If a selection isn't made, just do nothing. Give
the user a minute to think. They will either make the selection of their
own free will, or they will exit the program. But, they won't blame you
for writing lousy software. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|