Parse an argument for a symbol that requires one

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

Parse an argument for a symbol that requires one

Marcus Strehlow
Hi guys,

if you have a SimpleButtonMorph, you can decide what it should do and  
it's pretty easy. You say

self target: aTarget
actionSelector:  #someAction.

And it works. But what if not only an action should be executed, what  
if the actionSelector gets a symbol that requires an argument? In my  
case I need to change a variable first before further proceeding you  
see. So I am wondering if it is possible to do something like this:

self target: aTarget
actionSelector: #someAction: argumentRequired

I have tried many ways, including constructing the action first in  
temporary variables and then just using that temp variable as  
actionSelector string. All my efforts have been in vain. There is a  
way to solve this for me, but it would be very tedious to do and would  
increase the code volume... and that's not what I want.

If you have any ideas on this, let me know.


Thanks,
Marcus

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

Re: Parse an argument for a symbol that requires one

Jeroen van Hilst

"Marcus Strehlow" <[hidden email]> wrote in message
news:[hidden email]...
> Hi guys,
>
> self target: aTarget
> actionSelector:  #someAction.
>
> And it works. But what if not only an action should be executed, what  if
> the actionSelector gets a symbol that requires an argument?

Marcus,

I was curious about this, so i went and got this to work: (notice the ':' in
show:)

b := ScriptableButton new openInWorld.
b target: Transcript.
b actionSelector: #show:.
b arguments: (Array with: 'test').


HTH
    -Jeroen






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

Re: Parse an argument for a symbol that requires one

Jerome Peace
In reply to this post by Marcus Strehlow
[Newbies] Parse an argument for a symbol that requires
one


Hi Marcus

To get the best help, please describe the user story.
What are you trying to do?


You can give buttons arguments:
myButton target: aTarget .
myButton actionSelector:  #someAction: .
myButton arguments: Array with: myArgument .
        (You have to change #arguments: when ever the
argument changes.)

or you can use blocks as targets

myButton target: [ aTarget someAction: myArgument ]
actionSelector: value .

where myArgument could be something like
(FillinTheBlank request: 'Eh wot Marcus?')


This all seems a difficult way to achieve something.
Which is why I mention telling the story first. Then
it might be seen if what you want is better achieved
some other way.

Yours in curiosity and service, --Jerome Peace

***
>Marcus Strehlow marcus.strehlow at gmail.com
>Mon Mar 3 20:51:44 UTC 2008
>
>
>Hi guys,
>
>if you have a SimpleButtonMorph, you can decide what
it should do and  
>it's pretty easy. You say
>
>self target: aTarget
>actionSelector:  #someAction.
>
>And it works. But what if not only an action should
be executed, what  
>if the actionSelector gets a symbol that requires an
argument? In my  
>case I need to change a variable first before further
proceeding you  
>see. So I am wondering if it is possible to do
something like this:
>
>self target: aTarget
>actionSelector: #someAction: argumentRequired
>
>I have tried many ways, including constructing the
action first in  
>temporary variables and then just using that temp
variable as  
>actionSelector string. All my efforts have been in
vain. There is a  
>way to solve this for me, but it would be very
tedious to do and would  
>increase the code volume... and that's not what I
want.
>
I'm not at all sure what you are describing here.

>If you have any ideas on this, let me know.
>
>
>Thanks,
>Marcus
>
***



      ____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  http://tools.search.yahoo.com/newsearch/category.php?category=shopping
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Parse an argument for a symbol that requires one

Marcus Strehlow
In reply to this post by Marcus Strehlow
Hi Jeroen,

with your tip I have been able to accomplish what I needed. Thanks for your help!


Marcus


-- 
iMac -- 20 inch -- Core 2, 2 GHz -- 1 GB RAM -- Superdrive -- Mac OS X Leopard 10.5.2
MacBook -- 13.3 inch -- Core 2, 1.83 GHz -- 1.5 GB RAM -- Combodrive -- Mac OS X Leopard 10.5.2
iMac G5 -- 17 inch -- PPC G5 1.8 GHz -- 1 GB RAM -- Superdrive -- Mac OS X Leopard 10.5.2
iPod touch -- 16 GB -- Software Upgrade -- OS X 1.1.4

On 4 Mar 2008, at 09:05, [hidden email] wrote:

Marcus,

I was curious about this, so i went and got this to work: (notice the ':' in 
show:)

b := ScriptableButton new openInWorld.
b target: Transcript.
b actionSelector: #show:.
b arguments: (Array with: 'test').


HTH
   -Jeroen


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

Re: Parse an argument for a symbol that requires one

Marcus Strehlow
In reply to this post by Marcus Strehlow
Hi Jerome,

With the help of Jeroen earlier on, I have been able to complete this task. His approach is very similar to yours though.

The short version is, that I am trying to create my own Unix operating system, which comes with a user interface that is entirely written in Squeak, and therefore Smalltalk. This particular question was aimed at an obstacle I was facing while creating methods and operations for a Pulldown menu that I wrote for my UI. When a menu entry is clicked, an variable needs to be changed into a new value, which is why that one method requires an argument you see.

Here is a screenshot which shows you the Open File window, for which this question originally was.

More screens of the project

And what it is.


Thanks again,
Marcus



-- 
iMac -- 20 inch -- Core 2, 2 GHz -- 1 GB RAM -- Superdrive -- Mac OS X Leopard 10.5.2
MacBook -- 13.3 inch -- Core 2, 1.83 GHz -- 1.5 GB RAM -- Combodrive -- Mac OS X Leopard 10.5.2
iMac G5 -- 17 inch -- PPC G5 1.8 GHz -- 1 GB RAM -- Superdrive -- Mac OS X Leopard 10.5.2
iPod touch -- 16 GB -- Software Upgrade -- OS X 1.1.4

On 4 Mar 2008, at 09:05, [hidden email] wrote:

Hi Marcus

To get the best help, please describe the user story.
What are you trying to do?


You can give buttons arguments:
myButton target: aTarget .
myButton actionSelector:  #someAction: .
myButton arguments: Array with: myArgument .
(You have to change #arguments: when ever the
argument changes.)

or you can use blocks as targets

myButton target: [ aTarget someAction: myArgument ]
actionSelector: value .

where myArgument could be something like
(FillinTheBlank request: 'Eh wot Marcus?')


This all seems a difficult way to achieve something.
Which is why I mention telling the story first. Then
it might be seen if what you want is better achieved
some other way.

Yours in curiosity and service, --Jerome Peace


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