Re: Prob with classes, widgets and event handler [message #32924] |
Wed, 20 November 2002 16:50 |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Kenneth Bowman (k-bowman@null.tamu.edu) writes:
> With the power of Google, I think David's "friends" should get together
> and prepare a commemorative volume for his family! (Think coffee-table
> book!) It could contain code snippets, selected quotes, tennis scores,
> and, of course, personal endearments from this newsgroup. ;-)
"David Fanning, this is your LIFE!"
"Oh, my God! It's David Stern!!
I wake up sometimes in a sweat, thinking about this. :-)
Cheers,
David
P.S. Let's just say if you don't remember It's Your Life,
you probably don't remember black and white televisions either. :-(
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
|
|
Re: Prob with classes, widgets and event handler [message #32930 is a reply to message #32929] |
Wed, 20 November 2002 08:07  |
James Kuyper
Messages: 425 Registered: March 2000
|
Senior Member |
|
|
David Fanning wrote:
...
> P.S. Let's just say as bad as this is, it's nothing
> compared to the fact that my wife refuses to close
> a kitchen cabinet after she opens it. This one is
> DRIVING ME INSANE, and it's only been 25 years. :-(
Install spring-loaded cabinet doors that slowly close themselves when
left open. I've no idea whether anybody actually sells such things, but
it should be possible.
|
|
|
Re: Prob with classes, widgets and event handler [message #32931 is a reply to message #32930] |
Wed, 20 November 2002 05:22  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Sebastian Loebbert (sebaaihb@peach.zrz.TU-Berlin.DE) writes:
> That's exactly what I've been looking for, but the code is wrong:
> In the event handler, it must be (contrary to my intuition)
> Call_Method, cmd.method, cmd.object, event
Doesn't that drive you crazy!? I don't think I've
ever written that command right the first time in my
whole life!
Cheers,
David
P.S. Let's just say as bad as this is, it's nothing
compared to the fact that my wife refuses to close
a kitchen cabinet after she opens it. This one is
DRIVING ME INSANE, and it's only been 25 years. :-(
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|
Re: Prob with classes, widgets and event handler [message #32932 is a reply to message #32931] |
Wed, 20 November 2002 02:30  |
Sebastian Loebbert
Messages: 12 Registered: September 2002
|
Junior Member |
|
|
On 19 Nov 2002 savoie@pleasenospam.nsidc.org wrote:
Hi,
thanks a lot, not returning 1 in INIT was the problem. I had a look at my
"Buidling IDL apps" and they only say "INIT should return scalar TRUE",
but they don't say anything about objects being not valid...
> Don't fear, this is a pretty common mistake. Your init function needs to
> return 1 to be a valid object. [Didn't you take out a red pen and underline
> that in your IDL Programming Techniques (Second Ed.) :) ]
>
That's exactly what I've been looking for, but the code is wrong:
In the event handler, it must be (contrary to my intuition)
Call_Method, cmd.method, cmd.object, event
> <fanning>
> button = Widget_Button(bbase, Value='Quit', $
> UVALUE={object:self, method:'Quit'})
>
> All the event handler does is get the user value and dispatch the
> event to this method of this object:
>
> PRO EVENTHANDLER, event
> Widget_Control, event.id, Get_UValue=cmd
> Call_Method, cmd.object, cmd.method, event
> END
>
> </fanning>
>
Best regards,
Sebastian
|
|
|
|
Re: Prob with classes, widgets and event handler [message #32944 is a reply to message #32943] |
Tue, 19 November 2002 09:38  |
savoie
Messages: 68 Registered: September 1996
|
Member |
|
|
Sebastian Loebbert <sebaaihb@peach.zrz.TU-Berlin.DE> writes:
> Hi all,
>
> I try to write a class that contains some widgets. The event handler shall
> only call member functions of that class. To have access to the class, I
> try to put 'self' in the UVALUE of the base widget.
> When I 'GET' the UVALUE inside the event handler, self isn't a valid object.
> I attached a small example class which demonstrates the problem (when
> clicking on the 'dummy'-Button, self->DUMMY_FUN should be called, but the
> reference to self does not work. I tested that program on Win2000 and
> Linux with equal results).
>
> What am I doing wrong there?
> Is there a way to make the event handler a member function of the class?
Don't fear, this is a pretty common mistake. Your init function needs to
return 1 to be a valid object. [Didn't you take out a red pen and underline
that in your IDL Programming Techniques (Second Ed.) :) ]
> ;; init function
> FUNCTION OBJ_WIDGET::INIT
> self.DEBUG = 1
> IF (self.DEBUG GT 0) THEN print, "start: OBJ_WIDGET::INIT"
> res = self->CREATE_GUI()
> IF (self.DEBUG GT 0) THEN print, "done: OBJ_WIDGET::INIT"
return, 1
> END ;; of INIT
That will fix your problem.
But, I think you should take a look at a generic handler for object widgets.
the idea is that you don't have to store and retrieve the self object each
time, but you store a structure in the uvalue.
from a Fanning post...
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&a mp;safe=off&selm=MPG.17b8dc785d0409dc98994f%40news.frii. com
<fanning>
button = Widget_Button(bbase, Value='Quit', $
UVALUE={object:self, method:'Quit'})
All the event handler does is get the user value and dispatch the
event to this method of this object:
PRO EVENTHANDLER, event
Widget_Control, event.id, Get_UValue=cmd
Call_Method, cmd.object, cmd.method, event
END
</fanning>
|
|
|