[General] Attaching Events Handlers to Morphs is Not Obvious

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[General] Attaching Events Handlers to Morphs is Not Obvious

Philip Weaver
How do I attach a mouse handler to a morph? Most of the time I have no idea
what can be edited in the inspector: for instance how would I edit [object
Object]?. I did locate mouseHandler in the inspector; I type a little script
down below, accept changes, but that doesn't help. Overall I do think that
"Add Handler" needs to be added to each morphs menu instead of having to
scroll through the inspector.

Phil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://livelykernel.sunlabs.com/pipermail/general/attachments/20090224/d5901bf1/attachment.html 


Reply | Threaded
Open this post in threaded view
|

[General] Attaching Events Handlers to Morphs is Not Obvious

Philip Weaver
BTW, "Properties... -> add button behavior" appears to do nothing when
selected. I just revisited this command but it also did nothing for me a
couple of days ago.

On Tue, Feb 24, 2009@1:13 AM, Philip Weaver <[hidden email]> wrote:

>
> How do I attach a mouse handler to a morph? Most of the time I have no idea
> what can be edited in the inspector: for instance how would I edit [object
> Object]?. I did locate mouseHandler in the inspector; I type a little script
> down below, accept changes, but that doesn't help. Overall I do think that
> "Add Handler" needs to be added to each morphs menu instead of having to
> scroll through the inspector.
>
> Phil
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://livelykernel.sunlabs.com/pipermail/general/attachments/20090224/e9590c8f/attachment.html 


Reply | Threaded
Open this post in threaded view
|

[General] Attaching Events Handlers to Morphs is Not Obvious

Robert Krahn
In reply to this post by Philip Weaver
> How do I attach a mouse handler to a morph?

Open an inspector on a morph then, to attach a new submorph on every  
click e.g., type something like this:

// make sure the Morph really wants the event
this.handlesMouseDown = Functions.True;
// overwrite my onMouseDown method
this.onMouseDown = function (evt) {
        var localPoint = this.localize(evt.mousePoint);
        var new Morph = Morph.makeRectangle(localPoint.extent(pt(10,10)));
        this.addMorph(); // because we manually define a method
}.bind(this);

Other Mouse handler methods: onMouseMove, onMouseUp


> Most of the time I have no idea what can be edited in the inspector:  
> for instance how would I edit [object Object]?.

Multiple possibilities, assume x is an object

- If you have an instance of a class and want to know its methods
x.constructor.functionNames() // constructor is the klass

- If you have an object (instance or normal JS object) try
Object.keys(x);
Object.values(x);
for (var name in x) { console.log(name + ': ' + x[name]) }

- If you want to look@the source code open the SystemBrowser
In Core.js e.g. the fundamental parts of Morphic are defined.
You can also hit loadAll. Then enter in a TextMorph 'onMouseDown',  
select it and hit alt+w. You will get a list of all occurrences of  
onMouseDown in the source code.

Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://livelykernel.sunlabs.com/pipermail/general/attachments/20090224/37987242/attachment-0001.html 


Reply | Threaded
Open this post in threaded view
|

[General] Attaching Events Handlers to Morphs is Not Obvious

Philip Weaver
What's very confusing about the inspector is that the area on the right is
editable. If properties on the right are not persistable, then the right
should probably not be editable. I think I understand better.

So to alter an instance or class of a morph, a user must enter code in the
bottom area of the inspector window? And then do what: accept changes?
evaluate as JavaScript?

On Tue, Feb 24, 2009@2:58 AM, Robert Krahn <
[hidden email]> wrote:

> How do I attach a mouse handler to a morph?
>
>
> Open an inspector on a morph then, to attach a new submorph on every click
> e.g., type something like this:
>
> // make sure the Morph really wants the event
> this.handlesMouseDown = Functions.True;
> // overwrite my onMouseDown method
> this.onMouseDown = function (evt) {
> var localPoint = this.localize(evt.mousePoint);
> var new Morph = Morph.makeRectangle(localPoint.extent(pt(10,10)));
> this.addMorph(); // because we manually define a method
> }.bind(this);
>
> Other Mouse handler methods: onMouseMove, onMouseUp
>
>
> Most of the time I have no idea what can be edited in the inspector: for
> instance how would I edit [object Object]?.
>
>
> Multiple possibilities, assume x is an object
>
> - If you have an instance of a class and want to know its methods
> x.constructor.functionNames() // constructor is the klass
>
> - If you have an object (instance or normal JS object) try
> Object.keys(x);
> Object.values(x);
> for (var name in x) { console.log(name + ': ' + x[name]) }
>
> - If you want to look@the source code open the SystemBrowser
> In Core.js e.g. the fundamental parts of Morphic are defined.
> You can also hit loadAll. Then enter in a TextMorph 'onMouseDown', select
> it and hit alt+w. You will get a list of all occurrences of onMouseDown in
> the source code.
>
> Robert
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://livelykernel.sunlabs.com/pipermail/general/attachments/20090224/cca25f79/attachment.html 


Reply | Threaded
Open this post in threaded view
|

[General] Attaching Events Handlers to Morphs is Not Obvious

Philip Weaver
Yes, "evaluate as JavaScript". I just tried it - got it.

On Tue, Feb 24, 2009@6:08 AM, Philip Weaver <[hidden email]> wrote:

> What's very confusing about the inspector is that the area on the right is
> editable. If properties on the right are not persistable, then the right
> should probably not be editable. I think I understand better.
>
> So to alter an instance or class of a morph, a user must enter code in the
> bottom area of the inspector window? And then do what: accept changes?
> evaluate as JavaScript?
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://livelykernel.sunlabs.com/pipermail/general/attachments/20090224/04bc7840/attachment.html 


Reply | Threaded
Open this post in threaded view
|

[General] Attaching Events Handlers to Morphs is Not Obvious

Philip Weaver
In reply to this post by Philip Weaver
Actually I rediscovered this page on using inspector panel:

   -
   http://livelykernel.sunlabs.com/repository/lively-wiki/onlinetutorial14.xhtml

In a previous attempts I didn't have luck accepting/persisting changes to
values in the inspector but I will try again.

Also note that the image on this page is not actually the image of the
inspector.

On Tue, Feb 24, 2009@6:08 AM, Philip Weaver <[hidden email]> wrote:

> What's very confusing about the inspector is that the area on the right is
> editable. If properties on the right are not persistable, then the right
> should probably not be editable. I think I understand better.
>
> So to alter an instance or class of a morph, a user must enter code in the
> bottom area of the inspector window? And then do what: accept changes?
> evaluate as JavaScript?
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://livelykernel.sunlabs.com/pipermail/general/attachments/20090224/543b08b7/attachment.html