Re: Update text widget [message #65232] |
Fri, 20 February 2009 03:01 |
titan
Messages: 59 Registered: March 2006
|
Member |
|
|
Hi David and T.H.,
thank you very much for your suggestions!
I solved my problem :-)
Ps David I sent you an e-mail about some ordering info for your book
cheers
|
|
|
Re: Update text widget [message #65237 is a reply to message #65232] |
Thu, 19 February 2009 12:32  |
T.H.
Messages: 13 Registered: December 2008
|
Junior Member |
|
|
On Feb 19, 1:10 pm, titan <thunder...@inwind.it> wrote:
> Hi J.H.,
> excuse me if I was too cryptic in my previous message.
>
>
>
>> 1) I'm not sure where your events are supposed to be coming from.
>> Since all of your text widgets are unsensitive they can't produce any
>> events and you have no buttons to click, slider to mover , etc.
>
> What I want to do is to change the status of the text widget I create
> from SENSITIVE = 0 to SENSITIVE=1 after a series of calcolus is
> performed. For example consider a simple for cycle
>
> FOR i = 0, 5000 DO BEGIN
> Print, i
> ENDFOR
>
> once this cycle is finished I would like to communicate it to the
> event handler and change the status of the corresponding row making it
> sensitive
> I hope now I was clearer than before
>
>> 2) In the event handler, you are using variables that you defined in
>> the my_widget_text but have not passed in any way to the event
>> handler. The event handler doesn't know what text_1 or text_1_msg
>> are. One common way to handle this type of issue is to create a
>> pointer to a structure that contains all of the information that your
>> event handler might need. Then set the uvalue of you top level base
>> to that pointer. I prefer to do this kind of stuff as an object.
>> This allows you to define the widgets as member data and have access
>> to all of them throughout the event handler.
>
> unfortunately I don't know much about pointer that's why I was trying
> to use the keyword GET_UVALUE but now I understand that it is
> incorrect :o(
I think that in this case you don't need an event handler but could
simply change the sensitivity in the main code something like:
Build GUI just like you are doing now.
Perform Calculation step 1
WIDGET_CONTROL,text1,/sensitive
Perform Calculation step 2
WIDGET_CONTROL,text2,/sensitive
...
...
Or better yet consider using the a progressbar (such as the one
readily avialable at David Fanning's website).
When I started with IDL someone handed me David Fanning's book. It
saved me a lot of frustration.
|
|
|
Re: Update text widget [message #65238 is a reply to message #65237] |
Thu, 19 February 2009 11:51  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
titan writes:
> what I have in mind is the following
> consider a simple process (for example a for cycle) I know that when
> it is finished I can communicate it to user writing
> test_1msg='process A finished'
> print,test_1msg
> but if I don't have any command line I would like to do the same
> updating my widget text from sensitive=0 to sensitive=1
> It could be handled with the SEND_EVENT keyword?
Yes, if you knew the identifier of you text widget. But,
in this case, if you know the identifier of your text widget
you don't even have to send an event. You can just change
the text widget yourself:
Widget_Control, textWidgetIdentifier, Sensitive=1
> Could you please suggest me something or some example to study??
Well, XMovie is a pretty simple example:
http://www.dfanning.com/programs/xmovie.pro
It uses a NO_COPY method for moving the "info" structure
around from the top-level widgets global storage space
to the storage place in the local event handler. Most
of us don't do things this way any more, but it won't
hurt you any to learn how this works. :-)
Nowadays, we put the "info" structure in a pointer:
ptr = Ptr_New({....}, /No_Copy)
And pass the ptr around without bothering about the NO_COPY
keyword. But that is a little more complicated, and you have
to know how to clean up the pointer when you exit your program,
etc. All of that can wait until you can get and respond to a
single event.
Cheers,
David
P.S. Do think hard about that book. It will save you
untold *hours* of frustration, I can guarantee you. :-)
--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: Update text widget [message #65240 is a reply to message #65238] |
Thu, 19 February 2009 10:29  |
titan
Messages: 59 Registered: March 2006
|
Member |
|
|
Hi David,
> You can "communicate" with a widget by sending it
> events. These events can be generated by graphical
> user interface objects (buttons, text widgets, and
> the like), or you can just make up an event and send
> it to a widget, assuming you know the identifier of
> that widget, with Widget_Control and the SEND_EVENT
> keyword.
what I have in mind is the following
consider a simple process (for example a for cycle) I know that when
it is finished I can communicate it to user writing
test_1msg='process A finished'
print,test_1msg
but if I don't have any command line I would like to do the same
updating my widget text from sensitive=0 to sensitive=1
It could be handled with the SEND_EVENT keyword?
Could you please suggest me something or some example to study??
> Go to some reputable web site (I could suggest one if you can't
> find one) and find a widget program. See how information is passed
> in that program. And I would locate a good book on IDL, too. I think
> it will be extremely difficult to learn to write decent widget programs
> if all you have to go on is the IDL documentation.
>
> Widget programming is not difficult, once you get your head around
> how events happen and are processed (one at a time), and how to
> find the information you need to do whatever it is you need to do.
I know that I have to study more the "widget way" and, in the next
day, I will seriously think to buy your book
thanks
|
|
|
Re: Update text widget [message #65242 is a reply to message #65240] |
Thu, 19 February 2009 10:10  |
titan
Messages: 59 Registered: March 2006
|
Member |
|
|
Hi J.H.,
excuse me if I was too cryptic in my previous message.
>
> 1) I'm not sure where your events are supposed to be coming from.
> Since all of your text widgets are unsensitive they can't produce any
> events and you have no buttons to click, slider to mover , etc.
What I want to do is to change the status of the text widget I create
from SENSITIVE = 0 to SENSITIVE=1 after a series of calcolus is
performed. For example consider a simple for cycle
FOR i = 0, 5000 DO BEGIN
Print, i
ENDFOR
once this cycle is finished I would like to communicate it to the
event handler and change the status of the corresponding row making it
sensitive
I hope now I was clearer than before
> 2) In the event handler, you are using variables that you defined in
> the my_widget_text but have not passed in any way to the event
> handler. The event handler doesn't know what text_1 or text_1_msg
> are. One common way to handle this type of issue is to create a
> pointer to a structure that contains all of the information that your
> event handler might need. Then set the uvalue of you top level base
> to that pointer. I prefer to do this kind of stuff as an object.
> This allows you to define the widgets as member data and have access
> to all of them throughout the event handler.
unfortunately I don't know much about pointer that's why I was trying
to use the keyword GET_UVALUE but now I understand that it is
incorrect :o(
|
|
|
Re: Update text widget [message #65243 is a reply to message #65242] |
Thu, 19 February 2009 07:55  |
Michi
Messages: 9 Registered: December 2007
|
Junior Member |
|
|
David, I have the impression that you could recommend a book, too?
Just in case someone couldn't locate it? ;)
(I can recommend that book very much. ITTVIS should pay DF, because
without him, or without his website, IDL would be totally unusable for
beginners. Oh, and for some experts as well).
On Feb 19, 3:27 pm, David Fanning <n...@dfanning.com> wrote:
> titan writes:
>> I'm trying to write my own first widget but probably I'm missing
>> something about the event handler.
>
>> I would like to create a widget text with 4 rows. these rows are
>> created as insensitive and I would like to make them sensitive when
>> each of these processes occur.
>
>> How can I "communicate" to my widget that the process started and
>> after some calculations it is finished and then update my widget???
>
> You can "communicate" with a widget by sending it
> events. These events can be generated by graphical
> user interface objects (buttons, text widgets, and
> the like), or you can just make up an event and send
> it to a widget, assuming you know the identifier of
> that widget, with Widget_Control and the SEND_EVENT
> keyword.
>
> Your widget has not been built in a way that will generate
> any events, so you are unlikely to ever find yourself
> in your event handler. :-)
>
> A good thing, too, since as was pointed out, you are
> using variables in your event handler (text, text1_,
> and text1_msg) that are not defined in that procedure.
> IDL does not take kindly to using undefined variables in
> expressions. :-(
>
> So, the first thing you need to learn is how to get information
> you need in the event handler *into* the event handler. One way
> information comes into your event handler is via the event
> structure. But the event structure contains extremely limited
> information. It will not know the identifiers of any of your
> text widgets, for example. And without those identifiers, you
> have absolutely no way of interacting with them, since the ONLY
> way of interacting with widgets is via their identifiers.
>
> There are a couple of ways of getting the information you need
> where you need it. But the idea that comes immediately to mind,
> common blocks, is the worst possible one. :-)
>
> Go to some reputable web site (I could suggest one if you can't
> find one) and find a widget program. See how information is passed
> in that program. And I would locate a good book on IDL, too. I think
> it will be extremely difficult to learn to write decent widget programs
> if all you have to go on is the IDL documentation.
>
> Widget programming is not difficult, once you get your head around
> how events happen and are processed (one at a time), and how to
> find the information you need to do whatever it is you need to do.
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: Update text widget [message #65244 is a reply to message #65243] |
Thu, 19 February 2009 06:27  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
titan writes:
> I'm trying to write my own first widget but probably I'm missing
> something about the event handler.
>
> I would like to create a widget text with 4 rows. these rows are
> created as insensitive and I would like to make them sensitive when
> each of these processes occur.
>
> How can I "communicate" to my widget that the process started and
> after some calculations it is finished and then update my widget???
You can "communicate" with a widget by sending it
events. These events can be generated by graphical
user interface objects (buttons, text widgets, and
the like), or you can just make up an event and send
it to a widget, assuming you know the identifier of
that widget, with Widget_Control and the SEND_EVENT
keyword.
Your widget has not been built in a way that will generate
any events, so you are unlikely to ever find yourself
in your event handler. :-)
A good thing, too, since as was pointed out, you are
using variables in your event handler (text, text1_,
and text1_msg) that are not defined in that procedure.
IDL does not take kindly to using undefined variables in
expressions. :-(
So, the first thing you need to learn is how to get information
you need in the event handler *into* the event handler. One way
information comes into your event handler is via the event
structure. But the event structure contains extremely limited
information. It will not know the identifiers of any of your
text widgets, for example. And without those identifiers, you
have absolutely no way of interacting with them, since the ONLY
way of interacting with widgets is via their identifiers.
There are a couple of ways of getting the information you need
where you need it. But the idea that comes immediately to mind,
common blocks, is the worst possible one. :-)
Go to some reputable web site (I could suggest one if you can't
find one) and find a widget program. See how information is passed
in that program. And I would locate a good book on IDL, too. I think
it will be extremely difficult to learn to write decent widget programs
if all you have to go on is the IDL documentation.
Widget programming is not difficult, once you get your head around
how events happen and are processed (one at a time), and how to
find the information you need to do whatever it is you need to do.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: Update text widget [message #65246 is a reply to message #65244] |
Thu, 19 February 2009 03:33  |
T.H.
Messages: 13 Registered: December 2008
|
Junior Member |
|
|
On Feb 19, 4:25 am, titan <thunder...@inwind.it> wrote:
> Hi all,
> I'm trying to write my own first widget but probably I'm missing
> something about the event handler.
>
> I would like to create a widget text with 4 rows. these rows are
> created as insensitive and I would like to make them sensitive when
> each of these processes occur.
>
> How can I "communicate" to my widget that the process started and
> after some calculations it is finished and then update my widget???
> thanks
>
> Here is my wrong way (I tried it only for the first row)
>
> PRO my_widget_text_event, event
> WIDGET_CONTROL, event.id,GET_VALUE=text
> WIDGET_CONTROL,text1_,SET_VALUE=text1_msg
> END
>
> PRO my_widget_text, GROUP = GROUP
> base = WIDGET_BASE(TITLE = 'Processing info', XSIZE = 300, /COLUMN,
> XOFFSET=500, YOFFSET=300)
> row1 = WIDGET_BASE(base, /ROW, /FRAME)
> time_start_label = WIDGET_LABEL(row1,VALUE='Start Processing')
> time_start_txt = widget_TEXT(row1,VALUE=string(systime()))
> text1_msg='start process A'
> text1 = WIDGET_TEXT(base, YSIZE= 1, VALUE=text1_msg SENSITIVE=0,/
> FRAME, UVALUE=text1_msg)
> text2_msg = 'process A ok'
> text2 = WIDGET_TEXT(base, VALUE=text2_msg ,YSIZE = 1, /
> FRAME,SENSITIVE=0,UVALUE=text2_msg)
> text3_msg= 'Start process B'
> text3 = WIDGET_TEXT(base,VALUE=text3_msg , YSIZE = 1,/
> FRAME,SENSITIVE=0,UVALUE=text3_msg)
> text4_msg='process b ok'
> text4 = WIDGET_TEXT(base,VALUE=text4_msg ,YSIZE = 1,/
> FRAME,SENSITIVE=0,UVALUE=text4_msg)
> ; Realize the widgets:
> WIDGET_CONTROL, base, /REALIZE
> XMANAGER, 'wtext', base, GROUP_LEADER =
> GROUP,event_handler='my_widget_text_event', /NO_BLOCK
> END
I'm a bit confused about what you want this to do. Ignore me if I'm
missing something but a found two major problems with the code you
posted......
1) I'm not sure where your events are supposed to be coming from.
Since all of your text widgets are unsensitive they can't produce any
events and you have no buttons to click, slider to mover , etc.
2) In the event handler, you are using variables that you defined in
the my_widget_text but have not passed in any way to the event
handler. The event handler doesn't know what text_1 or text_1_msg
are. One common way to handle this type of issue is to create a
pointer to a structure that contains all of the information that your
event handler might need. Then set the uvalue of you top level base
to that pointer. I prefer to do this kind of stuff as an object.
This allows you to define the widgets as member data and have access
to all of them throughout the event handler.
|
|
|