Passing methods to buttons

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

Passing methods to buttons

Filip Malczak
While trying to understand SnakeGame I found interesting thing, but Im not sure how does it exactly work.

Does ButtonMorph #actionSelector: aSymbol gives a method to do when red-clicking? I mean:

SimpleButtonMorph new label: 'Label';
             color: Color lightGray;
             borderColor: #raised;
             borderWidth: 2;
             actionSelector: #delete;
             target: self);

will after clicking send message #delete to self? So when e.g. I give actionSelector: #openWindow; target: SuperMorph , I mean that after clicking this message openWindow will be sent to SuperMorph? (I give just an example, not real code)

So what about blue and yellow buttons? How to handle them from code-level?

I understand that I must have #aSymbol, #delete or #openWindow declared. But for what class? This, in which method I use upper code (when I create SimpleButton) or targets class?

Propably I got it all wrong, so if anyone can explain me how to create button and give a special action for clicking (any button, not only red) from code level, I'd be VERY pleased.

--
Greeting
Filip
GG: 2486889
mail: [hidden email]

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Passing methods to buttons

K. K. Subramaniam
On Thursday 15 Jan 2009 12:03:03 am Filip Malczak wrote:
> Propably I got it all wrong, so if anyone can explain me how to create
> button and give a special action for clicking (any button, not only red)
> from code level, I'd be VERY pleased.
Any morph can act as a button. Just add a method "handlesMouseUp:" to return
true based on the event passed as argument and handle the event in mouseUp:
method. See the section "Adding Interaction" in
 
http://stephane.ducasse.free.fr/FreeBooks/CollectiveNBlueBook/morphic.final.pdf

HTH .. Subbu
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Passing methods to buttons

Filip Malczak
Thanks for answering, but thats what I alrready knew from Squeak By Example. What I mean is:
I want to create object (lets call it Container) that contains e.g. 3 buttons (remembering that any morph could as one), each with different action. I dont want to create 3 subclasses of Button or SimpleButton and define #mouseDown: for them, but define some method for Container that adds submorphs Button with exact actions for clicking. Can I do this with #actionSelector: and #target: ? How does it exactly work? And (it should be first question) - is thing (with Container and 3 buttons) possible?

2009/1/15 K. K. Subramaniam <[hidden email]>
On Thursday 15 Jan 2009 12:03:03 am Filip Malczak wrote:
> Propably I got it all wrong, so if anyone can explain me how to create
> button and give a special action for clicking (any button, not only red)
> from code level, I'd be VERY pleased.
Any morph can act as a button. Just add a method "handlesMouseUp:" to return
true based on the event passed as argument and handle the event in mouseUp:
method. See the section "Adding Interaction" in

http://stephane.ducasse.free.fr/FreeBooks/CollectiveNBlueBook/morphic.final.pdf

HTH .. Subbu
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners



--
Pozdrawiam:
Filip
GG: 2486889
mail: [hidden email]

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Passing methods to buttons

Filip Malczak
damn, I send message, then I read it and found several language mistakes. It should go as quoted:

2009/1/15 Filip Malczak <[hidden email]>
Thanks for answering, but thats what I already knew from Squeak By Example. What I mean is:
I want to create object (lets call it Container) that contains e.g. 3 buttons (remembering that any morph could act as one), each with different action. I dont want to create 3 subclasses of Button or SimpleButton and define #mouseDown: for them, but define some method for Container, that adds submorphs Button with exact actions for clicking. Can I do this with #actionSelector: and #target: ? How does it exactly work? And (it should be first question) - is this (with Container and 3 buttons) possible?

2009/1/15 K. K. Subramaniam <[hidden email]>

On Thursday 15 Jan 2009 12:03:03 am Filip Malczak wrote:
> Propably I got it all wrong, so if anyone can explain me how to create
> button and give a special action for clicking (any button, not only red)
> from code level, I'd be VERY pleased.
Any morph can act as a button. Just add a method "handlesMouseUp:" to return
true based on the event passed as argument and handle the event in mouseUp:
method. See the section "Adding Interaction" in

http://stephane.ducasse.free.fr/FreeBooks/CollectiveNBlueBook/morphic.final.pdf

HTH .. Subbu
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners



--
Pozdrawiam:

Filip
GG: 2486889
mail: [hidden email]



--
Pozdrawiam:
Filip
GG: 2486889
mail: [hidden email]

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Passing methods to buttons

Jerome Peace
In reply to this post by Filip Malczak
[Newbies] Passing methods to buttons

Hi Filip,

Try this,
In a fresh squeak 3.9 or later
Open the world menu
Select objects. (you will get a tray of objects.)

Poke around in the catagories till you can pull out a pasteup morph
and some buttons.

Put the buttons in the paste up morph.

You now have a container with three buttons.

Now put the mouse over one of the buttons.
Halo click (push the button on the mouse that brings up the halos.
or press Cmd and click the mouse if you only have one button.)

Select the red handle it will give you a menu for that button.
Make the menu stay up.

At the bottom of the menu you will see items that allow you to set
the action selector. Pick that then type in the selector you want.
#delete would be sort of final so it would be best to pick something kind.
#flash is showy but harmless. So use that first.

Then select sight target. You will get a target sight cursor.
move it over to one of the other buttons an press.
you will get a list of morphs. the button you are over
 and the paste up morph it is on will be part of the options.
Select one.
Now press the first button and observe what happens.
Try setting a different target.
Press again. Observe again.

You can call up inspectors and explorers on the buttons to look inside.
Explorers allow you to follow objects relationships all over the place.
Inspectors allow you to change and objects parameters like its action selector.
You can also browse code. A good way to learn the answer to your question
below is to find something that does what you are trying and look at its code.



The ability of Squeak to teach is limited only by your willingness
to play.
You are trying to understand by reading and talking to those of us who
have played.

Stop.
Play first, then ask questions.
Squeak itself has all the answers.

In general, if you are trying to do something in squeak and it seems
hard you are missing something.

Try learning Squeak by playing with it.
You will learn how to code things much more easily afterwards.

Yours in service and curiosity, --Jerome Peace



Filip Malczak filet00 at gmail.com
Thu Jan 15 19:24:33 UTC 2009


2009/1/15 Filip Malczak <filet00 at gmail.com>

> Thanks for answering, but thats what I already knew from Squeak By Example.
> What I mean is:
> I want to create object (lets call it Container) that contains e.g. 3
> buttons (remembering that any morph could act as one), each with different
> action. I dont want to create 3 subclasses of Button or SimpleButton and
> define #mouseDown: for them, but define some method for Container, that adds
> submorphs Button with exact actions for clicking. Can I do this with
> #actionSelector: and #target: ? How does it exactly work? And (it should be
> first question) - is this (with Container and 3 buttons) possible?


><...>

> --
> Pozdrawiam:
>
> Filip
> GG: 2486889
> mail: filet00 at gmail.com
>




     
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners